Latest 4.2 SDK Bug in PWM class

PWM locks up if you set the DutyCycle to 0.0 or 1.0 while PWM is started.


private static PWM backlightPwm = new PWM(Cpu.PWMChannel.PWM_0, BACKLIGHT_FREQ, 0.0, false);


backlightPwm.Start(); // PWM starts running, little spikes show up in signal

backlightPwm.DutyCycle = 0.5; // Perfect square-wave

backlightPwm.DutyCycle = 1.0; // Signal goes high and stays high (normal for 100% duty)

backlightPwm.DutyCycle = 0.5; // Oops, signal stays high

backlightPwm.DutyCycle = 0.0; // Signal goes low and stays low

backlightPwm.DutyCycle = 0.5; // Oops, signal stays low

So, once you set DutyCycle to 1.0 or 0.0, you can only switch to 0.0 or 1.0, all values in between do nothing. PWM is dead :slight_smile:

I also tested this with the Period and Duration constructor/properties, result is the same.

My current work-around is to avoid 0.0 and 1.0, and use 0.01 and 0.99 as min/max DutyCycle

Very quiet in here :slight_smile: Just hope this will be fixed in final release, thanks.

Its fixed and will be in the next release.

This is the same problem I reported in
I’ve put a link from there back to here in case anyone following it wondered if it had been resolved.