cancel
Showing results for 
Search instead for 
Did you mean: 

Using single Timer to output several PWM on different channels with different frequencies

RSy.1
Associate III

Hi guys I am a beginner of STM32 user. Now I am learning PWM. I wanted to make use of a single Timer and use 2 or 3 of its channels to output PWMs of different frequencies. I saw AN2581 app notes but unfortunately there were no sample codes there. Would you be able to share some codes or references so I can do it. Example Timer 3 then output 5k PWM on CH1 and output 10k PWM on CH3

5 REPLIES 5
TDK
Guru

You can't do different PWM frequencies on the same timer, except under some very specific scenarios (such as two frequencies off by a multiple of 2 with a 50% duty cycle).

Since you want exactly this special scenario, on one channel you set the duty cycle to 50%, and on the other you configure it to toggle the pin on update. The second channel will be half the frequency of the first.

You can also do different duty cycles with the same frequency, but it seems this is not what you want.

If you feel a post has answered your question, please click "Accept as Solution".
RSy.1
Associate III

Thank you for the hint Sir! May I ask for OUTPUT COMPARE I think this is possible based on what I read. Do you have a tutorial where I can refer to. A single timer but the channels are of different frequency?

> A single timer but the channels are of different frequency?

As TDK said above, except a very specific case, it's not possible.

The specific case he mentioned above just confused you, it's practically unusable.

JW

radoslav
Associate

This is sometimes possible - you can use DMA and feed the timer channels with proper values.

BarryWhit
Lead II

I have not done this, but from my reading of the docs on the (specialized) HRTIM peripheral, it can do this (in P/N which have it):

HRTIM.jpg

I would call this more "advanced", while the OP is a self-proclaimed newbie (welcome!). Or was, 4 years ago. Still, I think ST does have support for this use case, Please correct me if I'm wrong, I could be misunderstanding the docs.

- If someone's post helped resolve your issue, please thank them by clicking "Accept as Solution".
- Please post an update with details once you've solved your issue. Your experience may help others.