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
    1. Does it work properly if you don't have the SD running?

    2. What is the range of duty cycle you wish to produce?

    If you are only using one channel, and you don't need to change duty cycle on the fly, I still believe you'd be better off writing your own PWM functions. If you don't need to use the IRQs, then since it's all hardware(timer compare events, GPIOTE tasks) it should work perfectly fine even with the SD running.

    On the other hand, I don't know what exactly you are trying to achieve.

Reply
    1. Does it work properly if you don't have the SD running?

    2. What is the range of duty cycle you wish to produce?

    If you are only using one channel, and you don't need to change duty cycle on the fly, I still believe you'd be better off writing your own PWM functions. If you don't need to use the IRQs, then since it's all hardware(timer compare events, GPIOTE tasks) it should work perfectly fine even with the SD running.

    On the other hand, I don't know what exactly you are trying to achieve.

Children
No Data
Related