So I have this circuit here. Ideally, it allows a momentary switch to connect the power circuit, and when released it would stay on.
Here's what I think this circuit does.
- The button is pressed
- Power flows and the micro controller begins running it program
- Software says to supply voltage on PB3
- Transistor turns on connects the circuit to ground
- The button is released, and the transistor stays connected.
Here's what it doesn't do yet:
- While power is on, hold the button for 1 second (how would I do this?)
- micro notices a long press on the button
- Software says to remove voltage from pin PB3
- 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?
Answer
Here is a possible solution for you:
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.
No comments:
Post a Comment