Dividing Timer
I need advice on setting up a 'primary timer/clock' to toggle a an output pin for 20ms, at a user set frequency of anywhere from 16Millihertz to 16.65Hz ( approx ) with 16 bit resolution. ( user sets value from 0 to 10000 )
The primary timer/clock must also trigger 4 'secondary timers/clocks'. Each secondary timer individually divides the primary timer frequency by a user set value of 1 to 16. ( slowing the frequency ) The user may change the division values while the primary timer is running. Eg. If the primary timer is running at 10Hz, dividing by 2 would produce 5Hz on a secondary output pin. The result is 4 'secondary' clock outputs running at different frequencies based on the primary clock.
I currently using polling and track system ticks to build software timers and to calculate when to trigger one shot PWM to each output pin. The primary clock 'counter' is in turn divided by up to 16, to trigger secondary output clocks when counters reach division thresholds. I works 'ok' but I realize this may not be the best solution, and I want to find more of a hardware approach if possible.
Is there a better approach which would use mostly/only hardware timers? I'm thinking maybe looking into timers 'triggered' by other timers and other STM32 timer features I may have initially overlooked.
One issue I encountered was getting the primary hardware timer to run at low frequencies of 16Millihertz. I currently use software counters using sytem tick, and toggle the output pins ( one-time-pulse of 20ms ) in software instead of relying on hardware timers to do the job. Do I need one timer to trigger the primary timer to get to that low of a frequency?
It would be preferable if I could just set PWM registers on the fly and keep clocks/outputs all in using peripheral timer features.
Thank you!