bluetooth-lowenergynrf51

Low-power PWM library: PWM doesnt stop if low_power_pwm_stop is called from handler. Is this a bug?


I am using SDK 12.0.0.

I am working with low_power_pwm_init() to initialise the pwm and I have passed a handler while initialising. I want to stop the pwm from the handler hence I am calling low_power_pwm_stop() from the handler. I observe that the pwm doesnt stop.

I tried to investigate the reason for this and found that pwm_timeout_handler() in low_power_pwm.c is restarting the pwm. Below is the snippet that is suspect.

if (p_pwm_instance->pwm_state == NRF_DRV_STATE_INITIALIZED)
{
    p_pwm_instance->pwm_state = NRF_DRV_STATE_POWERED_ON;
    err_code = app_timer_start(*p_pwm_instance->p_timer_id, p_pwm_instance->timeout_ticks, p_pwm_instance);
    APP_ERROR_CHECK(err_code);
}

In low_power_pwm_stop(), p_pwm_instance->pwm_state is assigned NRF_DRV_STATE_INITIALIZED and in the above snippet the timer is started if the driver state is NRF_DRV_STATE_INITIALIZED, causing the pwm to be ON again.

Is this a bug?


Solution

  • I had posted this question on nordic's devzone and below is the answer that I got from a nordic employee.

    Hi,

    I can see that this will be the case and will report it internally.

    You can set a flag in the event handler and call the stop routine in main.

    Ole

    So I guess this is a bug in nordic's sdk code.