eblc1388
Active Member
I have designed the following circuit to let me control the power supply to a PIC using a single push button.
Most circuits I have seen requires two PIC pins but mine needs one only. I have built and tested the scheme and it works everytime.
If you would like to try the design, please report back to the forum whether it works or you are experiencing any problem.
The key point to its requirement is the "Brown Out Reset" protection of the PIC, which must be enabled.
Enjoy.
Most circuits I have seen requires two PIC pins but mine needs one only. I have built and tested the scheme and it works everytime.
If you would like to try the design, please report back to the forum whether it works or you are experiencing any problem.
The key point to its requirement is the "Brown Out Reset" protection of the PIC, which must be enabled.
Enjoy.
Code:
;**********************************************************************
; *
; Filename: lf876_OnOff.asm *
; Date: 17-FEB-2006 *
; *
; File Version: 0.0 - Single button PIC Power On/Off *
; *
; Author: L.Chung *
; *
; When a PB is pressed, power is provided to the PIC and LEDs *
; and the PIC works normally. When the PB is pressed again and *
; released, power is turned off waiting for next PB activation. *
; *
; Special point: Only one PIC port pin is needed for this setup *
; Zero current drain in OFF mode *
; *
;**********************************************************************
; *
; Ext Files required: None *
; *
;**********************************************************************
; *
; Notes: Crystal freq: 11.0592MHz *
; instruction cycle timing: 361.69ns per cycle *
; *
; Power_sense pin: RB1 ; any Pic I/O pin (except open drain)*
; *
; *
;**********************************************************************
;
; Push Button Push Button
; _/ PIC Power On/Off
; +-------------o/ o--+ Using one pin only
; | |
; +5V | |
; ---o----+^+--------------)-------------------+
; | ||| | |
; .-. === | | Vdd
; | | | P-CH | .----------o---------.
; | | | MOSFET | | |
; '-' | | | |
; | | | | |
; +----o | | |
; 100K | | | P I C |
; | | | |
; | | | |
; +-|| 4M7 | 100R | |
; N-CH ->|| ___ |A ___ | |
; MOSFET +-||---o--|___|-o--|___|--o P |
; | | | | |
; | --- .-. | |
; | --- | | | .-----------------.|
; | | 30PF | |1K8 | | Designed by: ||
; | | '-' | | ||
; | | | | | L.Chung Feb/06 ||
; | | .-----o | '-----------------'|
; | | | | '---------o----------'
; | | .-. V -> | Vss
; | | | | - |
; | | | |10K | LED |
; | | '-' | Power |
; 0V | | | | |
; -------o------o--o-----o-------------------o------------
; -(created by AACircuit v1.28.6 beta 04/19/05 [url]www.tech-chat.de)[/url]
;
; Design logic:
;
; A P-channel MOSFET is used as the main power switch and another N-Channel
; MOSFET pulling gate of P-Ch MOSFET down to GND to hold it on. The Gate of the
; N-Ch MOSFET is controlled by the PIC via 4M7+100R resistors. When all is off,
; there is zero battery current drain.
;
; When the PB is pressed, power is fed to A and the gate of the N-Ch MOSFET
; via the 4M7 resistor. Because of the internal protection diode of the PIC,
; a 100R resistor is needed. N-Ch MOSFET conducts and pulldown gate of
; P-Ch MOSFET. It too conducts and powering up the PIC.
;
; All this take little time and after the PIC is started up, PIC sets pin P as
; input pin and goes into an infinite loop checking for the pin P level to
; go LOW, which happens when user released the push button. As long as user
; keep pressing the button, a logic HIGH will be read by the PIC.
;
; When user released the button, the N-Ch MOSFET does not immediately shutoff
; because of the charge retained on gate capacitance and the added 30pF capacitor.
; However, the charges will discharge via 4M7 resistor and the 1K8+10K resistors
; eventually to 0V. Because of the large divider ratio between these resistors,
; PIC will read back a logic LOW and detected that user has released the button.
; Once a LOW is detected, PIC would reconfigure the Pin P into an output pin
; and outputs a HIGH to keep the N-Ch MOSFET in conduction. All these happens in
; the time span of a few PIC instructions, which is far far less than the RC time
; constant of the gate RC circuit.
;
; After an additional wait of 200mS in software to let the switch contact
; bounce to die down, the main user program is executed.
;
; PIC then starts periodic checking pin P, either in routines or during
; Interrupt. First it changes pin P into an input pin and read the logic level
; on it. If a LOW is read, the pin is set back to output with a HIGH.
; All this happens in a few instructions and the existing RC combination will keep
; the N-Ch MOSFET in conduction regardless. This indicates that user has
; not pressed the push button yet.
;
; However, if a HIGH is read, it means user is now pressing the button. Once this
; is detected, PIC executes shutdown sequence, and when it is ready to shutdown
; the PIC, it sets Pin P as input and then outputs a LOW to the PORT register,
; just in case. It doesn't matter whether user has released the push button.
; Shutdown is going to happen anyway. It then goes and executes an infinite loop.
;
; After the user released the push button or when the PIC changed the pin P into
; an input pin, N-Ch MOSFET gate capacitance and 30PF start discharging
; via the 4M7 & 1K8+10K resistor. N-Ch MOSFET starts turning OFF.
; P-Ch MOSFET starts turning OFF and supply voltage to PIC gradually reduced.
; This is where PIC Brown Out protection comes into effect. The PIC is held
; in reset state as voltage decreases to zero.
;
; Actual tests on a PIC showed that the scheme works perfectly.