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

app_pwm with additional timers

Hi,

i tried to modify app_pwm to add an additional timer, since i'm out of timers.

so at the end of app_pwm_init i added

nrf_drv_timer_compare(p_instance->p_timer, NRF_TIMER_CC_CHANNEL0, ticks, true);

and in the interrupt handler i just additionally check for NRF_TIMER_EVENT_COMPARE0

however, whatever i set for ticks, both COMPARE0 and COMPARE2 are always true in exact sequence, at the same frequency. I would have expected two nrf_drv_timer_compare to only fire at their distinct counter value.

edit:

Maybe i figured out the original question: either of the compare events will of course fire a reset, which resets the entire counter. Apparently there's only one counter per timer shared by all channels, so all channels fire when any of them resets. What confused me that in app_timer you do:

nrf_timer_event_clear(NRF_TIMER1, NRF_TIMER_EVENT_COMPARE0);

which looks like you can clear just one timer channel without somehow affecting the others. What's the purpose of the clear mask there?

Related