This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Random PWM dutycycle inversion in SoftDevice 8.0

I am using the PWM library in this repository for a nRF51822. I write the following code to generate a ~ 30% dutycycle 500 kHz PWM output:

#define V_CLK  5

static void v_clock_start(void)
{   
    // Init PWM
    nrf_pwm_config_t pwm_config = PWM_DEFAULT_CONFIG;
    pwm_config.mode             = PWM_MODE_500kHz; // PRESCALER of 0, pwm_max_value of 31
    pwm_config.num_channels     = 1;
    pwm_config.gpio_num[0]      = V_CLK;
    // Initialize the PWM library
    nrf_pwm_init(&pwm_config);
	
   // Start PWM
   nrf_pwm_set_value(0, 10); 
}

And I use

nrf_pwm_set_enabled(false); 

to stop PWM. The enum type PWM_MODE_500kHz (self-defined) corresponds to PRESCALER of 0 and pwm_max_value of 31, making the PWM frequency 500 kHz. I enable and disable PWM periodically based on a timer, and monitor the output with an oscilloscope. I can see for the majority of time, the PWM has correct dutycycle ~30%. However, from time to time, the dutycycle is inversed (~70%), and I can see the complementary PWM waveform. It happens regularly and randomly. I am just wondering what can cause such a problem.

Parents
  • Hi

    We have seen this problem before and there are several possible causes. We think however that the problem is related to the update of the PWM duty cycle when PWM frequency is high, i.e. when nrf_pwm_set_value is called. Are you calling this method, or are you maintaining a fixed duty cycle PWM?

    If the frequency of the PWM is too high, the PWM might flip when the duty cycle is updated. I think the library implements the PWM_MODE_BUZZER_255 mode which is 62.5kHz and that is max frequency in order to do this safely. Is that frequency too low for your scenario? Can you try to lower the frequency in order to see if that is the actual issue.

Reply
  • Hi

    We have seen this problem before and there are several possible causes. We think however that the problem is related to the update of the PWM duty cycle when PWM frequency is high, i.e. when nrf_pwm_set_value is called. Are you calling this method, or are you maintaining a fixed duty cycle PWM?

    If the frequency of the PWM is too high, the PWM might flip when the duty cycle is updated. I think the library implements the PWM_MODE_BUZZER_255 mode which is 62.5kHz and that is max frequency in order to do this safely. Is that frequency too low for your scenario? Can you try to lower the frequency in order to see if that is the actual issue.

Children
No Data
Related