2018-01-23 12:51 PM
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!
Solved! Go to Solution.
2018-01-24 01:19 PM
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
2018-01-23 02:22 PM
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 ?
2018-01-23 02:46 PM
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'
2018-01-23 02:48 PM
PMW mode 1 and mode 2 have opposite senses as I recall.
2018-01-23 03:34 PM
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
2018-01-23 04:02 PM
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
2018-01-24 10:57 AM
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).
2018-01-24 01:19 PM
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
2018-01-24 01:41 PM
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.
2018-01-24 01:57 PM
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