uC controlled 6-level fixed LED striplight w/ schematic + code

zipplet

Flashlight Enthusiast
Joined
Dec 11, 2006
Messages
1,139
Location
Ireland
Hi,

A couple of months ago I built a simple uC controlled LED driver. It can dim a 12V LED strip or several strips in parallel up to the current limit of the MOSFET switch - which is probably around 40A :)

The dimming method is a very high frequency PWM and it is not noticeable even when I put a desk fan underneath the light. I could have built a variable constant current supply instead but it would have been a linear design and not very efficient, whereas the PWM method is probably 99%+ efficient.

I built and installed this light for my brother (hence the wallpaper!) and one of the design goals was for it to be very easy to operate without needing an instruction manual.

fixedled1.jpg


This is the control box and I've deliberately taken the image like this to show the glowing green power switch. I used a switch designed for illuminated keypads with a removeable transparent keycap. I printed a power symbol and cut it to size then snapped the keycap on. Looks pretty cool I think :D. The installation could have been a bit neater but I was limited on time to fit it.

All 3 buttons are momentary switches. There is a red indicator LED at the right (barely visible in the pic) which blinks when buttons are pushed. This is especially useful with the black/red buttons which don't have any tactile feedback.

While the light is on, a push of the red button increases the light level and a push of the black button decreases the light level. Holding either of these buttons while pushing the power switch will start the light on the lowest or highest level. This was done so that the light could be started on the lowest level without disturbing others in the room at night.

The last level used is remembered but not if power is removed from the microcontroller. The microcontroller does have serial EEPROM but I had no need to store the last level in the EEPROM because this particular light is wired to a 12V backup power system I designed a year ago :) It would be trivial to change this - if anyone is interested I'd be willing to help.

Now a couple of very cropped images of the light underneath a shelf. I can't show better pics until my brother tidies his room.. you would not want to see what's lurking :eek: As soon as he does I'll post a couple of shots of the light in a dark room, it's bright enough on high that you can comfortably stay in the room and even read during a blackout :twothumbs

fixedled2.jpg


fixedled3.jpg


Schematic

The fuse should be appropriately sized according to the load from the LEDs at full brightness. It's just incase the output is shorted to prevent burning out the MOSFET and fuses are just a good thing generally, I probably use too many of them. D1 is the LED that blinks when buttons are pressed. D2 is an extra precaution and could be omitted. If you use D2 you may wish to use a schottky depending on the gate threshold of the MOSFET. A PIC16F627A may be used instead (and is recommended as the 627 has been discontinued). The MOSFET should be a logic MOSFET or one with a sufficiently low gate threshold voltage.
sch_uc.png


The microcontroller needs a simple 5V supply using a 7805 or so, for reference here is mine:
sch_ucpsu.png


The LED on the 5V supply is wired to the green pilot light on the switch. To increase efficiency slightly the pilot LED could be driven directly from the 12V supply with a different resistor instead but I prefer to see the status of the 5V supply.

Mine is powered from a 12V backup power supply which could peak at 13.8V, so I use a simple 12V LDO regulator circuit to drop the voltage to 12V to protect the LED strips. The rest of the circuit could happily work on 30V perhaps depending on the 5V regulator and MOSFET you use. The nice thing is this is easily adaptable.

Microcontroller

I used a PIC16F627 originally but later switched to the 16F627A as I fried the 627 during development (ESD sucks!). Any similiar microcontroller should be fine and it should be easily adaptable, just make sure the uC has a CCP pin. You will need to alter the timings if you don't use a 4mhz oscillator. As the source code is too long to post here I'll link to the source code and a large version of the schematic. My apologies for the messy code ;)

Large full schematic
Microcontroller source code

Adapting the circuit for other lights

This circuit could possibly be used to drive a buck/boost converter to regulate the light output. I have not tried this. It's really designed for fixed LED light strips (which have the LEDs wired in a series+parallel configuration and a few resistors). Standby current is not a lot but too much to use from small batteries. This could be reduced by omitting the pilot light and adding code to put the uC to sleep when waiting for the power switch.

Altering the levels

Near the bottom of the source code there is a table:

Code:
table_brightness
        movwf   ta                              ; save W (index to table)
        movlw   HIGH    table_brightness        ; get high addr into W
        movwf   PCLATH                          ; set PCLATH
        movfw   ta                              ; restore W
        addwf   PCL                             ; computed GOTO
        dt .00                      ;off
        dt .00                      ;level1 (special handling)
        dt .01
        dt .25
        dt .70
        dt .128
        dt .255

The numbers beginning with a full stop after the dt statements specify the PWM period for each level. Do not alter the first couple as they are special cases - the first is ignored because the light is off and the second is for level 1 which is handled specially as I'll explain.

Levels 2 to 6 follow. The higher the number the longer the PWM period is. 255 means the MOSFET is never off (full brightness). The response is not linear and it took quite a lot of experimentation to set these levels nicely for the LED strip I'm driving.

Back to level 1. The PWM period on the 16F627A is a 10-bit register. The light levels set the most significant 8-bits of the register. The 2 least significant bits are always set to 01. As the table for level 1 specifies that the most 8 significant bits will be 0 the light will still be on due to the 2 least significant bits but very dimly and this was a perfect brightness for level 1.

Note that there is quite a jump in light produced from a value of 0-1 in this table.

Have fun :grin2:
 
Nice project.

What frequency PWM?

What is the purpose of D2?

What Mosfet did you use? You might want to recommend some choices.
 
Hi,

D2 was me being overly cautious - incase the MOSFET shorted in such a way as to place 12V on the gate (and uC) hence why I mention that it's optional. I doubt it's needed really.

For the MOSFET I believe I used an STP36NF06L or a variation of - from http://www.rapidonline.com/Electronic-Components/Discrete-Semiconductors/MOSFETs/TO-220-Logic-level-power-MOSFETs-N-Channel/77687

PWM frequency should be around 15.6Khz! I'll pull up some datasheets and double check - it was a couple of months ago.
 
Top