Attention Digital Logic Gurus - Flashlight Mod related questions

Candle Power Forums

Help Support Candle Power:

Doug S

Flashlight Enthusiast
Joined
Jun 20, 2002
Messages
2,712
City & State/Province
Chickamauga Georgia
Below is a response to a question I gave in another thread. I am wandering a bit from my core areas of expertise. I am interested in hearing from others about favorite/most simple ways of converting momentary switch closures into maintained toggle action. Also the related topic of contact debouncing, etc. IMHO, these digital switching techniques offer many advantages for mods, especially where compactness and hi-reliability are prime objectives.
Originally posted by LED HED:
Here's another question for you electronics geniuses: how do I add a tiny on/off switch into an LED circuit? Appearantly, the manufactures can't make a really small click-type switch because the mechanism is too large to fit in the case. There are momentary contact switches that are tiny however. So, the real question is: where do I find a circuit for on/off using a momentary contact switch? Or maybe a circuit which can dim the LED also. Kind of a three position setup: on, dim, off.

thanks
<font size="2" face="Verdana, Arial">Good topic! I have been thinking about starting a similar thread and still might do so if this one doesn't get sufficient attention. One approach is to use the momentary switch as an input to a digital logic IC. This may sound like a complicated solution but it has some advantages. It can be made very compact and by using the output of the IC to drive a very low resistance MOSFET it can be made to handle high currents. It allows a consistantly low resistance path for the main current unlike many flashlight grade mechanical switches. For a simple ON-OFF action a type D flip-flop wired as a "T" toggle is the way to go. For more complicated multiple output arrangements [e.g., multiple levels or light combos] a counter IC can be used. The old CMOS digital logic families such as the CD4000 or MM54C/74C draw so little current [<1uA] that they are wired to be energized all the time. They will have no appreciable drain on the battery even after years of standby. One consideration is that momentary switches have contact "bounce" which may be seen by the logic as multiple switch depressions. You can correct for this with "debounce" circuitry which effectively allows the IC to see only one contact closure in a given time period. I don't work with digital logic much and don't have any online tutorials to direct you to. Maybe one of the more digitally oriented gurus [from the era when cars had carbs] can help out. The younger guys are going to suggest a microprocessor solution but if you're like me, it will not be worth the effort to learn to program them.
 
And at around $20 a pop, not quite in the price league. Take a look at the Microchip 12F675.

10 bit A/D 1K word of Flash program, built in OSC, serially programmable, etc. They come in some pretty small packages, too. Oh, and in 25 quantity, they're about $1.25 from Digikey. If you don't need the A/D, there's a cheaper one that's just over a buck. Everyone and their dog (in the microcontroller world) knows how to program them, so tools are free and easy.
 
Another chip to consider: The AVR ATTINY15. Also available from Digikey, cheap, and has a built in high frequency PWM and pre-amp for the A/D converter. You could use this chip both for control (on, off, dim, etc.) and as the core of a switching regulator to run LEDs.

-Jon
 
I've heard a lot of good stuff about the AVR chips. If anyone wants references, I'll be glad to provide them. The instruction set looks quite complete and pretty orthogonal.

I'm still in love with the Ubicom SX parts.
smile.gif
I feel the need, the need for speed....
 
As an Amazon Associate we earn from qualifying purchases. Product prices and availability are accurate as of the date/time indicated and are subject to change.
Originally posted by Doug S:
Below is a response to a question I gave in another thread. I am wandering a bit from my core areas of expertise. I am interested in hearing from others about favorite/most simple ways of converting momentary switch closures into maintained toggle action. Also the related topic of contact debouncing, etc. IMHO, these digital switching techniques offer many advantages for mods, especially where compactness and hi-reliability are prime objectives.
</font><blockquote><font size="1" face="Verdana, Arial">quote:</font><hr /><font size="2" face="Verdana, Arial">Originally posted by LED HED:
Here's another question for you electronics geniuses: how do I add a tiny on/off switch into an LED circuit? Appearantly, the manufactures can't make a really small click-type switch because the mechanism is too large to fit in the case. There are momentary contact switches that are tiny however. So, the real question is: where do I find a circuit for on/off using a momentary contact switch? Or maybe a circuit which can dim the LED also. Kind of a three position setup: on, dim, off.

thanks
<font size="2" face="Verdana, Arial">Good topic! I have been thinking about starting a similar thread and still might do so if this one doesn't get sufficient attention. One approach is to use the momentary switch as an input to a digital logic IC. This may sound like a complicated solution but it has some advantages. It can be made very compact and by using the output of the IC to drive a very low resistance MOSFET it can be made to handle high currents. It allows a consistantly low resistance path for the main current unlike many flashlight grade mechanical switches. For a simple ON-OFF action a type D flip-flop wired as a "T" toggle is the way to go. For more complicated multiple output arrangements [e.g., multiple levels or light combos] a counter IC can be used. The old CMOS digital logic families such as the CD4000 or MM54C/74C draw so little current [<1uA] that they are wired to be energized all the time. They will have no appreciable drain on the battery even after years of standby. One consideration is that momentary switches have contact "bounce" which may be seen by the logic as multiple switch depressions. You can correct for this with "debounce" circuitry which effectively allows the IC to see only one contact closure in a given time period. I don't work with digital logic much and don't have any online tutorials to direct you to. Maybe one of the more digitally oriented gurus [from the era when cars had carbs] can help out. The younger guys are going to suggest a microprocessor solution but if you're like me, it will not be worth the effort to learn to program them.</font><hr /></blockquote><font size="2" face="Verdana, Arial">Hey Doug,
Thanks for trying again with this topic. So, where do electronics no-nothings like me go from here? Back to school for an education or can one of you guys create some hardware for guys like me and make it available for sale. On the other post, someone was scavenging switches and innards from other lights, this worked but obviously isn't cost effective. Alternatively, I'm still searching for those switches.
Thanks
 
CYGNAL has a COMPLETE development kit for $99 which includes

) Programmer
) C Compiler
) Assembler
) Debug board with processor

The "pill" version of the CPU chip is about $3; the dip version (which most people can solder to) is about $8

www.cygnal.com

About 10yrs ago, I used the Intel 8051 to make an 8x8 array of 3-color (Red, Green, 2xBlue) LEDs for a rippling wave effect that would cycle thru the colors - I wrote my own PWM routines (since I needed 24 pins) using a very simple interrupt handler - and it worked perfectly
 
Originally posted by Doug S:
.... The younger guys are going to suggest a microprocessor solution but if you're like me, it will not be worth the effort to learn to program them.
<font size="2" face="Verdana, Arial">Well, I'm not a younger guy and not an older guy
smile.gif
. I work on both carbs and fuel injection computers
winkie.GIF
winkie.GIF
. Here's my 2 cents.

TI sells single device logic. They have a single "D" flip flop in a 5 lead SOT-23 package (3mmx3mm) which you could easily mistake for a broken pencil lead tip, but is large enough for us patient types to solder by hand. The part number is SN74LVC1G80. DigiKey will sell them for 50 cents each, or a dime each if you buy a lot. They can tolerate 5V, and supply 32mA which is plenty to drive a FET, a transistor, or a single LED. They consume 10uA worst case so you can leave them on all the time.

If you're a real sick-o, they sell the same part in a package they call "nano-star" which is basically 1.5 x 1mm. It's a ball grid array, and you could easily mistake these for pepper grains. One good sneeze with a dozen of these on the table, and you'd never see them again. Same specs.

For either of these, the tactile momentary switch would be far larger than the rest of the circuit.
Basically, connect the "D" input to the "not Q" output and connect that output to your FET, transistor (with base resistor) or LED. Then connect a 4.7M ohm or larger resistor to the CLK input and ground. In parallel with that resistor, connect a 0.001uF cap to ground. Also connect one end of the momentary switch to the CLK input, with the other end to the positive power supply. If the switch behaves erratically, you might need a 0.0047 cap, but I doubt it. Values are not critical - use what you have.
Use a low gate threshold FET (2.5V or so), or a low saturation voltage bipolar (like those Zetek parts). This type of circuit would work with any CMOS part - such as the HUGE (14 pin DIP) CD4013, which happens to tolerate up to 15V. I say huge because they are about 5/8" long, won't disappear when you sneeze, and can be seen without a magnifying glass
grin.gif
.

There you have it, a debounced click-on, click-off switch for < 50 cents in quantity.

Of course, I'd be tempted to buy a 12C6xx PIC microcontroller in a SOIC, use the internal OSC, and code ON/OFF plus dimmer, auto off, low batt indication, flasher, etc. This would realistically cost more like $3 bucks total. I've already written the code for this in HiTech "C" and fooled with it on a 16F8xx series part just for fun. The switch gets a little too busy when you load too much functionality on it, so in a real light I'd probably just do ON/OFF and one or two DIM levels with optional auto off.
 
Originally posted by php_44:
</font><blockquote><font size="1" face="Verdana, Arial">quote:</font><hr /><font size="2" face="Verdana, Arial">Originally posted by Doug S:
.... The younger guys are going to suggest a microprocessor solution but if you're like me, it will not be worth the effort to learn to program them.
<font size="2" face="Verdana, Arial">Well, I'm not a younger guy and not an older guy
smile.gif
. I work on both carbs and fuel injection computers
winkie.GIF
winkie.GIF
. Here's my 2 cents.

</font><hr /></blockquote><font size="2" face="Verdana, Arial">php_44: I was about to give you my vote for honorary "old guy" until you went off on that PIC microcontroller stuff at the end
grin.gif
Actually you and I are singing from the same page. While there are several other manfacturers that make their own version of the tiny single [and double] gate logic parts, I had selected that very same TI part for the simple ON-OFF function you have described. I like your debounce circuit better than what I was using since yours uses one less component than mine. Your circuit is even better IMHO than you have described it. You mentioned the 10 uA device current which is the max specified on the datasheet. Even though the datasheet doesn't give a "typical", the reality is that it is under 1 uA. I think that some of the microprocessor solutions that have been suggested overlook the device quiescent current consideration. With the very low Ron, low gate voltage MOSFETS in SOT-23 and micro6 packages now available, Your circuit can be implemented in small quantities for just over $1 or so. This figure includes all components, even the microswitch itself. Your selected TI part can handle up to 6.5V which would cover up to 4 alkaline cells. You cannot buy a good quality mechanical switch for anywhere near this cheap.
For the application where incandescent lamps are the load, soft-start [lamp inrush current control] can be simply incorporated by adding a capacitor to the gate of the Mosfet and a resistor from the logic output to the Mosfet gate. Select an RC time constant around a second or so. If the resulting slow turn-off is a problem, this can be eliminated by paralleling the resistor with a diode in the appropriate direction.
 
Originally posted by Doug S:
I was about to give you my vote for honorary "old guy" until you went off on that PIC microcontroller stuff at the end
grin.gif

<font size="2" face="Verdana, Arial">These days I do all I can to fight off that "old guy" title
smile.gif
.

I agree that the single gate would in practice have a very-very low idle current consumption. It's also simple - which is very appealing.

Surprizingly, the PIC12C508/9 are specified to have a "sleep" state current consumption of 4uA max and 0.25uA typical. You'd program the part to be sleeping when the light was off, with a wake up on button press.

Sickeningly, the PIC solution would have a lower parts count - you could eliminate the resistor and the cap. (The I/O pins can be programmed for weak pullup - so the circuit can consist of the PIC, a switch to gnd, and the FET). Debounce would be done in the firmware - along with dimming, etc. In fact, it would be simple to write firmware to implement various handy features for a light modder that could be enabled or disabled when the light was built. Features like soft start, auto-off, battery indicator, an extra "mode" button, etc, could be enabled or disabled when the light was built by tying PIC pins to gnd or supply voltage (I'd have to work out a means to do this without affecting sleep current).

It's frustrating that the elegant and simple solution has two more components than the "nerdy" one, but at least the PIC solution is much more expensive
smile.gif
.
 
Originally posted by LED HED:
Hey Doug,
Thanks for trying again with this topic. So, where do electronics no-nothings like me go from here? Back to school for an education or can one of you guys create some hardware for guys like me and make it available for sale. On the other post, someone was scavenging switches and innards from other lights, this worked but obviously isn't cost effective. Alternatively, I'm still searching for those switches.
Thanks
<font size="2" face="Verdana, Arial">LED HED: Trust me, scavenging those switches may be *much* more cost effective than going back to school
wink.gif
By all means, continue your search for the ideal compact switch. I have spent many hours on this myself and have discovered the same thing that you have so far; that very compact alternate action switches are hard to find. One thing you may wish to look at is using magnetic reed switches. I have seen them as small as 0.3" long and less than 0.1" in diameter. Some waterproof diving lights use reed switches.
 
Hello Doug and others,

Nice topic Doug :-)

I've given a little thought to this a few times
myself but never went anywhere with it.

My input now will be to remind everyone about
the simplicity of the 'touch' switch.
Two contacts and your finger to short them
and you've got an input to a cmos logic gate
or transistor. One contact to v+ turns it on,
another contact to ground and it turns it off.

I've used this idea to make a touch dimmer
switch. Pressing hard on the contacts makes
more light; less pressure less light.
You also need a 20meg resistor across the contacts
for this one.

Take care,
Al
 
Originally posted by php_44:
</font><blockquote><font size="1" face="Verdana, Arial">quote:</font><hr /><font size="2" face="Verdana, Arial">Originally posted by Doug S:
[QB ....very compact alternate action switches are hard to find. ....Some waterproof diving lights use reed switches.
<font size="2" face="Verdana, Arial">Yes good compact alt action "push/push" switches are hard to find. DigiKey sells panasonic miniature click on/off push-push switches. Their part #P1162S-ND is 11mm square and handles 200mA - pretty small. They also have a P8102S-ND that handles 3A, and is just slightly larger at 12mm X 12mm X 16mm. There are others in the catalog, but their current handling capability is lacking. I have some of these, and they work very well. The acutation force is low and switch travel is short, so gloved operation behind a rubber dome might not have that positive feel of a purpose built flashlight switch. They are much quieter though - there's no quiet piercing CLICK! I have three in use for custom lights I made for my kids (RGB flashing / fading lights). For my lights - I start with a body having a good push-push switch built in and mod from there.

About reed switches.... Be careful to get a reed switch that can handle enough current. Their abilities vary widely, and some can handle a lot of current while others will weld in an "on" state with very little current - especially with a high inrush current like an incandescent bulb would cause.

Mechanical, Electronic, or microprocessor controlled - so many options - so little time
smile.gif
.[/QB]</font><hr /></blockquote><font size="2" face="Verdana, Arial">php_44, all good input! I have never played with membrane switches. Do you have any experience or comment on these? I am always interested in switches which offer good environmental protection.
 
Originally posted by Doug S:
[QB ....very compact alternate action switches are hard to find. ....Some waterproof diving lights use reed switches.[/QB]
<font size="2" face="Verdana, Arial">Yes good compact alt action "push/push" switches are hard to find. DigiKey sells panasonic miniature click on/off push-push switches. Their part #P1162S-ND is 11mm square and handles 200mA - pretty small. They also have a P8102S-ND that handles 3A, and is just slightly larger at 12mm X 12mm X 16mm. There are others in the catalog, but their current handling capability is lacking. I have some of these, and they work very well. The acutation force is low and switch travel is short, so gloved operation behind a rubber dome might not have that positive feel of a purpose built flashlight switch. They are much quieter though - there's no quiet piercing CLICK! I have three in use for custom lights I made for my kids (RGB flashing / fading lights). For my lights - I start with a body having a good push-push switch built in and mod from there.

About reed switches.... Be careful to get a reed switch that can handle enough current. Their abilities vary widely, and some can handle a lot of current while others will weld in an "on" state with very little current - especially with a high inrush current like an incandescent bulb would cause.

Mechanical, Electronic, or microprocessor controlled - so many options - so little time
smile.gif
.
 
Originally posted by Doug S:
php_44, all good input! I have never played with membrane switches. Do you have any experience or comment on these? I am always interested in switches which offer good environmental protection.
<font size="2" face="Verdana, Arial">For non-environmentally protected switches, I usually use a tactile switch with a long enough attached post to poke through the case I'm putting the switch in.

For a more weather proof option, I buy a tactile switch with a low and wide button surface. I put the switch right at the case surface (or even outside the case) and cover it with a weather proof material. The covering is the tough part. Rubber sheeting (inner tube or plumbing stuff), or self stick heavy gauge vinyl work. Sometimes good quality tape works (like taillight repair tape). I suppose you could use silicone RTV if you were careful. In flashlights with a rubber outside shell - you can wedge such a switch between the hard shell and the rubber covering if you pick a good spot.

I've never used membrane switches as I've only seen them as part of a keypad or other assembly, but they would work fine in the circuits mentioned in this thread. A can see it now - a flashlight with a control panel. I guess the "Eternal Lights" are like this.

You can make a membrane switch using a PCB with two sets of contact fingers (take apart a cheap calculator to see what I'm talking about), an insulating spacer with small holes where the fingers are, a metal tactile dome, and a self stick cover (tape, etc)with a label for the button.
 
Originally posted by Jonathan:
Another chip to consider: The AVR ATTINY15. Also available from Digikey, cheap, and has a built in high frequency PWM and pre-amp for the A/D converter. You could use this chip both for control (on, off, dim, etc.) and as the core of a switching regulator to run LEDs.

-Jon
<font size="2" face="Verdana, Arial">Haven't dealt with the ATTinys yet, although will be ordering some soon. (Stupid handling charge for orders below $25 from DK...)

I have dealt with the 8515s and Mega163s, AVRs are WONDERFUL to program with. Codevision AVR is an excellent C compiler. GCC can also compile to AVR targets, and as much of a fan of GCC as I am, once I get back to AVR programming I'm going to use CV.

http://instruct1.cit.cornell.edu/courses/ee476/ has LOTS of good links and cool AVR-based projects. (I took this class just before graduating from school, it was a blast.)
 
Lots of good input here even if it has trended in the direction of a "how many firmware engineers does it take to turn on a lightbulb" joke. Thanks guys, keep it coming.
 
Originally posted by Entropy:
</font><blockquote><font size="1" face="Verdana, Arial">quote:</font><hr /><font size="2" face="Verdana, Arial">Originally posted by Jonathan:
Another chip to consider: The AVR ATTINY15. Also available from Digikey, cheap, and has a built in high frequency PWM and pre-amp for the A/D converter. You could use this chip both for control (on, off, dim, etc.) and as the core of a switching regulator to run LEDs.

-Jon
<font size="2" face="Verdana, Arial">Haven't dealt with the ATTinys yet, although will be ordering some soon. (Stupid handling charge for orders below $25 from DK...)

I have dealt with the 8515s and Mega163s, AVRs are WONDERFUL to program with. Codevision AVR is an excellent C compiler. GCC can also compile to AVR targets, and as much of a fan of GCC as I am, once I get back to AVR programming I'm going to use CV.

http://instruct1.cit.cornell.edu/courses/ee476/ has LOTS of good links and cool AVR-based projects. (I took this class just before graduating from school, it was a blast.)
</font><hr /></blockquote><font size="2" face="Verdana, Arial">Note that the ATTiny15 (like most of the others in the Tiny line) doesn't have any RAM (just a bunch of registers that you can use for variables), so GCC can't handle it. So you're either going to use assembly language, or something like ICCTiny from Imagecraft
 

Latest posts

Back
Top