uC PWM Driver schematic/source code

PEU

Flashlight Enthusiast
Joined
Feb 26, 2004
Messages
3,602
Location
Buenos Aires / Argentina (I like ribs)
A post by a fellow CPFer inspired me to share with you all how to easily dim a LED with a microcontroller by using PWM (pulse wide modulation)

Here is the schematic:
Variable_Brightness_via_ADC.jpg


and here is the source code:

Code:
@ device INTRC_OSC_NOCLKOUT  'PIC12F683

DEFINE OSC 4

DEFINE ADC_BITS 8 
DEFINE ADC_CLOCK 3 
DEFINE ADC_SAMPLEUS 50 

ANSEL = %00000011  ' GPIO.0 A/D in, rest digital
TRISIO = %00000011 ' GPIO.0 lectura AD,

pote 		var byte
oldvalue    var byte
frecu       con 800     'set  PWM frequency

oldvalue=0
loop:
    oldvalue=pote
    ADCIN 0, pote ' (0-255) 'reads pot position 
    if oldvalue <> pote then 
        hpwm 1,pote,frecu
    endif

GoTo loop
   
End

This schematic shows how to dim a single 5mm led, but it can be used to control the enable pin of a buck/boost controller or a LDO or a FET...
To do it, just remove the led and send the uC pin to the enable pin of the device you are controlling. The PWM level is selected with the potentiometer.

And to make things even more simple, here is a zip file with the schematic, the source code and the HEX file for the ones that dont have a PICbasic compiler:

Variable_Brightness_via_ADC.zip

I hope this introductory post will help develop new cool flashlights :)


Pablo
 
Many THX!!!
Its great idea...
Its possible to build microcontroller regulated driver with dc/dc converter..who working, for example identity with P1D Fenix?I can build driver with regulated dimming but regulation only through on/off switch.Can You help me?Im electronic and I can build this...but I dont know microcontrollers language, I can program , I can build programmer...for example I have Willem and another simple atmega, pic programmers...
Sorry for my not-good english ;-)
Best regads.Calineczka
 
sysadmn said:
For those who are Atmel AVR fans, http://www.atmel.com/journal/documents/issue5/pg41_43_Atmel5_Tiny.pdf

This is a clever starting point because the AVR is also the boost controller.

Here's another: http://cq.cx/smps.pl

This first link its very intrested, I think so I try made it after upgrade to 1W elements...maybe more, I try with another coil/transistor/capacitance.
Second link-beautifull driver, great fotos, but no schematic, no eprom/eeprom for AVR.Have You program for microcontroler?Many thx for answers :)
 
Hi Pablo,

I was going to do the same with my 1 watt Luxeon and Li-ion light.
No converter though, just have the PIC chip drive a low sat NPN (Zetex)
or an N channel Mosfet to do the pulsing. To do this a simple resistor
in series with the base of the NPN or MOSFET gate driven from one of
the outputs of the PIC. Of course a small value resistor in series with
the LED too to keep peak current low enough.
Efficiency would be as good as with a converter with some input voltages,
but not as good with others...that's life :)
 

Latest posts

Top