PWMOutput Flicker [Solved]

Hi,

I’m using a FEZ Cerberus to control meanwell LED drivers. The drivers default to full power without a PWM signal. I’m getting a full power flicker every time I use PWMOutput.Set or .SetPulse to change the PWM output. See simplified example code bellow. I’m new to working with hardware along with Gadgeteer and .netmf. I’m not sure how to troubleshoot this as I’m still very much learning the basics.


PWMOutput flicker = this.extender.SetupPWMOutput(GT.Socket.Pin.Nine);
for (double duty = 1; duty > 0; duty -= .01)
{
       flicker.Set(1000, duty);
       Thread.Sleep(1000);
}

Does not flicker:


PWM flickerFree = new PWM(Cpu.PWMChannel.PWM_5, 1000, 1, false);
for (double duty = 1; duty > 0; duty -= .01)
{
       flickerFree.DutyCycle = duty;
       Thread.Sleep(1000);
}

Thanks,
Jack

hi Jack, welcome to the forum.

I’d try changing your frequency from 1000 to something higher, say 10,000, and see if that changes the behavior. What you’re seeing could simply be the change taken over one full normal pulse, so making the normal pulse smaller will mean that has a lesser impact. Are there any specs on the driver with regard to frequencies?

Thank you Brett.

Sorry for the long delay in my response. Things got busy and I did not have any project time.

The spec calls for 100 to 1KHz. Here is the datasheet: http://www.meanwell.com/search/LDD-H/LDD-H-spec.pdf Edit: NM, it’s the first result on google for “ldd-1000h datasheet”

I’ve played with it some more. It seems the flicker is only noticeable when the LEDs are greatly dimmed. Once you get to about 50% power it is not noticeable. I tried 10,000 as you suggested and the flash became much more pronounced. 100 and 1000 seam similar to each other.

It seems the flashing is not related to transitioning but when Set() is used. The following code flashes every 10 seconds and is otherwise properly dimmed:

PWMOutput flicker = this.extender.SetupPWMOutput(GT.Socket.Pin.Nine);
Do
{
       flicker.Set(1000, .05);
       Thread.Sleep(10000);
} while (true);

So to me this would imply that the call to set can change the pulse width outside the range of what the device can handle. I don’t have access to VS at the moment, are there other methods for pwm that behave differently?

Hmm yeah, I think you are right. Dropping bellow 100Hz causes the drivers to go crazy with the same brightness of flashing but very fast like a strobe light on caffeine. Perhaps there is a small delay when I call Set momentarily triggering the sub 100Hz behavior?

For PWMOutput, there is just Set and SetPulse. I’m getting the flashing with SetPulse too.

    public class PWMOutput
    {
        //
        // Parameters:
        //   socket:
        //     The socket that supports pulse width modulation (PWM) output.
        //
        //   pin:
        //     The pin on the socket that supports PWM.
        //
        //   invert:
        //     Whether to invert the output voltage.
        //
        //   module:
        //     The module using this PWM output interface, which can be null if unspecified.
        //
        // Remarks:
        //     This automatically checks that the socket supports Type P, and reserves the
        //     pin.  An exception will be thrown if there is a problem with these checks.
        public PWMOutput(Socket socket, Socket.Pin pin, bool invert, Module module);

        // Summary:
        //     Returns the Gadgeteer.Socket.SocketInterfaces.PwmOutput for a Gadgeteer.Interfaces.PWMOutput
        //     interface.
        //
        // Parameters:
        //   this:
        //     An instance of Gadgeteer.Interfaces.PWMOutput.
        //
        // Returns:
        //     The Gadgeteer.Socket.SocketInterfaces.PwmOutput for this.
        public static explicit operator Socket.SocketInterfaces.PwmOutput(PWMOutput @ this);

        // Summary:
        //     Gets or sets a Boolean value that indicates whether the PWM interface is
        //     active, true if active otherwise false.
        public bool Active { get; set; }

        // Summary:
        //     Releases all resources used by the interface.
        public void Dispose();
        //
        // Summary:
        //     Sets the frequency and duty cycle of the Gadgeteer.Interfaces.PWMOutput interface
        //     and starts the PWM signal.
        //
        // Parameters:
        //   frequency:
        //     Required frequency in Hertz.
        //
        //   dutyCycle:
        //     Duty cycle from 0-1.
        public void Set(int frequency, double dutyCycle);
        //
        // Summary:
        //     Sets the period and high time of the Gadgeteer.Interfaces.PWMOutput interface
        //     and starts the PWM signal.
        //
        // Parameters:
        //   period_ns:
        //     Period of the signal in nanoseconds.
        //
        //   highTime_ns:
        //     High time of the signal in nanoseconds.
        public void SetPulse(uint period_ns, uint highTime_ns);
    }

So I added some 10K pull-down resistors to the mix and that fixed the flicker. :clap:

@ BraveBuc - I get the same flickering effect when I gradually change the intensity of the led light. Could you please clarify how exactly you used the pull down resistors?

Thanks!