Maker Pro
Maker Pro

Microcontroller controlled by pushbutton for LED flashlight

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Damn that week went fast!

Here is the circuit I promised:

schematic.png
The only parts not in the current design are U1 and R1

U1 is a voltage detector. I used one I had on hand which has a trigger voltage of around 4V and a hysteresis of about 200mV. It also has no inbuilt delay.

R1 here simply turns on the mosfet. In real life, it would be connected to the microcontroller's output. I used a 680 ohm resistor.

Also note that during testing, a resistor was placed across C1 to give a current draw of approximately 500uA. The voltage detector draws 1 to 2 uA.

My power supply was set for 5.65V (for no really good reason) and current limited to 50mA. The load was a 100 ohm resistor.

IMG_6651 (Small).JPG
This is the scope with the input shorted. I have photographed the display so you can calculate voltages and times as well. This is the reference unless otherwise noted. (Oh, and I'm using a 10x probe)

IMG_6652 (Small).JPG
This is the voltage across the device. Note that it has a minimum of about 0.3V because I wasn't using a very fancy mosfet :) The short pulses are the mosfet being turned off to charge the cap.

IMG_6653 (Small).JPG
If we change the horizontal timebase we can see that it takes a little over 0.1ms to charge the capacitor, and with this load, 1.4ms to discharge the capacitor.

IMG_6654 (Small).JPG
Looking at the voltage across the capacitor, it falls to a little under 4V (the trigger voltage of my voltage detector) before rising to a little above 4.5V.

IMG_6655 (Small).JPG
Looking at that in more detail (note that this is AC coupled), you can see a small dip as the voltage detector triggers, drawing current before the mosfet switches off, then another dip just after the voltage reaches a peak as the mosfet's gate is charged (the time it takes for the voltage detector to fully turn off may be a factor here as well).

IMG_6656 (Small).JPG
Vgs of the mosfet shows the capacitor slowly discharging followed by the mosfet being turned off and then on.

IMG_6657 (Small).JPG
The stunningly well placed cable hides the fact that the vertical amplifier is set to 0.2V/div for both traces, and the horizontal timebase is 0.5ms/div. The ground reference for these traces is the bottom and middle graticule. This is with the same 10k (500uA) load.

IMG_6658 (Small).JPG
Changing to a 220k load (about 22uA) and the delay between charging cycles extends to a little over 15ms. This is a little less than you might expect, but acceptable. The charging period should remain the same at around 0.1ms, so less than 1% of the time is taken charging the capacitor. (You might say it looks more like 0.25ms -- and indeed it does)

If there are any problems in getting the microcontroler to regulate the capacitor voltage, then this circuit (the addition of 2 components) should get the job done.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Here's a trick to reducing the current required to detect a switch press.

Connect a small (a few nF is plenty) capacitor between the input and ground. Connect a moderate value resistor in series with your switch and connect them between the cap and V+.

Read the value on the input. If it is 1, assume the switch is pressed. Now set the pin to an output and write a 0 briefly before setting the pin to an input again. The idea is that if the button is pressed, you give plenty of time to recharge the cap, and by reading it fairly infrequently you limit the average current.
 
I just wanted to jump in and say thank you for everyone's continued hard work. At this point, it is difficult for me absorb everything that is going on, though I will continue trying. I won't even attempt to contribute anything right now, as it would just make me look like a babbling idiot. :confused:
 
No, haven't seen this issue when working with Diptrace. But on a some what related note: I have noticed that if you route a trace and then delete the trace the rat nest won't come back. But as a work around you can just go under File->Renew Design From Schematic->By Components Then in the pop up window select the schematic and click open, and the rats nest should reappear.

Just so you know, if @TenderTendon is going to be selling these you can't use the free version of Diptrace to design the schematics, because in their license it says you can only use it for non-profit designs. :mad: That's the only bad thing about Diptrace free!
Dan
Thats it Dan, yes it must have been when I deleted the trace to re-route it. I had refreshed many times but must have missed this one.
Thanks
Adam
 
Here's a trick to reducing the current required to detect a switch press.

Connect a small (a few nF is plenty) capacitor between the input and ground. Connect a moderate value resistor in series with your switch and connect them between the cap and V+.

Read the value on the input. If it is 1, assume the switch is pressed. Now set the pin to an output and write a 0 briefly before setting the pin to an input again. The idea is that if the button is pressed, you give plenty of time to recharge the cap, and by reading it fairly infrequently you limit the average current.

Good idea Steve. But the button is on one of the programming lines, this can cause the programmer to do into current limit mode and fail to program. Not sure what the max capacitance is, but I have tried 0.22uF earlier for debounce and it failed.
Thanks
Adam
 
I just wanted to jump in and say thank you for everyone's continued hard work. At this point, it is difficult for me absorb everything that is going on, though I will continue trying. I won't even attempt to contribute anything right now, as it would just make me look like a babbling idiot. :confused:

Hi Jeff
Do you have a PCB size in mind for the final design, Hop mentioned it being circular.
Thanks
Adam
 
Damn that week went fast!

Here is the circuit I promised:

View attachment 19736
The only parts not in the current design are U1 and R1

U1 is a voltage detector. I used one I had on hand which has a trigger voltage of around 4V and a hysteresis of about 200mV. It also has no inbuilt delay.

R1 here simply turns on the mosfet. In real life, it would be connected to the microcontroller's output. I used a 680 ohm resistor.

Also note that during testing, a resistor was placed across C1 to give a current draw of approximately 500uA. The voltage detector draws 1 to 2 uA.

My power supply was set for 5.65V (for no really good reason) and current limited to 50mA. The load was a 100 ohm resistor.

View attachment 19737
This is the scope with the input shorted. I have photographed the display so you can calculate voltages and times as well. This is the reference unless otherwise noted. (Oh, and I'm using a 10x probe)

View attachment 19738
This is the voltage across the device. Note that it has a minimum of about 0.3V because I wasn't using a very fancy mosfet :) The short pulses are the mosfet being turned off to charge the cap.

View attachment 19739
If we change the horizontal timebase we can see that it takes a little over 0.1ms to charge the capacitor, and with this load, 1.4ms to discharge the capacitor.

View attachment 19740
Looking at the voltage across the capacitor, it falls to a little under 4V (the trigger voltage of my voltage detector) before rising to a little above 4.5V.

View attachment 19741
Looking at that in more detail (note that this is AC coupled), you can see a small dip as the voltage detector triggers, drawing current before the mosfet switches off, then another dip just after the voltage reaches a peak as the mosfet's gate is charged (the time it takes for the voltage detector to fully turn off may be a factor here as well).

View attachment 19742
Vgs of the mosfet shows the capacitor slowly discharging followed by the mosfet being turned off and then on.

View attachment 19743
The stunningly well placed cable hides the fact that the vertical amplifier is set to 0.2V/div for both traces, and the horizontal timebase is 0.5ms/div. The ground reference for these traces is the bottom and middle graticule. This is with the same 10k (500uA) load.

View attachment 19744
Changing to a 220k load (about 22uA) and the delay between charging cycles extends to a little over 15ms. This is a little less than you might expect, but acceptable. The charging period should remain the same at around 0.1ms, so less than 1% of the time is taken charging the capacitor. (You might say it looks more like 0.25ms -- and indeed it does)

If there are any problems in getting the microcontroler to regulate the capacitor voltage, then this circuit (the addition of 2 components) should get the job done.

Hi Steve
What's the part number for the device (U1) you used?
Thanks
Adam
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Good idea Steve. But the button is on one of the programming lines, this can cause the programmer to do into current limit mode and fail to program. Not sure what the max capacitance is, but I have tried 0.22uF earlier for debounce and it failed.
Thanks
Adam

I have seen it work using only the junction capacitance of the input circuit. This is a special case of leaving a CMOS input unterminated. You can also look at how high an input pull up or pull down you can get away with. You may be able to get away with something larger than you expect.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
[QUOTE="Arouse1973, post: 1648904, member: 33717"What's the part number for the device (U1) you used?[/QUOTE]

Sorry about that. It was a S8054HN-T.
 
Due to the design of the switch housing and actuating button, the switch must be in the center. Also, the switch must have an actuation force of at least 400 grams. I purchased the smallest switch I could find meeting this requirement. It's dimensions are below. Also, all components must be on one side of the board.

Switch dimensions:
switch-jpg.19302
 
Ok so we are going to have to go small which makes the choice of capacitor critical. This is doing to be a challenge if hand soldering
Adam
 

hevans1944

Hop - AC8NS
We need to find a smaller SMD Schottly diode of modest forward current and reverse voltage rating... surely Digi-Key has something that will fit... perhaps the attached datasheet describes what we need.
 

Attachments

  • ZLLS410.pdf
    559.2 KB · Views: 85
Last edited:

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
This is doing to be a challenge if hand soldering

If you're hand soldering that microcontroller then 0603 components won't be a problem :)

If you can fit the SOT-23 voltage detector on the board then you can probably go for a 1uF 16V cap. Note that you can get a 1uF ceramic rated at 6.3V in 0402. I would personally go for a higher voltage rating.

The issue with ceramics is that they can very easily fracture if the board flexes. This would be compounded by the high actuation force for the switch. There are components designed with this in mind, and careful placement can also minimize the risk (as can adding slot in the board).

If you go the automotive "boardflex sensitive" components, you can get a 1uF 100V cap in 0805.

This may be a reasonable choice of voltage detector. I'd prefer something with more hysteresis, and you would have to evaluate it to make sure it behaves well.

I also agree on the choice of diode. It has to be smaller. Be careful of the peak currents while charging the capacitor though.

A question for @TenderTendon, The components need to be on one side, but can the other side have tracks on it or does it double as the battery connector? Also, how will your design support the board to minimise flexing (possibly important for the capacitor)?
 
If you're hand soldering that microcontroller then 0603 components won't be a problem :)

If you can fit the SOT-23 voltage detector on the board then you can probably go for a 1uF 16V cap. Note that you can get a 1uF ceramic rated at 6.3V in 0402. I would personally go for a higher voltage rating.

The issue with ceramics is that they can very easily fracture if the board flexes. This would be compounded by the high actuation force for the switch. There are components designed with this in mind, and careful placement can also minimize the risk (as can adding slot in the board).

If you go the automotive "boardflex sensitive" components, you can get a 1uF 100V cap in 0805.

This may be a reasonable choice of voltage detector. I'd prefer something with more hysteresis, and you would have to evaluate it to make sure it behaves well.

I also agree on the choice of diode. It has to be smaller. Be careful of the peak currents while charging the capacitor though.

A question for @TenderTendon, The components need to be on one side, but can the other side have tracks on it or does it double as the battery connector? Also, how will your design support the board to minimise flexing (possibly important for the capacitor)?

Yep some good points Steve. The diode could be a Bat54A in sot23. The max current will be limitted by the 330R so its quit low.
Adam
 
Top