cancel
Showing results for 
Search instead for 
Did you mean: 

Inverting PWM signal

e d
Associate II
Posted on January 23, 2018 at 21:51

Is there a quick and clever way of inverting a PWM signal in software (I am using timer 2 of the Discovery Kit board/STM32L100)? Was looking for the complementary feature but I don't want a pair of PWMs, just the inverted of the original signal (top).

Thanks in advance!

0690X00000609TBQAY.png
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on January 24, 2018 at 21:19

How do you achieve that PWM OFF, in terms of TIM register values?

If it means TIMx_CCER.CCxE=0, try to switch on pull-up on given signal, if its loading is low enough. Otherwise, leave TIMx_CCER.CCxE=1 and set TIMx_CCMRx.OCxM to one of the 'force' levels (depending on value of TIMx_CCER..CCxP).

(Please spare me with any reference to  'libraries'.)

JW

View solution in original post

11 REPLIES 11
T J
Lead
Posted on January 23, 2018 at 23:22

there are three ways,

setup a separate PWM output to be as requested,

or use an inverter outside the processor,

or use a transistor

if you only need 1 output but inverted, there is a switch to do it in the cube, are you using the cube ?

T J
Lead
Posted on January 23, 2018 at 23:46

If you have tried to use the invert function and it doesnt work,

then you need either to read the pin and invert it to another pin in a a very tight loop,

or use an inverter.

otherwise you could invert the periods, so the 'on' time is 'off'

Posted on January 23, 2018 at 23:48

PMW mode 1 and mode 2 have opposite senses as I recall. 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
e d
Associate II
Posted on January 23, 2018 at 23:34

As I mentioned I was looking for a software solution. Yes I only need 1 PWM (inverted) output. What 'switch' in the Cube are you referring to? This:

sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;?

I've tried this (changed from

TIM_OCPOLARITY_HIGH) 

and it worked but when inactive the signal was low instead of high as seen in the 'Desired' trace.

Thanks

Posted on January 24, 2018 at 00:02

That was what I was looking into but my scope is in repair now so I hope to get it back tomorrow to do some experiment with the PWM mode setting. I might have some follow up tomorrow that needs some feedback. Thanks

Posted on January 24, 2018 at 18:57

Been playing with the OCxM (PWM mode) and the polarity and got the same result: looks good while active (inverted polarity as desired). But I couldn't seem to make the signal HIGH when inactive (PWM OFF time). Is it even possible in single output mode? I know in complementary pair it is possible (make dead band zero).

Posted on January 24, 2018 at 21:19

How do you achieve that PWM OFF, in terms of TIM register values?

If it means TIMx_CCER.CCxE=0, try to switch on pull-up on given signal, if its loading is low enough. Otherwise, leave TIMx_CCER.CCxE=1 and set TIMx_CCMRx.OCxM to one of the 'force' levels (depending on value of TIMx_CCER..CCxP).

(Please spare me with any reference to  'libraries'.)

JW

Posted on January 24, 2018 at 21:41

Yes, the CCxE (or CC1E specifically) = 0 for PWM OFF period (for PWM ON, 

CCxE 

= 1). Do you suggest going back and forth between GPIO mode (pull-up) and normal PWM mode? This has been discussed internally but sounds kludgy. I was looking for an elegant way of doing it. Otherwise it will be done in hardware.

The load on this signal is about 100 mW.

Posted on January 24, 2018 at 21:57

Do you suggest going back and forth between GPIO mode (pull-up) and normal PWM mode?

No.

This has been discussed internally but sounds kludgy.

Regardless of the 'no' above, why?

And with regard of 'No', as I've said above: leave TIMx_CCER.CCxE=1 and set TIMx_CCMRx.OCxM to one of the 'force' levels .

JW