I'm using a timer and the TIMERx_COMPA
ISR to generate a signal in "the background".
This ISR is triggered when the timer reaches a certain value (OCRxA
), which in turn can be changed by the user.
Once the ISR triggers, the timer is reset and the next waiting period occurs.
If the compare value (OCRxA
) is changed to a value below the current timer value before having hit the old compare value, the timer keeps running until it overflows back to 0 and hits the new OCRxA
value. This results in no signal being generated until the timer has looped around, which can be quite long for the 16-bit TIMER1
timer.
There are multiple way to get around this:
- Reset
TCNTx
to zero wheneverOCRxA
. Easy, but one signal will always be off-clock - If
TCNTx
is greater thanOCRxA
(after changingOCRxA
), reset it to just belowOCRxA
- If
TCNTx
is greater thanOCRxA
, trigger the interrupt manually, where the signal is generated andTCNTx
is reset
I belive the third option would be the cleanest, both in checking whether the issue has occured as well as for the signal quality.
This is certainly an X -> Y
problem, so I'm open for other approaches.
My question, for now, would be: Can I manually jump to an ISR regardless of its "normal" trigger?