Wednesday 23 September 2015

transistors - Momentary switch power: press to turn on, microcontroller can turn itself off


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?




Answer



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.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...