PWM polarity changed

Hi,

Could it be that the polarity of PWM changed with 2.2 firmware? We are seeing opposite behaviour of PWM in the newest firmware. For example, a duty cycle of 1 used to mean full on and duty cycle of 0 was fully off. This now seems to be reversed.

I see there was a PWM glitch fixed in the changelog, does this have something to do with it?

Hi, on what device so we can test exactly?

Yes, we fixed glitch. But I just read the code and it should not change PWM behavior.

Did you start pwm and change duty after start?

On SC20

We start PWM and sometimes change duty cycle to adjust brightness of some LEDs.

We will take a look. You can stop, change duty cycles and start again. That how it was in previous version, if you don’t care about glitch issue.

1 Like

Stopping the pwm, change duty cycle and starting again seems to have fixed the issue we were experiencing. Thanks!

1 Like

We still could not reproduce this issue. Below is code we tested, every time press button, dutycycle will change. Tested at freq = 1KHz and 1MHz.

var pwmController1 = PwmController.FromName(SC20260.Timer.Pwm.Controller8.Id);
            var pwmChannel1 = pwmController1.OpenChannel(SC20260.Timer.Pwm.Controller8.PI2);


            pwmController1.SetDesiredFrequency(1000);

            pwmChannel1.SetActiveDutyCyclePercentage(0.25);

            pwmChannel1.Polarity = PwmPulsePolarity.ActiveLow;

            pwmChannel1.Start();
            var count = 0;

            while (true)
            {
                
                if (ldr1.Read() == GpioPinValue.Low)
                {
                    while (ldr1.Read() == GpioPinValue.Low);

                    if (count % 2 == 0) {
                        pwmChannel1.SetActiveDutyCyclePercentage(0.10);
                       
                    }
                    else
                    {
                        pwmChannel1.SetActiveDutyCyclePercentage(0.25);
                    }

                    count++;
                }                
            }

What led and code are you using to see the issue please?

I made this small project to reproduce:

https://www.mediafire.com/file/3kaskvnqxiyejq9/PwmTest.zip/file

I use generic 5V leds with the + connected to 5V and the ground is switched on/off by a mosfet with it’s gate connected to the PWM pin.
There is 2 PWM helper classes in there, one works as expected, the other works weird. If you run the code I provided, you will see two leds with a dimming effect that work opposite of each other. When one is fully off, the other is fully on. Both of the pwm led helpers are fed the same value.

Please try around with the enable/disable combined with the brightness features in this code. You will see that both classes operate very differently.

Thanks. Fixed in next release.

1 Like