1
\$\begingroup\$

I am working on a project that involves controlling WS2812B led strips using a Teensy 4.0 microcontroller. I got everything working during the testing phase, but now, after transitioning from breadboards to prototyping boards, I'm having some issue with power delivery to the microcontroller. I do not have any electrical engineering background, so this might be a total newbie question, forgive me please ;)

I created a quick sketch of how the power supply is setup right now, to give you a general idea of what we're working with. enter image description here

Running it like this results in glitched visualizations of the data sent to the matrix: (later you'll see what it is supposed to look like) enter image description here

Of course, I have already tried a bunch of different things to fix it, following the "try random things until it works"-solution finding pattern.

I noticed that, when powering the microcontroller using its USB port with my laptop, while disconnecting the 5v line between the power supply and the microcontroller, but leaving the ground line between the two connected; the interference/noise/glitching (whatever you call this) will go away. (as long as the USB cable is lying on the table near the 5v and ground wires from the power supply (this seems like magic to me, but maybe this information will help you))

So I continued reading and trying stuff out. I tried looping the positive wire (between the microcontroller and powersupply) through a ferrite (probably) core. This, in itself does not improve much. However, when I press my fingers on the metal USB-input-port-casing and some pins on the microcontroller, then the interference disappears again!. enter image description here

I am stuck with this problem. Like I said, I do not have a background with electrical engineering, and this is my first bigger project I'm working on. If the problem is super obvious to you, please PLEASE let me know. Otherwise, I would also appreciate material to read up on or general pointers that can get me thinking in the right direction.

In any case, thanks a lot for reading this far!

\$\endgroup\$
  • 1
    \$\begingroup\$ Do you know what decoupling capacitors are? \$\endgroup\$ – DKNguyen Jan 22 at 20:51
  • \$\begingroup\$ @DKNguyen I do not! Will read up on those now, thanks. Do you suspect that this could be a solution? \$\endgroup\$ – hmmmniek Jan 22 at 20:53
  • 1
    \$\begingroup\$ Normally it is pointless to try debugging any issue until they are in place since without them lots of weird things can happen. But the symptoms you describe certainly sound like this is the issue. \$\endgroup\$ – DKNguyen Jan 22 at 20:55
1
\$\begingroup\$

I'll try to explain simply...

WS2812B draws pulsed currents from the supply. When you have lots of these LEDs, the high amount of varying current will create voltage drop across the supply wires, which have both resistance and inductance. This causes the supply voltage to ripple, which will crash your microcontroller, and also makes the controllers inside each LEDs lose their marbles.

This is a common problem with these LEDs.

The large varying currents drawn by the LEDs runs in the supply wires, but also in the ground wires, which means voltage drop in the ground wires will affect the potential of "GND" on each strip. This is called "ground bounce".

WS2812B receive data signals from the microcontroller, but remember these signals are voltage, which means they are referenced to ground. The actual value of the signal is the voltage between your signal wire and whatever potential the "GND" pin of the LED chip happens to be at. So, when current flowing in the ground wires makes the "GND" potential wiggle all over the place, the LEDs can receive the wrong commands because the data signal voltage becomes a mess.

Solution is to add decoupling capacitors which act like local energy storage close to the LEDs. Pulsed currents will travel in the lowest impedance loop which means the shortest loop. So the decoupling capacitor provides the "fast varying" part of the current, and the wires only carry the low frequency parts of the current. This also avoids wires acting like antennas and the whole thing being a radio jammer.

Since these LEDs draw substantial currents, I won't recommend small ceramic caps like DKNguyen says. Instead I'd solder low-ESR electrolytic capacitor on the strips, about one each 20 centimeters of strip.

The design requirements for these capacitors are:

Enough capacitance to do the job, so (wet finger in the wind) more than 100µF per cap and a decent ripple current rating.

ESR between 0.05 and 0.5 ohms. ESR is the internal resistance of the cap. We want that to be low so the cap actually does something useful, but not too low as that would create unwanted resonances with the wiring inductance.

Lowish ESL (series inductance) which means a small capacitor, like 6.3mm diameter, with short leads.

You can get a bag of 100 of these which fit the bill for about 10€ so that would do the job. Given the shape of your matrix, one cap on each end of each strip, between "+5V" and "GND" should work nicely.

I noticed that, when powering the microcontroller using its USB port with my laptop, while disconnecting the 5v line between the power supply and the microcontroller, but leaving the ground line between the two connected; the interference/noise/glitching (whatever you call this) will go away. (as long as the USB cable is lying on the table near the 5v and ground wires from the power supply (this seems like magic to me, but maybe this information will help you))

Looking at the picture, this isn't surprising. The data signals for these LEDs are pretty fast which means they can have signal integrity issues. Without going into too much detail... a fast signal with fast edges implies a high rate of change in volts/second (dv/dt) when it flips from 0 to 1 and back. This implies a current flowing into the wire to charge the parasitic capacitances along the way. Current flows in a loop, so this current returns to whatever "ground" wire connects the LED matrix to your microcontroller. If the wires are widely spaced (as seen in the picture) there will be a lot of loop area, thus a lot of inductance, which leads to ringing (random image from the net as an example)...

enter image description here

...and the chip receiving that can interpret the ringing as several pulses instead of one, and then it receives it wrong.

The solution is to route a ground wire along each fast signal wire.

It looks like you've grouped your WS2812B into several bunches and you're running one data signal per bunch. Try twisting each data wire with a ground wire, connected to ground at both ends. I mean the ground wire should go to ground on the microcontroller side at the connector, and to the "GND" pad on the strip right next to where the signal wire goes, not to any other point labeled "GND" anywhere else. You can also add a 33R resistor in series with the signal on the microcontroller side to reduce ringing, if necessary.

Once you did that, note that a small fraction of the total current used by the LEDs will find its way into these ground wires. This shouldn't be a problem since you used fat wires to supply the LED, and thin wires for signal, the bulk of the current should go into the fat wires and not into the microcontroller board.

\$\endgroup\$
  • \$\begingroup\$ @peufeu Wow thank you so much for this VERY detailed information! First I will try to add the ground wires along the data lines soon, since that seems like the easiest thing for me to do first. If that does not work, I will try adding the capacitors. I will keep this post updated with any progress that i make. \$\endgroup\$ – hmmmniek Jan 22 at 22:19
  • \$\begingroup\$ @hmmmniek I'd like to call attention to the point about the larger electrolytic caps for the ICs. LED power currents are (probably) larger and lower frequency so the higher capacitance, but higher inductance electroytics are suitable there. Ceramic caps are used for the ICs because the frequencies are higher so the cap parasitic inductance must be lower. Larger caps for decoupling lower frequencies are less critical of how closely they are placed to the load since lower frequency currents are less affected by the same amount of parasitic inductance in wires. \$\endgroup\$ – DKNguyen Jan 22 at 22:20
  • \$\begingroup\$ @DKNguyen WS2812B strips I looked up all had ceramic caps next to the "LEDs". It would be nice to know if OP's strips have them. \$\endgroup\$ – peufeu Jan 22 at 22:21
  • \$\begingroup\$ @peufeu here's a picture of a leftover cutoff of the led strips i used. Seems to me that they indeed have small ceramic caps. Inexperienced me initially thought that they were small resistors for some reason, but now it makes more sense that they are capacitors. i.imgur.com/sMKojZo.png \$\endgroup\$ – hmmmniek Jan 22 at 22:29
  • \$\begingroup\$ Yes they're ceramic caps. \$\endgroup\$ – peufeu Jan 22 at 23:10
2
\$\begingroup\$

Try adding decoupling capacitors.

Decoupling capacitors are like sugar and your primary power supply is like fat. The first is fast and on-demand, the second is high energy but slow. If you try to do strenuous activity and your blood sugar is low, you pass out. Same thing with circuits, more or less.

All connections have inductance so sudden changes in current demand produce transient voltage drops or spikes across the trace inductance leading to the IC which can cause glitches and other issues.

Rule of thumb is to place a 100nF ceramic capacitor in parallel with the power pins of every IC as close as possible to the IC. You want a tiny store of reserve charge with minimal inductance to the IC to smooth over these transient current demands. This slows down the current change through the trace inductance as the main supply reacts as therefore reduces these voltage spikes and drops.

More capacitance is not always better. Well, in theory it is, but real capacitors have parasitic inductance too and larger capacitors tend to have more inductance which can defeat the purpose of smoothing high frequency transient currents. The large caps will smooth lower frequency transient currents better though.

\$\endgroup\$
  • \$\begingroup\$ Tried this out real quick by simply pressing the leads of various different capacitors to the 5v and ground of the microcontroller, but not much changed. However, I did see some change in the glitches, but I cant tell if they reduced or not, they did change though. I will read more about this, hopefully I will stumble upon something that will work. \$\endgroup\$ – hmmmniek Jan 22 at 21:31
  • \$\begingroup\$ @hmmmniek In addition to the aformentioned high frequency decoupling caps you added to all your ICs, try adding larger (47-100uF electrolytic) capacitors at the load end of any long power cables. \$\endgroup\$ – DKNguyen Jan 22 at 21:33
  • \$\begingroup\$ tried that, no change either. I "trial and error"-ed a bit more with the capacitors: I added the ferrite core again and pressed my fingers on the microcontroller to remove the interference. Now, when i add a 47uF electrolytic capacitor at the load end of the microcontroller power cables, then the glitching comes back! Does this give you any new clue perhaps ;) ? The capacitors do seem to be doing something .. just have to figure out the right configuration I guess. \$\endgroup\$ – hmmmniek Jan 22 at 21:45
  • \$\begingroup\$ @hmmmniek It's tough to say without actually being there. Are you able to tighten up your wiring at all? Is there a ground line running between your display and MCU? You can also add caps for your LED display. Your MCU isn't the only thing that suffers from trace inductance. For example, if the MCU was controlling a motor, the MCU would have caps, but so would the motor; Just the caps for the motor would be much bigger since the currents involved are much higher but at lower frequencies. \$\endgroup\$ – DKNguyen Jan 22 at 22:01
  • \$\begingroup\$ Understandable. For what I am capable of doing, the wiring around the mcu is as clean and tight as I can make it. The ground between display and mcu is not super direct. The power delivery to the display is separated over multiple wires to spread out the load a bit. All go back to the power supply obviously, and then the same negative terminal on the power supply goes back to the ground of the mcu. Maybe interesting to note, I keep the display power and ground wires relatively long (temporarily around 2 meters i guess). I could try to add caps between the led display tomorrow! \$\endgroup\$ – hmmmniek Jan 22 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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