From the STM32F405xx/STM32F407xx datasheet, I read that (at least) TIM2, TIM3, TIM4, and TIM5 have output compare units that can be configured to produce PWM signals on 4 channels each. If one configured the timers like this:

  • TIM2: PA15/PB3/PB10/PB11
  • TIM3: PC6/PC7/PC8/PC9
  • TIM4: PB6/PB7/PB8/PB9
  • TIM5: PA0/PA1/PA2/PA3

One would achieve sixteen simultaneous PWM outputs, is that correct? Is there something I've overlooked? Is there some reason that this is not possible, or not advisable?

  • \$\begingroup\$ Arent there even more since Timer 1 and Timer 8 can also be used to generate PWM signals? \$\endgroup\$
    – Slaxx
    Commented Mar 5, 2015 at 15:30

2 Answers 2


Check for missing pins

That does look like it should work exactly as described in the datasheet. The main thing to watch out for is missing pins on lower pin-count packages; in this case ST put a full complement of 16 pins on ports A-C and simply added new ports (D and E) for the 100-pin version. Fortunately, none of your required pins are on ports D or E.

Check for over-stated resources

The other thing to watch out for is designs that use muxes to share hardware. On some micros with equivalent marketing specs there might only be four output compare units muxed between each timer. This would prevent you from using all the features at once, but it looks like this controller has a startlingly large amount of silicon dedicated to timers and it appears that you're good to go.

Check that this is really necessary

Do you really need 84 MHz PWM clocks?

That said, 16 PWM outputs sounds like an awful lot for most of the high-speed applications I can think of like motor control, switch-mode power supplies, and power-factor correction. If you are in fact doing one of these things on 16 channels, then your product's primary purpose is probably to perform this PWM and it's perfectly acceptable and normal to use this hardware for this purpose.

Or can you do it with less hardware and some software?

However, 16 channels sounds more like you're dimming an array of LEDs. If you're just dimming LEDs, then you can run your PWM at frequencies as low as 100 Hz or so, and there's little reason to utilize all this hardware for such a simple, easy task. Use one timer and some simple (fast) arithmetic in it's ISR to control the PWM for as many channels as you like on ordinary GPIO pins.

ST went to a lot of expense to put some impressive hardware clocking silicon in this chip. If your design is likely to go through future iterations, you should consider whether you really want to use this hardware for something as simple as making an LED glow. You'd be using your only 32-bit timers, 4 of 6 timers with down and up/down counting ability, 4 of 8 timers with DMA request generation ability, and 8 of 18 capture/compare channels. If you're likely to make changes or add features that might need this hardware later, it doesn't make sense to use it for LED modulation.

As I said before, though, if PWM is what you're doing, then use the hardware!

  • 1
    \$\begingroup\$ It's mere curiosity on my part, because this part was described to me as having "8 PWM". I didn't think that sounded right... \$\endgroup\$
    – Mark
    Commented Mar 8, 2012 at 21:01

Page 30: The STM32F40x include 4 full-featured general-purpose timers: TIM2, TIM5, TIM3, and TIM4.The TIM2 and TIM5 timers are based on a 32-bit auto-reload up/downcounter and a 16-bit prescaler. The TIM3 and TIM4 timers are based on a 16-bit auto-reload up/downcounter and a 16-bit prescaler. They all feature 4 independent channels for input capture/output compare, PWM or one-pulse mode output. This gives up to 16 input capture/output compare/PWMs on the largest packages

It doesn't say which packages it are, but likely it's 144 and 176 pin devices, maybe 100. You'd have to check those pin ports and see if they are present, including the output compare I/O function.

According to that paragraph, each timer can be connected to 4 output compares. The output compare set the duty cycle basically, and the timer the frequency. Thus in the end you can have 4 groups with a set frequency, but each with an individual duty cycle.

I don't know how critical the PWM accuracy is, or you're trying to get some continuous control of some sort, you could also try: * Software PWM, manually setting output ports. Takes one timer and more processor time. * PWM drivers, basicaly LED drivers abused as PWM drivers. PCA9634 for example, does fixed frequency(97kHz) but with an individual duty cycle. There are also 16-channel versions. TI also makes a ton of LED Drivers, but most of those have constant current outputs, which I kinda avoid to interface with.

I wouldn't see why this isn't advisable thing to do. If the chip can do it, go ahead. Things I would consider is whether you can get the desired duty cycle accuracy at the set frequency. For example, if you need a 10-bit duty cycle accuracy (like 0-100% is set up in 0-1023) and 100kHz output, you basically need a 2^10*100k=102.4MHz reference clock.

So actually, PWM is not just PWM, to be more specific about whether the chip suits your needs, maybe you could tell us more about the speed and accuracy required?

  • \$\begingroup\$ I read that same sentence in the datasheet, and it seems like if some of the output compare channels are missing in the small package, it should say so somewhere, and as far as I can see, it doesn't... \$\endgroup\$
    – Mark
    Commented Mar 8, 2012 at 21:04
  • \$\begingroup\$ Check table 6 on pages 44ff. \$\endgroup\$
    – starblue
    Commented Mar 9, 2012 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.