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
  • Well my guess would be that you are stopping the PWM in an entirely unsychronized fashion, and not dismantling the PPI/GPIOTE stuff, and since the PWM has to use the toggle function, anything can happen. In my opinion, the PWM capability of the nRF51 is flawed, but if you are not using ISRs you should be able to write something using PPI and GPIOTE that works. If I were you I would ignore the PWM library and write my own functions. A quick search on PWM might persuade you...

Reply
  • Well my guess would be that you are stopping the PWM in an entirely unsychronized fashion, and not dismantling the PPI/GPIOTE stuff, and since the PWM has to use the toggle function, anything can happen. In my opinion, the PWM capability of the nRF51 is flawed, but if you are not using ISRs you should be able to write something using PPI and GPIOTE that works. If I were you I would ignore the PWM library and write my own functions. A quick search on PWM might persuade you...

Children
No Data
Related