cancel
Showing results for
Did you mean:

# Long Period Timer PWM Setup

Senior

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Senior

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.

5 REPLIES 5
Principal III

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

Senior

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.

Principal III

The solution with the 1 ms ticker interrupt will have less jitter againt the 16 bit timer.

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..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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.