Home  Order  |  DIY Regulator  |  Solo Controller  |  Twin Controller  |  Twin Plus Controller  |  Photos

Bike Light Digital Voltage Regulator/Dimmer Project

D.I.Y.
Regulator

PROJECT

COMPARE FEATURES
to other Light Brain
Controllers

 

 

 Description

The D.I.Y. Regulator is a full featured high performance Lamp Voltage Regulator design that can be used for a variety of lighting applications.  If you already have some knowledge of electronics and programming you can use this project as a starting point for your own design or use it as is.  I expect most users will at least want to experiment with tweaking a few of the parameters.

If you would like to purchase a pre-built and tested lamp regulator, please see the Twin-Plus Controller (it has a few more features too).  I don't currently have plans to sell kits or assembled versions of the DIY controller as it is intended mainly as an informational project for "tinkerers" and hobbyists.  This is also why the hex code is not provided.  I expect the users of this source code to be able to compile the code (or that they are willing to learn).  For information on PIC programming there are many sources on the web (and many good books) out there.   I have tried to comment the code as clearly as I can.  If you are really stuck, send an email and I will try to answer if I have the time (or I may add it to the QandA section below).

You are free to use this design for any personal non-profit non-commercial use.  Build one for yourself, build a couple for your friends.  Have fun.  Please do not copy or re-distribute the information and files presented here.

Please drop me a note if you build the project or use the information presented here.  It helps me determine how much effort to put into this page.  If you have a suggestion for an improvement, let me know.  I might just use it.

 Features

- Various battery/lamp combinations are possible by modifying the code
- Compatible with NiMH, NiCad, SLA, Lithium batteries
- Compatible with most single lamp systems
- Compatible with halogen lamp up to 35 watt (20-watt lamp recommended)
- Battery reverse protection
- Dim-up to extend bulb life
- 99% efficiency

 Downloads

Download Assembly Code  

   Download PIC12C672 version HERE   (OTP / EPROM)
      
Can also be adapted to PIC12F675 FLASH chip with minor code modifications.
        Requires Microchip MPLAB or MPASM to assemble.  (Available free from http://www.microchip.com/)

Alternate Regulation Tables    Download HERE

 

Output

Input range

TABLE A 13 volt 13 - 20 volt
TABLE B 12 volt 12 - 20 volt
TABLE C 7.2 volt 7.2 - 18 volt
TABLE D 6 volt 6 - 18 volt

MS Excel Spreadsheets    Download HERE    (Calculates circuit and code values) 

NEW SPREADSHEET - calculates list of up to 255 table values based on circuit data:    Download HERE 
        Requires Microsoft Excel or compatible file viewer.

 Operation

Turn ON - press and release button

Increase power level - press and release button 

Decrease power level - press and hold button

Turn OFF - press and hold button (from lowest power setting)

 Q and A

How do I change the low battery warning and auto-shutoff voltages for my battery pack? Download the Excel spreadsheet above and use the AtoD Calculator to determine value for your application.  This will allow you to calculate the correct value even if you change the resistors of reference voltage.  Here are some example values for the standard circuit:

A to D values 
Pack voltage # of cells in pack Low battery warn
1.0V per cell
Auto shutoff
0.9V per cell
9.6V 8 86 78
12.0V 10 108 97
13.2V 11 119 107
14.4V 12 129 116
15.6V 13 140 126
16.8V 14 151 136
18.0V 15 162 146

How can I overvolt my lamp a bit more than the included tables allow?  If one of the 4 provided tables does not meet your needs, you can write your own table or try adjusting the resistor values slightly (increasing R1 will increase lamp voltage).  Just remember when adjusting resistor values to check that the circuit is regulating properly through the full range of your battery pack.

I can't find the IRL540N, can I use a substitute FET?  Yes, you need a logic level N-Channel HEXFET with an "on-resistance" (RON) less than 0.1 ohms.

Can the PIC12C672 be erased and reprogrammed?  No.  This is an OTP (one-time-programmable) device.  You can use the PIC12C672(JW) which is an EPROM device, but you will need a UV eraser.  

What is the purpose of "t1min", "t1max" and "t1duty" values?  Do I need to change them when I write my own tables?  Yes, these must be set according to the comments provided in the source code.  These are constants used by the program to identify the start and end of the regulation range (start and end of the table).

How do I write my own regulation tables?  I cannot give detailed instructions at this point, but I can provide a really excellent tool (download HERE requires MS Excel) that pretty much writes the tables for you based on a few circuit values (Output Voltage, R1, R2, and Vreg).  Simply enter these values in the spreadsheet, then cut and paste the resulting "Table Code" for the regulation range you require.  Then set the values for "lowbatt_voltage" and "shutoff_voltage" according to the examples above or your own calculations.  Set t1min, t1max, and t1duty per guidance in the source code comments.  With a little luck, you have a new custom regulation table.  Special thanks to Jordan Richardson for hugely improving my original "Calculator" spreadsheet.

A few tips:  1) Table must start at 254 or less.  2) Don't exceed the available code space for your processor.  3) There are other factors affecting component selection.  4) The spreadsheets are tools, they don't "guarantee" an operating circuit.  5) Nobody's perfect.  I try to eliminate all typos and errors in my code and instructions, but....   6) Let me know if you really get stuck, I'll probably try to help.  7) Don't try to program a PIC, or modify the code without the reference sheet (download from Microchip).....even changing a pin assignment can cause huge problems unless you are familiar with the processor internals.  8)  Have fun!!  If you improve something please let me know.


 


REF PART FUNCTION VALUE Digikey Part #
U1 MICROCONTROLLER, FLASH   PIC 12C672 PIC12F675-04I/P-ND
U2 REGULATOR, Low Dropout uC power & Vref 5.0V, LP2950 LP2950ACZ-5.0-ND
C1 CAPACITOR, Electrolytic Power Filter 22uF, 25V  
C2 CAPACITOR, Tantalum V Reg Feedback 10uF, 10V  
C3 CAPACITOR, low ESR Decoupling 0.1uF  
C4 CAPACITOR, Tantalum A/D Filter 10uF, 10V  
D1 DIODE, Signal Reverse Protect 1N4148  
R1 Resistor, precision 1% Voltage Divider 150K 1% .125W  
R2 Resistor, precision 1% Voltage Divider 40.2K 1% .125W  
FET N CHANNEL HEXFET Current Switch IRL540N IRL540N-ND
LED LED, resistored type Indicator 5 volt LED  
Button Pushbutton, Momentary On / Off / Dim Level Normally Open