cancel
Showing results for 
Search instead for 
Did you mean: 

What determines polarity of PWM?

SWenn.1
Senior III

I am finding the documentation to be very difficult to parse through and had a few questions:

  1. I have PWM set up using TIM2 and one on TIM1. There are no interrupts. I initialized it using CubeMX. Based on my understanding I expect that the output to be low until CCR1 then remain high until ARR but I seem to be having the opposite happening. How do I flip this?
  2. Where are example programs....I am new to this and have installed CubeMx but nowhere do I seem to be able to access basic examples for each target to be able to get a feel for how things work? (This is very frustrating)
5 REPLIES 5

Which STM32?

There are two PWM modes, differing in polarity. Read description of TIMx_CCMR1.OC1M in TIM chapter of RM.

Moreover, polarity of PWM can be switched also by setting TIMx_CCER.CCxP. Again, read description of that bit in RM.

Examples are in the directory where Cube (the "library") is installed; there's a "Projects" subdirectory there, and there are examples organized by individual development board. Cube (the "library") is available also on github, for example for examples for the classic 'F4 Disco board you would go to https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32F4-Discovery/Examples

JW

TDK
Guru

Some things are hidden, but I think channel polarity is pretty clearly displayed in the interface. Even if you don't know what "high" means exactly, it should be clear the "low" would flip it.

0693W00000GWzq6QAD.png 

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

Yes I was able to 'guess ' HIGH or LOW but it seems that by changing to PWM1 or PWM2 you get the same results....Not sure why all the bells and whistles

As far as my directory I have no "library" where STM32CubeIDE resides:

0693W00000GX0BdQAL.png

TDK
Guru

> Not sure why all the bells and whistles

The timers are quite complicated. The reference manual, as JW suggests, will let you see the internals if that is what you're interested in.

The Cube repository is stored within C:\Users\USERNAME\STM32Cube\Repository by default.

Timer capabilities are different on different families of chips. It helps if you include your STM32 chip number in your question so the answers can be more relevant.

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

PMW1 vs PWM2 relates to the phase and whether the signal starts High or Low at zero degrees, and switches at the phase comparison point of the cycle

Tends to be of more consequence when you have multiple channels, and you need duty/phase relationships between them.

The TIM in the STM32 are both frustratingly complex and poorly executed.

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