Skip to main content
e d
Associate III
Jan 23, 2018 8:51 PM UTC
Solved

Inverting PWM signal

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
    This topic has been closed for replies.
    waclawek.jan
    waclawek.janBest answer
    Super User
    Jan 24, 2018 9:19 PM UTC
    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

    11 replies

    T J
    Senior III
    Jan 23, 2018 10:22 PM UTC
    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 ?

    e d
    e dAuthor
    Associate III
    Jan 23, 2018 11:34 PM UTC
    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

    T J
    Senior III
    Jan 23, 2018 10:46 PM UTC
    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'

    Tesla DeLorean
    Guru
    Jan 23, 2018 10:48 PM UTC
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    e d
    e dAuthor
    Associate III
    Jan 24, 2018 12:02 AM UTC
    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