0
\$\begingroup\$

I have the following circuit, the gate is driven by a pwm pin on a raspberry pi zero.

The LED, successfully light when my program commands it to.

However, the LEDs flicker occasionally when the duty cycle is set to anything less than 100.

What can I do to stop the LEDs from flickering?

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
3
  • \$\begingroup\$ Increase frequency. \$\endgroup\$
    – winny
    Commented Jan 27, 2018 at 20:30
  • 1
    \$\begingroup\$ Is your PWM software or hardware controlled? If in software it will flicker as the PI is not a real-time OS so regularly the CPU will have something else to do and your lights will flicker. \$\endgroup\$
    – Oldfart
    Commented Jan 27, 2018 at 20:33
  • \$\begingroup\$ Yes, the 3.3V is controlled entirely by the PI. Thanks for the reply! Increased Frequency still results in the flickering. \$\endgroup\$
    – MKUltra
    Commented Jan 27, 2018 at 20:44

2 Answers 2

1
\$\begingroup\$

I'll turn my comment then into an answer:

If your PWM is done in software it will flicker as the PI is not a real-time OS so regularly the CPU will have something else to do and your lights will flicker.

You can TRY to give our program a higher priority. The 'nice' command does that. Beware that a lower nice number is a higher priority.

Better is to use the hardware PWM in the Pi. That comes out of specific GPIO pins.

\$\endgroup\$
3
  • \$\begingroup\$ I tried using the nice functionality, no noticeable changes. I am using pin 33, which is a designated pwm pin on the PI. \$\endgroup\$
    – MKUltra
    Commented Jan 27, 2018 at 21:04
  • 2
    \$\begingroup\$ why did you accept an answer if you still have a problem??? \$\endgroup\$
    – vicatcu
    Commented Jan 27, 2018 at 21:09
  • \$\begingroup\$ TDoing manual PWM on an OS which includes the 'nice' command... The very fact of Raspberry Pi being an interrupted multitasking OS makes it inherently unsuitable for manual PWM. I for one feel confident this is the answer. Could the PWM task be offloaded to a downstream Arduino? \$\endgroup\$ Commented Jan 27, 2018 at 23:59
0
\$\begingroup\$
  1. Check resistor values for each LED. (IMO the green LED resistor should be the same or close to that of the Red LED but that's maybe another problem).

  2. The MOSFET gate voltage may be too low too. Replace R1 by a 470K resistor or something. 3.3V as mentioned is already too much on the limit according to Mosfet's datasheet (2 to 4V). I would suggest applying at least 4V, say 5V to make sure, more if possible. Or choose a mosfet with lower treshold voltage, but most of them are around these values and, anyway, I'll always recommand using at least 5V.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.