Sunday, September 23, 2012

Dimming a 12V LED strip with a mosfet and PWM

Dimming a 12V LED strip with an N-channel power mosfet is pretty straightforward. In this experiment I'm using 5 meter of cool white LED strip running at about 800 mA giving 10 Watt.

the basic setup
 An Arduino Duemilanove (my trusty lucky white one) is used to provide pulse with modulation ( PWM ). Digital pin 9 and 10 (also known as OC1A and OC1B) are used. They both use the Timer2 facility of the atmega328p microcontroller which means I can have them output exactly the same PWM signal. Digital 9 is used to drive the mosfet and digital 10 is only used for displaying the unloaded PWM signal on the scope.

Basic PWM setup schematic


PWM on the scope
On the scope you can see the yellow PWM signal driving the mosfet and the blue one that is not connected to any load.

The following Arduino sketch does a simple PWM sweep in 10 steps per second:

 1 void setup()
 2 {
 3   pinMode( 9, OUTPUT);
 4   pinMode(10, OUTPUT);
 5 }
 6 
 7 byte b = 0;
 8 
 9 void loop()
10 {
11   analogWrite(9, b);
12   analogWrite(10, b);
13   delay(100);
14   ++b;
15 }

This gives a PWM signal as shown in the (crude) video below.


Not shown in the video is that this also nicely dims the LED strip.

This is actually good enough for simple dimming, but lets look at it more in detail. More specific lets look at the rise and fall of the PWM signal at the gate of the mosfet.

a detailed look at the voltage at the rising edge at the gate of the mosfet

Whats interesting to see is that it takes about 600ns in total to go from 0V to 5V at the mosfet gate.
The first sharp rise is from 0V across the threshold voltage of the mosfet to the Miller plateau voltage and takes about 100ns. At this point the current through the mosfet is already at the peak but the voltage across the mosfet from drain to source still has to drop from the 12V it starts at. This drop happens across the relatively flat part of the peak in the middle called the Miller plateau region. After this drop the Drain-Source voltage for this particular mosfet will be a bit above 150mV and the remaining 11.85V will be across the LED strip. Finally the voltage at the gate rises to 5V which will slightly lower the on-resistance of the mosfet and the final Drain-Source voltage should be about 100mV.
As mentioned all this takes about 600ns which is not very fast. Looking at the specification of the IRF540 mosfet a rise time of about 35ns should be possible.

I got quite some interesting info concerning mosfet gate drivers from this Texas Instruments paper.

The basic idea to get a faster transition is driving more current in the mosfet gate then the measly 50mA that the digital pin of the Arduino/atmega is capable of providing.

One solution suggested by the paper is to use a Bipolar totem-pole driver. The idea behind that is that by using the very fast operation and large gain of bipolar transistors the gate can be charged and discharged quickly.

adding the bipolar totem-pole mosfet driver 
When the PWM signal is high the NPN transistor is on and the PNP transistor is off. This allows a large current to flow from the 5V power supply and the tank capacitor C into the mosfet gate.

PWM high and NPN on
When the PWM signal is low the PNP transistor is on and the NPN transistor is off allowing for a quick sink of the charge on the mosfet gate into ground.

PWM low and PNP on

For the transistors a BC639 NPN and a BC640 PNP do the job. R is 3.3Ω. RB is 22Ω. RGATE is 4.7Ω. C is a big 1000μF electrolytic.

final setup
improved rise time
A rise time of 44ns using the bipolar totem-pole driver is not bad at all.

Lets take a look at the other side of the wave form.

fall ringing
There is some nasty ringing on the fall side of the pulse. This won't affect the dimming but it's interesting anyway to take a look what is happening.

First thing I checked is RGATE. Increasing the resistance off RGATE does lower the ringing but it also kills the just gained speed improvement.

Then I noticed something weird: if I unrolled part of the LED strip the peaks of the ringing got larger. I then replaced the LED strip by a single LED and surely the ringing is all but gone.

I assume the capacitance/inductance of the 5 meter LED strip and/or all its LEDs cause the ringing.

Adding a shunt resistor across the LED strip lowers the amplitude of the ringing but it requires quite a low ohm resistor which in turn gets very hot when there is 12V across it, and it wastes a bit of energy.

Measurement with the scope shows that the ringing is at about 3.5Mhz. A simple shunt capacitor of 100nF should nicely act as a low-pass filter. If we presume a parasitic resistance of 1Ω, using f = 1/(2*pi*R*C) gives about 1.5Mhz cut-off frequency for the filter.

schematic with CSHUNT added


with 100nF filter
That certainly looks nice. I still don't think it is more then aesthetics though..

 I'd love to hear comments on this! Either here or on G+.
Post a Comment