STM32 PWM Frequency vs PWM resolution - Page 1
Forum section: electronics / general

author: gab_22
author_rank: Contributor
timestamp: May 12, 2020, 01:51:10 pm
content: Hi all !I'm trying to do a little project on STM32 MCU (withNUCLO-F429ZI Dev board) featuring PWM signal generation. I have some experience on PWM signal gneration with PIC MCUs, and with them, the PWM resolution is related to the PWM frequency. i.e with a high PWM frequency we have a low PWM resolution. And with a low PWM frequency with have a higher PWM resolution.So I guess it's the same thing with STM32. But I didn't find any clear information about that.SOmeone have an idea or documentation about that ?Thank you

author: capt bullshot
author_rank: Super Contributor
timestamp: May 12, 2020, 03:35:30 pm
content: It's the same as everywhere else. Some of the STM32 chips can run their timers at 100MHz and more and sometimes they're 32Bit, so one can get reasonable resolution at high frequencies. For details, you'd need to look up the timer sections in the respective reference manual and the maximum clock frequencies for the timers (these are simple to figure out using the STM32CubeMX tool). STM32 chips have many timers, and they have different maximum clock frequencies even on the same chip. With the modern derivatives, you should be able to run at least one or two timers at the same or half the CPU core clock.

author: NorthGuy
author_rank: Super Contributor
timestamp: May 12, 2020, 04:58:21 pm
content: The PWM resolution depends on the underlying clock, so the faster the clock the better the PWM resolution. Some MCUs have built-in PLL with high frequency VCO and allow the VCO to be used as a PWM source clock. These will have much better resolution.

author: lucazader
author_rank: Regular Contributor
timestamp: May 12, 2020, 08:58:25 pm
content: The timers will have a tradeoff between frequency and seolution just like the PIC timers.The stm32 timers however do run quite fast usually, so you can quite often get good resolution with high enough frequencies to be out of the audio range.As mentioned previously some of the more recent stm32 chips have extra PLL's that can clock their timer peripherals fasterThe F429ZI however doesn't have any PLLs specifically for timers to get higher resolution. So the fastest the tiemr peripheralas can be clocked with the 429 is 90MHz.If you need higher:Most of the stm32 F3's have the ability to run the timer clock at 2x the system clock, so up to 144MHz.Some of them also have a High resolution timer. I have never used this, so i dont really know how it works, but it may be of interest to you.The new G0 series have the same 2x clock generator for some of the timer peripherals. so you can get up to 128MHz timers on them, and they are super cheap!Hope this helps.

author: mino-fm
author_rank: Regular Contributor
timestamp: May 13, 2020, 08:29:12 am
content: Quote from: lucazader on May 12, 2020, 08:58:25 pmIt's 180 MHz.

author: Siwastaja
author_rank: Super Contributor
timestamp: May 13, 2020, 11:06:31 am
content: No magic happening: for example, divide a 16MHz clock in 1000 steps, and you have a 16kHz PWM with 1000 steps in resolution. Using center-aligned multiphase PWM, of course only if you need that, requires the timer to run up and down alternatively, dividing the frequency (or resolution) further by two.STM32 obviously goes to higher clock rates than PICs, though, which gives you a bit of extra, but not groundbreaking. Higher-end chips may have timers up to some 200MHz, but beware, only a few timers on a chip may run at the highest clock domain (the CPU rate).STM32F334 offers a special "HRTIM" PWM module which "breaks free" of the typical constraint, and uses analog wizardry to divide the clock periods into finer grain (in 16 sub-steps, if I remember it correctly). Here, the "equivalent digital" clock rate is some 3GHz if I recall correctly, which obviously allows combination of quite high resolution and output frequency: for example, divide 3GHz in 10000 steps, and the frequency is still 300kHz!

author: gab_22
author_rank: Contributor
timestamp: May 13, 2020, 04:36:21 pm
content: Hi all, and thanks for the replies ! it's very helpful for meQuoteOk I got it. I did a test, and it seems I have this behaviour.Thank you

author: lucazader
author_rank: Regular Contributor
timestamp: May 13, 2020, 08:20:27 pm
content: Quote from: mino-fm on May 13, 2020, 08:29:12 amThe core can be clocked at 180MHz correct, and some timer peripherals can as well, but not all of themHowever it depends on the timer peripheral and what bus it is connected to.If it is on the APB1 bus then it is only 90MHz, APB2 can go up to 180 though you are right.

author: mino-fm
author_rank: Regular Contributor
timestamp: May 14, 2020, 08:44:27 pm
content: Setting TIMPRE in RCC_DKCFGR each timer is clocked by HCLK (max. 180 MHz).

author: Doctorandus_P
author_rank: Super Contributor
timestamp: May 15, 2020, 03:51:23 pm
content: If you want to filter the PWM to DC with an RC filter, there is a simple and very nice trick:You can use a 2, 3 to 4 bit R-2R network and use that for your most significant bits.This inherently reduces the ripple on the output 4, 8, or 16 times.By adding suitable capacitors inside the R-2R network the extra component count is minimal.Because you need fewer bits in the PWM signal, you can use a higher PWM frequency which reduces ripple even more.