2
\$\begingroup\$

So I have this circuit here. Ideally, it allows a momentary switch to connect the power circuit, and when released it would stay on.

enter image description here

Here's what I think this circuit does.

  1. The button is pressed
  2. Power flows and the micro controller begins running it program
  3. Software says to supply voltage on PB3
  4. Transistor turns on connects the circuit to ground
  5. The button is released, and the transistor stays connected.

Here's what it doesn't do yet:

  1. While power is on, hold the button for 1 second (how would I do this?)
  2. micro notices a long press on the button
  3. Software says to remove voltage from pin PB3
  4. Transistor disconnects and the circuit is disconnected

The only part of that I'm not getting is how the chip can detect the button state if both sides are connected to ground.

So two related questions: Will this work to latch power on? And how can the chip know the same button state so it can turn itself off?

\$\endgroup\$
  • \$\begingroup\$ related: Microcontroller soft off circuit \$\endgroup\$ – Nick Alexeev Jan 4 '15 at 7:56
  • \$\begingroup\$ Do not switch the GND of the MCU. Instead switch the Vcc pin. The reason this is important is that there are things connected to your MCU that may very well be referenced to GND even including an earth GND connection. \$\endgroup\$ – Michael Karas Jan 4 '15 at 10:55
  • \$\begingroup\$ I made a simple timer with a ATTiny a while ago. Instead of powering it off, I put the controller in low power mode. The switch was hooked up to the reset input. That way, the switch would 'turn on' the micro, and it would turn itself 'off'. Even though it wasn't really off, it lasted years on two AA batteries. If I remember correctly, it draws a few micro-amps when 'off'. Some info that might help: jeelabs.org/tag/lowpower \$\endgroup\$ – RJR Jun 28 '18 at 8:12
1
\$\begingroup\$

Here is a possible solution for you:

schematic

simulate this circuit – Schematic created using CircuitLab

The pin A0 from the microcontroller is a pin capable of both digital output and analog input. This pin is configured as input during start.

This circuit is wired so that the gate voltage of M1 (aka analog input A0 of the microcontroller) maps to this:

  • \$0\mathrm{V}\$: circuit is turned off, or turning this entire circuit off.
  • \$\frac{1}{2}V_{cc}\$: circuit is running, button not pressed.
  • \$V_{cc}\$: Button is pressed.

Power on: The button SW1 is pressed down and +5V is present at the gate of M2, pushing M2 on and in turn push M1 on, turning this entire circuitry on. Microcontroller start and wait until the voltage of pin A0 drop to \$\frac{1}{2}V_{cc}\$ and start the program.

Power off: When pin A0 is pulled to +5V for several seconds and released, switch pin A0 into digital output and output a logic 0, turning M2 off and in turn cutting off M1, turning this circuit off.

\$\endgroup\$
  • \$\begingroup\$ You're in the ballpark (I've done something similar myself), but there are a few issues with that design. What if the supply voltage is not in the operating range of the MCU? \$\endgroup\$ – markt Jan 4 '15 at 7:39
  • \$\begingroup\$ Then the MCU wont be released out of reset by the brown-out circuit. \$\endgroup\$ – iggy Jan 4 '15 at 8:30
  • \$\begingroup\$ @iggy If the circuit is going to switch off completely - zero current - then any regulator or SMPS (to e.g. convert a battery up or down to 5V) must be after the PMOS (or replace the PMOS - /SHDN input on many regs/converters), which introduces a host of problems with that circuit. \$\endgroup\$ – markt Jan 4 '15 at 8:45
  • \$\begingroup\$ @markt An open-drain buffer can be used to shift the MCU level to whatever power level you have there. No worries. \$\endgroup\$ – Maxthon Chan Jan 4 '15 at 9:02
  • \$\begingroup\$ That's not what markt ment. \$\endgroup\$ – iggy Jan 4 '15 at 14:10
0
\$\begingroup\$

You can't do this with your circuit, you can not sense if the switch is presser or not.

But you could do it if you had a dual terminal switch. In this case you could sense the key press.

You can use a:

  • Single Pole Double Throw switch
  • Double Pole Switch

You always connect the normaly open part to supply the MCU, use the other terminal/pole to sense the key press and shutdown.

\$\endgroup\$
  • \$\begingroup\$ This costs serious $$$, especially in volume production. SPST tactile button costs less than US$0.01 each but SPDT or DPDT cost more than US$1 \$\endgroup\$ – Maxthon Chan Jan 4 '15 at 8:58
  • \$\begingroup\$ A double pole switch will certainly be less than a SPST + 2x MOSFET. Besides This is for hobby not production. Otherwise someone is going to pay me royalties. \$\endgroup\$ – iggy Jan 4 '15 at 13:46
  • \$\begingroup\$ 2x MOSFET actually cost less than DPDT. 2N7000 cost about US$0.01, BS250 cost about US$0.05 and power MOSFET IRF4905 cost about US$0.5. Either way the 1 tactile + 2 MOSFET is cheaper than any DPDT. For those who use SMT parts 2N7002 cost US$0.005 and PMV48XP cost US$0.1, even cheaper. \$\endgroup\$ – Maxthon Chan Jan 4 '15 at 13:53
  • \$\begingroup\$ Source of prices? \$\endgroup\$ – iggy Jan 4 '15 at 14:01
  • \$\begingroup\$ Taobao.com, Chinese equivalent of Ebay, parts from Shenzhen. \$\endgroup\$ – Maxthon Chan Jan 4 '15 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.