1

I'm attempting to drive a matrix of LEDs. Columns. Rows. It flickers too much for my liking, so I tried smoothing the LEDs with capacitors, but I'm getting very odd behaviour.

Here is a minimal schematic of my test setup:

schematic

The A1-A3 and C1-C3 lines are tristated when not in use. They don't go high/low, they go active/tristate. I figured this would allow me to parallel a capacitor across each LED without them affecting each other, but apparently not.

If I close the A1/C1 switch, I would expect the capacitor to affect the operation of that LED and no others.

Test sequence:

  1. Activate A1/C1. Wait.
  2. Deactivate A1/C1.
  3. Activate A3/C2. Wait.
  4. Deactivate A3/C2.
  5. Go to step 1.

I expected D1 to light, then fade out whilst D6 was lit. I expected the other LEDs to remain dark.

What actually happens is that D3 and D4 flicker noticeably as well. Given that the control lines are tristated when not in use, I'm at a loss to understand how the stored power is getting from the capacitor to these other LEDs.

It occurred to me that maybe some LEDs are passing reverse-bias current. LEDs aren't perfect diodes, but given that D1 is conducting forwards, I wouldn't expect that to be a factor.

JRE
  • 67,678
  • 8
  • 104
  • 179
Sod Almighty
  • 1,295
  • 13
  • 22
  • the problem may be caused by the code – jsotola Nov 10 '22 at 16:35
  • We often forget about microcontroller clamping diodes that snub voltages **below GND**. These diodes might provide a path for current to flow from capacitor to other LEDs. – glen_geek Nov 10 '22 at 16:37
  • The code is simple; and I have already tested with a meter to see if any of the other lines are being activated. – Sod Almighty Nov 10 '22 at 16:47
  • @glen_geek an interesting idea. But there aren't any voltages "below ground" here. That would require A1 to go to ground, and it is instead tristated. – Sod Almighty Nov 10 '22 at 16:48
  • Would be nice to know what microcontroller you have, and the current through the LED's – Voltage Spike Nov 10 '22 at 17:11
  • I'm using an ESP8266. I figured drawing that on the schematic would overcomplicate the issue. The LEDs are running on 3.3V, so if we assume a 1.8V drop (for red LEDs), the current would be around 0.75mA per LED. – Sod Almighty Nov 10 '22 at 17:15

2 Answers2

4

I think td127's answer is correct. After you've turned off A1 and C1, and turned on A3 and C2, current takes the following path:

Starting from the microcontroller pin connected to A3, the current goes forwards through R3 and D3 to C1, then through the capacitor in the negative-to-positive direction to A1, then through R4 and D4 to C2, then to the microcontroller pin that's connected to C2.

(The image has a text description of the path as alt-text. The pentagons indicate that current goes from the A3 pin of J1 to the A3 lead of R3.)

The microcontroller and the capacitor are effectively in series, so their voltages add. If the microcontroller is putting out 3.3 V and the capacitor is still charged up to 3.3 V, that adds up to 6.6 V. The two LEDs are also effectively in series, and 6.6 V is enough to light up the two LEDs in series.

Another way to see this is to apply Kirchhoff's voltage law to the circuit. If \$V_{uc}\$ is the voltage between A3 and C2 (produced by the microcontroller), \$V_{cap}\$ is the voltage across the capacitor, and \$V_{D3}\$ and \$V_{D4}\$ are the voltages across the diode-and-resistor pairs, we find that we must have

$$V_{uc} + V_{cap} = V_{D3} + V_{D4},$$

so D3 and D4 will light up if the capacitor hasn't discharged enough by the time that the microcontroller puts out voltage on A3 and C2.

This happens regardless of whether or not the clamping diodes are conducting. And I don't think that the clamping diodes will conduct, because D3 and D4 will probably have approximately the same voltage across them, and that voltage will be no greater than \$V_{uc}\$. If one of them does conduct, that will decrease the voltage across one of the LEDs, and thereby increase the voltage across the other one. It looks like there's no way for both clamping diodes to conduct at the same time.

Cassie Swett
  • 2,991
  • 12
  • 21
  • Yeah, I think you effectively undebunked my hypothesis. You've earned the checkmark! – td127 Nov 11 '22 at 02:52
  • Wow. I never even though of that. I mean, @td127's idea made sense to me, in conjunction with the clamping diodes, but the idea of the capacitor being _in series_ with the microcontroller output didn't occur to me. This is a great answer, thank you! – Sod Almighty Nov 11 '22 at 06:55
3

Here’s my hypothesis:

When the capacitor is charged it holds A1 high and C1 low (for a while) even after they are tristated.

The capacitor will start discharging through D1 when A1/C1 is tristated, but as soon as A3/C2 is activated (assuming capacitor still has some charge) the C2 will provide a parallel discharge path from A1 through D4.

Likewise, when A3 is brought high then there is a residual discharge path through D3 to the still-somewhat charged capacitor. These parallel discharge paths manifest as flicker.

To reduce flicker you must run at sufficiently high update rate. I wouldn’t waste any time in tri-state – move on to the next row/column as soon as possible.

td127
  • 2,932
  • 6
  • 13
  • No, C2 doesn't provide a discharge path through D4, because the charge on the capacitor doesn't want to get to circuit ground via the microcontroller. It wants to get to the other side of the capacitor. For current to flow, there has to be a closed loop. Granted there is a path from A1 to C2 via D4, but there is no path back to C1. Ergo, no current flows back to the capacitor, and it does not discharge (except via D1 of course). – Sod Almighty Nov 10 '22 at 17:30
  • Do you mean in combination with the clamping diodes @glen_geek mentioned? As in, a tristated microcontroller pin is still being clamped? – Sod Almighty Nov 10 '22 at 17:41
  • It seems all the pins have clamping diodes even when tristated, so you may well be correct. Presumably if I used transistors, this would be mitigated? Incidentally, I know that it's better to increase the update frequency, but I'm trying to solve a specific problem: I want to use a TM1637 to drive an LED display, but the update frequency is dire! – Sod Almighty Nov 10 '22 at 17:51
  • Yeah, I think you effectively debunked my hypothesis. – td127 Nov 10 '22 at 18:25
  • No, I think you might be right. – Sod Almighty Nov 10 '22 at 18:36