I'm wondering why are you using an external 4Mhz crystal instead of 16LF628's internal oscillator? Or the LF version doesn't have one? That could save some power and reduce circuit complexity. -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU] On Behalf Of Olin Lathrop Sent: Saturday, September 07, 2002 7:37 AM To: PICLIST@MITVMA.MIT.EDU Subject: Re: [PIC:] [EE:] Driving a 15W LED? > Any thoughts on using the PIC (which will also be in the circuit) for > regulating the LED current? Yup, done that. See the schematic at http://www.embedinc.com/pic/light.pdf. This was something I whipped up quickly the day before I was heading off to the woods of Maine for a week, so the design was limited to parts on hand. The purpose of this circuit is to run a constant 20mA thru the string of 4 LEDs D2 - D5. These are bright white, and need a bit over 12V total. The battery is a rechargeable NiMH pack with a useful voltage range from 4V down to about 2.5V. The PIC is a 16LF628 because that was the smallest L part I had around. The basic algorithm is to do a single fixed pulse if the current is too low, the voltage not too high, and the previous pulse is done. The port B passive pullups are enabled. The B-E voltage of Q2 is used as a cheap reference with R4 the current sense resistor. Q2 pulls RB1 low if the LED current is above the regulation threshold. Q5 works similarly except that it senses the LED power voltage. The purpose of this is to keep the circuit from destoying itself in case there is ever a break in the LED current path. Q5 triggers at about 15V, which is above the 13V or so needed to run the LEDs, but low enough to keep things from getting fried. Therefore RB1 high means another pulse is desired. Q3 turns off during the flyback phase of a pulse, allowing RB0 to go high. RB0 is set to catch rising edges, so the INTF bit gets set when the previous pulse is over. However, this mechanism only works when the LED voltage is 700mV or more higher than the battery voltage, so it is not reliable during startup. The firmware therefore also uses a timeout to decide that the previous pulse is over, which should only kick in during initial power up. When all the conditions are met, a pulse is started by raising RB7 for a fixed time. This is directly tied to the gate of Q1. These are amazing little FETs that have only 23mOhm on resistance with 2.8V gate drive, even better with more. Inductor L1 charges while Q1 is on, and dumps its energy onto the LED supply thru D1 when Q1 is turned off. The firmware then waits for INTF to get set indicating the pulse is over, then waits for RB1 to be high to do another pulse. Efficiency was only 74%, but there are a number of improvements I didn't have time to make or didn't have parts in stock. I think in this case I made the Q1 pulses too long, thereby increasing I*R losses in the inductor and increasing the losses in D1. The thing worked great, see the attached picture. I built the circuit one-off on a piece of perfboard. Unfortunately you can't see the circuit itself because it's all wrapped up in electrical tape. I also used the tape to make a pocket for the battery. That's the green thing with the wire coming from it. I epoxied the LEDs to the perfboard you see and rigged up a mount with two paper clips to clip it to the visor of a hat. A used margarine container gave its life for the white bracket. For now the cord runs thru another paper clip behind the right ear and then down into the shirt to a pocket somewhere. The circuit is small and light enough that I think it could be mounted on the back of the hat somehow. I'd like to make a few real circuit boards, but haven't found (haven't looke real hard either yet) a nice way of holding the battery in place. Anyway, it seemed to work at least as well as any other hiker's headlamp. I had no problem walking around the woods with this thing at night. One fully charged battery pack lasts for about 4 hours. These things are small and light (about 3 AAA), so it's easy to carry several of them. I've been thinking of similar circuits where a little more accuracy is needed. I haven't done this yet, but I'm thinking of using a 12F629 and using its built in comparator and an external reference (LM385-1.2, 1.23V @ 20uA). -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body