Skip to main content
e d
Associate III
January 23, 2018
Solved

Inverting PWM signal

  • January 23, 2018
  • 3 replies
  • 6043 views
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.
    Best answer by waclawek.jan
    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

    3 replies

    T J
    Senior III
    January 23, 2018
    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
    January 23, 2018
    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
    January 23, 2018
    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
    January 23, 2018
    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    e d
    e dAuthor
    Associate III
    January 24, 2018
    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