Way to cancel TASK_STOP (PWM driver)

Hi there,

I'm using nRF52840 dev kit board and v15.2 SDK.

I've set up a PWM using the PWM driver and is working well. 

I'm frequently stopping and starting the PWM and I'm stopping the pwm by calling nrf_drv_pwm_stop. My PWM is running at around 1kHz so sometimes stop event takes long time after calling nrf_drv_pwm_stop.

The problem is, occasionally I can see that my code tries to enable PWM before stop event interrupt is called and this causes a problem because my code enables the PWM but TASK_STOP is already triggered so it stops the PWM after it has just been enabled. 

I have tried nrf_pwm_event_clear(my_pwm.p_registers, NRF_DRV_PWM_EVT_STOPPED) but this is only clearing the stop event to trigger ISR. The actual stopping task still seems to happen and I was wondering if we could somehow cancel the already triggered TASKS_STOP.

I've tried writing 0 to my_pwm.p_registers->TASKS_STOP but this does not seem to have any effect.

Please someone help!



  • I've tried writing 0 to my_pwm.p_registers->TASKS_STOP but this does not seem to have any effect.

     After triggering the STOP TASK, i do not see anyway of stopping this. I strongly recommend you not to pursue this direction.

    The problem seems to be that your application logic is starting the new PWM action before the previous one stop has completed. In this scenario, the proper way, according to me, is to fix your application logic, that it could wait until the STOP_TASK has finished its work and the interrupt is triggered for EVENT_STOP.  

  • Hi Susheel,

    Ok, I just wanted to confirm there was no way of canceling a task that was already triggered.

    I will need to handle it in my code then. 

    Thanks for the confirmation!


  • Triggering any TASKS would start set of actions within the hardware like requesting/releasing resources (like clocks etc) which cannot be undone and brought back to the state as it was before. So I can confirm that you can safely think that once doing a TASKS_STOP your app needs to wait until you get the event that the stop is finished.