Keeping 2 Timer Interrupts with different Frequencies in Sync
Hello,
I have two 32bit timers running on an STM32F373, TIM2 and TIM5.
I have successfully chosen TIM2's prescale and ARR values to generate the 'update' interrupt as I require by using TIM2's prescale set to 0 and modifying the ARR to set a target frequency. TIM2 is working as I need.
I now need to have TIM5 run its interrupt the same way, but 24 times faster than TIM2. If I change TIM2's ARR value, I plan on setting TIM5's ARR to TIM2->ARR/24.
My question is; Over time, I see TIM5 will become slightly out of synch with TIM2 due to rounding. Is it ok to adjust TIM5->CNT each time TIM2's interrupt occurs to ensure they are in sync? Is there a better way to do this? I was looking at cascading timers but maybe that is too complex compared to just setting TIM5->CNt on each TIM2 interrupt.
UPDATE: I think I have this figured out. I'll re-configure my setup a bit to make use of only 1 TIM running at 24x with a cnt variable to trigger a function instead of a second timer's interrupt.
Thank you!!
