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

TIMER1 compare not triggered for CC=0x00

I am using a TIMER1 compare event to generate an interrupt. Generally the code all works fine, but I have noticed some strange behaviour when loading the CC register with 0x00. If the timer is allowed to run freely and overflow, then it is possible to generate a compare event when the timer rolls-over to 0. No problem there. But then I tried to limit the maximum timer count using;

NRF_TIMER1->SHORTS |= TIMER_SHORTS_COMPARE2_CLEAR_Enabled << TIMER_SHORTS_COMPARE2_CLEAR_Pos;
NRF_TIMER1->CC[2] = T1_TICKS_MAX;

My understanding is that this should cause the timer to reset to zero when it hits the value in CC2 (T1_TICKS_MAX). However, when I do this I no longer get any compare events generated for CC=0x00. Any other CC value less than or equal to T1_TICKS_MAX works fine.

This seems a bit unexpected to me. Is this normal behaviour? Or do I perhaps have a bug in my code somewhere?

Parents
  • I'm surprised it works reliably at all. The product sheet says that the COMPARE event is generated when the timer is incremented and then becomes equal to the value in the CC register, it doesn't say that it's generated when the timer is set to the CC value (ie cleared to zero in your case) without incrementing. The other type of timer, RTC, which I know you're not using here, specifically says that a clear with CC set to zero won't generate an event.

    If you can have the CC register set to something the timer is going to count through to, that would probably be more reliable.

Reply
  • I'm surprised it works reliably at all. The product sheet says that the COMPARE event is generated when the timer is incremented and then becomes equal to the value in the CC register, it doesn't say that it's generated when the timer is set to the CC value (ie cleared to zero in your case) without incrementing. The other type of timer, RTC, which I know you're not using here, specifically says that a clear with CC set to zero won't generate an event.

    If you can have the CC register set to something the timer is going to count through to, that would probably be more reliable.

Children
No Data
Related