Changing the period values of all timers in high-resolution timer
I have a high-resolution timer configured at some frequency. This master timer has three other timers associated to it, where each timer also runs at the same frequency. But the trigger events of these timers are compare values from the master timer, that generate update event to trigger the reset of these timers.
This works and all and I am using LL APIs but I need now at some point to change the period of these timers to a lower frequency. I know I can change the period using LL APIs while running. But can I do so without causing any glitches?
I have 6 outputs (2 for each timer) set to 50% duty cycle.
My approach would be to use the functions as follows, but instead of doing a jump in the period, I do in a ramped fashion. Which means each run of the mainLoop I changed the period and then apply the code shown for all timers.
Then after 10 mainLoop runs, the change of frequency is completed
LL_HRTIM_TIM_SetPeriod(HRTIM1, LL_HRTIM_TIMER_MASTER, NEW_PERIOD);
LL_HRTIM_TIM_SetPeriod(HRTIM1, LL_HRTIM_TIMER_A, NEW_PERIOD);
uint32_t newCompareValue = __calculateCompareValue(NEW_PERIOD);
LL_HRTIM_TIM_SetCompare1(HRTIM1, LL_HRTIM_TIMER_MASTER, newCompareValue); // Compare value 1 used for timer A
