# Demonstrate PWM with flickering LEDs

Blog Post created by dmercer on Oct 20, 2014

Demonstrate PWM with flickering LEDs.

I recently purchased some flickering LED candles at the dollar store ( 2 for \$1 ) to investigate the flickering LEDs. These LED candles came with a CR2032 3V coin cell battery. Not bad, the LED and battery for 50 cents.

Most of these flame-less LED candles are quite simple circuits. They consist of nothing more than an on/off switch, a 3V coin cell battery and the special flickering LED. The flickering effect is produced by an integrated pulse width modulation (PWM) circuit, inside the special LED as shown in figure 1. These flickering LEDs would make a perfect way to demonstrate PWM in action both visually and with the Analog Discovery scope and logic analyzer.

Figure 1 inside a flickering LED

After extracting the LED from the plastic candle housing I inserted it in a solder-less breadboard along with a 220 Ω current limiting resistor as shown in figure 2. Each time that the LED circuit turns on, current is drawn from the +5 V supply and through the 220 Ω resistor R1 to ground. To observe the voltage across R1 we can connect scope channel 1 to the resistor as shown.

Figure 2, LED test circuit

The LED is on most of the time and is switched off in a pulse width modulated fashion in bursts that make it appear dimmer or to flicker. When the LED is on the current through the LED causes a voltage drop across R1 raising the voltage to about 2.5 V in the case of the LED I was using and the 220 Ω resistor. The current through the LED is much smaller when it is off thus the voltage across R1 goes down to nearly 0 V. So the PWM current through the LED will appear as a PWM voltage that swings from 0 to 2.5V as we can see in figure 3.

Figure 3 Example PWM voltage waveform

From this screen shot we can see one of the PWM bursts. It is 32 pulses long for a total of about 231 mS. The next two screen shots, figure 4 and 5, are close-ups of the beginning and end of the burst. From them we can measure the pulse width and period. For this burst the pulses are low (LED off ) for 4.6 mS and high ( LED on) for 2.65 mS for a total period of 7.25 mS. This comes out to be about a 36% duty cycle.

Figure 4, Beginning of burst

Figure 5, End of burst

Here is another close up screen shot showing the chip transitioning from one pulse width to another.

Figure 6, Changing pulse width

Another way to observe, hear actually, the PWM signal is to replace the 220 Ω R1 with the series connected combination of a 100 Ω resistor and the buzzer/speaker from the Analog Parts Kit.

Not very musical but still interesting.

Looking more closely that the bottom of the pulses, when the LED is off, you might notice what looks like noise. Zooming in closer we can see that there are actually a number of small current pulses as shown in the screen shot in figure 7.

Figure 7, Small current pulses when LED is off

These small pulses are about 7.4 uS wide or at 135 KHz. The peak current is about 75 mV/220Ω or 340 uA. These are most likely due to the clock timer running in the control chip and we can guess that the clock runs at 135 KHz. This will also probably give us a clue as to the resolution of the pulse width modulation.

Now, the question to be answered is how many different pulse widths can the control chip generate? Since the pattern is random it would take a lot of samples to get data on every possible pulse width. This would be very tedious and time consuming using the analog scope tool. This is where using the Analog Discovery Logic analyzer tool would be a huge time saver. The 0 to 2.5 V swing will interface well with the 3.3 V logic inputs of the Discovery digital inputs. Just connect digital I/O pin D0 to the end of R1 as indicated in figure 2.

We will want to capture as many bursts of pulses as possible in a single data record so it will be better to reconfigure the Analog Discovery to apply all the FPGA resources to the logic analyzer. This is done through the device manager available from the main Waveforms menu. Configuration 4 sets up the FPGA for just the logic analyzer, pattern generator and power supplies. This allows 4X the number of digital samples to be captured per buffer compared to the default configuration 1. The captured buffers can be saved to .csv files for analysis. You will want to save the “events” data i.e. 0-1, 1-0 transition times rather than the raw data. That way you can easily calculate the pulse high and low times or duty cycle.

There are interesting consequences to the way that these flicker LEDs work. This means that – even ignoring the yellow light coming out – we have an unusual electronic component that produces a seemingly random sequence of current pulses when voltage is applied. We might use that current to control other circuitry.

As always I welcome comments and suggestions from the user community out there.

Doug