Maker Pro
Maker Pro

Microcontroller controlled by pushbutton for LED flashlight

Kris had already considered charging the cap with a P channel MOSFET instead of the diode, but the idea was abandoned (idea was suggested in post 60, abandoned in post 70).

Hi Jeff
The FET will work if we keep the diode. This is the best option I think. We can increase the capacitor size and run the circuit out of sleep and every so often (TBD) charge the capacitor. This then means no extra constant drain on the battery. Only short burst of energy to charge the capacitor.
Adam
 
Trying to follow this thread to see if I can help. Can someone post an up to date schematic? I really have no idea what we are talking about now.

Bob
 
This is the latest schematic we have. I have not installed the Zener on my proto board though. The LED driver presents a load when powered, but does not pass any considerable current when off. For design purposes, the LED driver can be omitted from the circuit. RC will be a load when the MOSFET is on and a supply when the MOSFET is off. Hope that sums it up OK.
272661-003-gif.18850
 
Thanks.

So I guess the capacitor provides power to the uC when the light is on, and it is (hopefully) in sleep mode during this time.

Bob

Yes, but the original plan was to pulse the MOSFET OFF for 1ms every 100ms, to keep the capacitor charged. We do not know yet if this will work. Here is a quote from Kris explaining the theory:

"So here's my suggestion. Use 1 µF for the reservoir capacitor on your switch board, and use 330Ω across the LED driver to provide the top-up current for that reservoir capacitor. Have the PIC switch the MOSFET OFF for 1 ms every 100 ms. I believe that should work safely. My calculations have all been conservative."
 
We have plenty of room to increase capacitor value. Very little wiggle room to decrease resistor value, as it cuts into the run time.
 
Last edited:
The capacitor value should be way above what is needed if the uController is sleeping during this time. The sleep current is < 1uA and 1 1uF capacitor will lose 1 volt per second at that rate.

Bob
 
The capacitor value should be way above what is needed if the uController is sleeping during this time. The sleep current is < 1uA and 1 1uF capacitor will lose 1 volt per second at that rate.

Bob

That sounds like good news. I'm not familiar with how the micro's operate, so here's a stupid question. Can the PIC sleep while it is cycling the MOSFET off every 100ms? That would appear to be running to me, not sleeping.
 
The micro has a watchdog timer that you can run while in sleep and it will wake the PIC up when it expires. You can set the time to expire over a fairly wide range. I assume that is what Adam is using.

Bob
 
The micro has a watchdog timer that you can run while in sleep and it will wake the PIC up when it expires. You can set the time to expire over a fairly wide range. I assume that is what Adam is using.

Bob
Yep thats my next job. When I have time.
Adam
 

hevans1944

Hop - AC8NS
I just now got caught up reading this thread. All my tools for working with PICs and SMT components have now arrived, including a populated board and syringe of flux that Jeff mailed earlier this week that came in the mail today.

Last week, I received the PICkit and four SMT PICs plus four 8-pin carriers for the PICs from Digi-Key. I realized when I saw how tiny the PICs were that I needed some small tweezers, 0.015" diameter eutectic lead solder, and the finest conical tip Weller sells for my ancient WTCPN soldering station, all of which I ordered from Amazon Prime and received via UPS today. Now I wish that I had a hot-air soldering pencil. The stuff that Zephyrtronics sells is ideal, but way beyond my budget for now. I do have a temperature-controlled, variable temperature, Sears Craftsman heat gun that I might be able to re-purpose from its original intent as a heat-shrink gun and paint remover.

For good measure (I plan to do some more SMT work after Jeff has his project up and running), I also purchased some liquid flux and 63%Sn-37%Pb solder paste in syringes from Amazon Prime.

In the next few days I will solder-up one PIC and one 8-pin SMT carrier and breadboard the circuit on a solderless breadboard. I'll also energize the board Jeff sent and see if I can read his PIC with the PICkit. I think my PICs are a later model than the PIC 10F200 so I need to figure out if my PIC 10F206 is compatible. I sure wouldn't want to try using a feature on my PIC that isn't present on the PIC soldered to Jeff's board!

Edit: corrected my PICF206 part number.
 
Last edited:
The PIC on the board I sent you contains the program that Adam wrote. I obviously screwed something up when I edited it to use to GPIO 2 instead of GPIO 0 as the output. You can just throw 4 volts on the board and monitor the output across the resistor. The switch has a pretty high activation force, so your fingertip may be too soft to get it to click. Something like a pencil eraser will work better.
 

hevans1944

Hop - AC8NS
Roger on the switch actuation force being largeish.

And I suppose that gigantic device near the top edge is the Schottky diode? And the little speck mounted next to the push button switch is the energy-storage capacitor? And the little part on the right side is a 220 resistor connected between the MOSFET drain and the black wire (WP1)? And the red wire, soldered next to the black wire on the right edge of the board, is the circuit common (WP2)? Any reason for that particular ordering of colors? The free end of the resistor is positive (usually colored red) with respect to circuit common (usually colored black).

Would you suggest that I apply +4 VDC to the black wire (WP1) with the red wire (WP2) as common to power this up for testing?

Will the PICkit 3 provide Vdd power for the PIC 10F200 from the USB computer connection, for purposes of examining the code present in the PIC? In other words, can I just connect the cable to the PIKkit 3 and not worry about applying any additional power to the PIC?

On connecting the multi-colored wires on the male header to the PICkit 3 6-pin female connector:

ORG (PP6) to Pin 1 (denoted by an arrow on the PICkit 3 case)
RED (PP5) to Pin 2
BLK (PP2) to Pin 3
WHT (PP1) to Pin 4
BLU (PP3) to Pin 5
no connection to Pin 6.

If all the above looks okay, I will power the board up tomorrow and look at the I/O pins with an oscilloscope.

If it isn't working when powered through the 200 Ω resistor, i.e., the PIC resets when it turns the MOSFET on, instead of holding up through the charge stored on CR, I will apply +4 VDC to PP5 with PP2 as common. This will allow the PIC to continue to operate normally while I examine the I/O pins with the oscilloscope. Measuring between WP1 and WP2 as common, I would expect to see a signal mostly at common potential (plus the Vds drop across the MOSFET) with narrow positive pulses between WP1 and WP2 whenever Adam's code turns the MOSFET off to re-charge CR through zener diode DC and the resistor RC. If the positive pulses are occurring, the next step is to figure out why the capacitor charge isn't holding up between re-charge pulses.

IIRC, Kris calculated a 1% duty cycle (one millisecond pulses every one hundred millisecond of MOSFET on time) would be sufficient to recharge the 1 μF energy storage capacitor, CR, if the PIC current load was on the order of one microampere. That load is a discharge rate of one volt per second, so the voltage on CR should only drop about a tenth of a volt between re-charge pulses. OTOH, with a one millisecond re-charge time interval through a 330 Ω resistor, the time constant for 1 μF and 330 Ω is 330 microseconds. So the re-charge interval is about three time constants. This should be more than enough time to replace the charge lost during 99 milliseconds of one microampere discharge.

If it isn't enough time, either the PIC is drawing way more average current than one microampere, or the capacitor is not really one microfarad. I will discover which of these two instances is the case, hopefully sometime tomorrow.

Much to my chagrin, I still haven't taken the time to review Adam's code yet. I am still on a learning curve for the PIC (my only excuse), which is wearing thin since Jeff sent me a board with a programmed PIC on it. I'll fire up the PICkit 3 tomorrow to see what I can discover.
 
Update: I am having a right nightmare trying to get this PIC to go to sleep and wake-up on the watch dog. With the watch dog enabled I am in a tight software loop trying to go to sleep but the watch dog keeps resetting the PIC instead of resuming the program from where it left off. I have spent far to long on this PIC so I have ordered the next version up of the PIC (P10F320) and a PICKIT 3 and I am going to install MPLABX tonight. @hevans1944 if you can get it to go to sleep I'll give you a big kiss from the UK :). Sorry it's taking me so long. I am a week behind due to work at home.
Adam
 
Roger on the switch actuation force being largish.
The high activation force is needed to give the operator feedback, even if they are wearing gloves.
And I suppose that gigantic device near the top edge is the Schottky diode?
Yes, it’s quite huge.
And the little speck mounted next to the push button switch is the energy-storage capacitor?
Yes. Tiny little sucker. I had fun soldering that one.
And the little part on the right side is a 220 resistor connected between the MOSFET drain and the black wire (WP1)? And the red wire, soldered next to the black wire on the right edge of the board, is the circuit common (WP2)? Any reason for that particular ordering of colors? The free end of the resistor is positive (usually colored red) with respect to circuit common (usually colored black).
I put the 220 ohm resistor there, as I didn’t have a 330 here. If you have a 330 there, please substitute. It sounds like I got those wires backwards. Right before I shipped it to you, I replaced the supply wires as the ones that I was using had a little plug connector on the end. The MOSFET source should be black, resistor tail red. Sorry about that. Good catch! No power was applied the board after the wires were replaced.
Would you suggest that I apply +4 VDC to the black wire (WP1) with the red wire (WP2) as common to power this up for testing?
Yes, but you can use anything from 2.8-5v for testing. I just said 4v, as that's what I was using. Again, sorry about the switched colors. You could also switch the wires. :)
Will the PICkit 3 provide Vdd power for the PIC 10F200 from the USB computer connection, for purposes of examining the code present in the PIC? In other words, can I just connect the cable to the PIKkit 3 and not worry about applying any additional power to the PIC?
Yes, but the option to have the PICKIT3 supply the power is somewhat hidden in the software. Let me know if you don’t find it and I'll locate it again.
On connecting the multi-colored wires on the male header to the PICkit 3 6-pin female connector:
ORG (PP6) to Pin 1 (denoted by an arrow on the PICkit 3 case)
RED (PP5) to Pin 2
BLK (PP2) to Pin 3
WHT (PP1) to Pin 4
BLU (PP3) to Pin 5
no connection to Pin 6.
Correct
If all the above looks okay, I will power the board up tomorrow and look at the I/O pins with an oscilloscope.
Thank you and take your time!
Update: I am having a right nightmare trying to get this PIC to go to sleep and wake-up on the watch dog. Sorry it's taking me so long. I am a week behind due to work at home. Adam
Do not apologize. There is no rush on this. All of your efforts are deeply appreciated!
 
Top