2024-05-13 11:14 AM
Hello,
I am attempting to set up a timer PWM output to have a set 600s period with a variable duty cycle based on a potentiometer input using an STM32G030J6 MCU. I've setup PWM output timers before will little difficulty but this time I'm having a difficult time calculating the Prescaler and ARR values to accomplish this long of a period. Are the timers just not capable of doing this long of a period and I need to us a different method to create this signal?
Solved! Go to Solution.
2024-05-13 02:32 PM
Uwe,
I was able to figure this out before you got back to me using these equations:
PWM Freq = Fclk/((PSC + 1) (ARR + 1))
DC = CCR/ARR
I'm running the MCU at 125kHz and setting ARR at the full value of 65535, this gives me a prescaler of 1143...this results in a Period of 599.8s when using an internal oscillator.
Duty Cycle will vary with a potentiometer. I'm going to to do further testing with this tomorrow to see how good of resolution I can get out of this.
2024-05-13 01:56 PM
What resolution do you need? What amount of Jitter do you allow? You get e.g. Millisecond resolution if you set up a 1 Millisecond interrupt and set up up a GPIO Pin accordingly. A 16 bit timer could only run at ~100 Hz. A 32 bit time at about 7 Mhz, if a 32 bit timer is available on GO
2024-05-13 02:32 PM
Uwe,
I was able to figure this out before you got back to me using these equations:
PWM Freq = Fclk/((PSC + 1) (ARR + 1))
DC = CCR/ARR
I'm running the MCU at 125kHz and setting ARR at the full value of 65535, this gives me a prescaler of 1143...this results in a Period of 599.8s when using an internal oscillator.
Duty Cycle will vary with a potentiometer. I'm going to to do further testing with this tomorrow to see how good of resolution I can get out of this.
2024-05-13 02:38 PM
The solution with the 1 ms ticker interrupt will have less jitter againt the 16 bit timer.
2024-05-13 02:57 PM
16-bit TIM are going to be next to useless for long duration.
Clocked slow enough, and perhaps picking a different TIMCLK source a 32-bit one would be more flexible.
Who makes a 32-bit MCU with only 16-bit TIM? ST Micro.. I worry about the CO2 levels in the design building sometimes..
2024-05-14 05:14 AM
Jitter isn't a concern in my application. I looked into the resolution and I was able to calculate it to be 16bits...the max for this MCU
Resolution(bits) = log (ARR + 1) / log(2) = log(65536) / log(2) = 16 bits.
I think this will be a good solution. If jitter becomes an issue I'll go the 1ms ticker interrupt route.