PDA

View Full Version : Simple way to determine how long PIC is off



rmteo
- 25th July 2009, 14:33
Looking for a simple way to determine how long a PIC has been off when it is turned on. The actual time is not critical - say about five seconds. Just need to know whether it has been off for MORE (or LESS) than 5 seconds when it is turned on.

Jumper
- 25th July 2009, 15:22
If you only want to figure out longer or shorter than 5 seconds maybe you can use 2 pins. One I/O pin and one AD pin.

Connect both the AD pin and the I/O pin to the + side of a capacitor and then parallell to this capacitor also connect a resistor, both the resistor and cap connect to ground.

When the pic starts up you read the AD value to see how much the capacitor has discharged. Then you turn on the I/O pin to charge the capacitor full and keep the capacitor charged until you power off the PIC. Then the resistor that is parallell to the cap will discharge it.

By choosing different values on the capacitor and resistor you can get different discharge times. This combined with the AD value will give you a quite good clue how long the PIC has been off.

If you dont have any AD avaliable then you might be able to just use a normal digital i/o. If the cap has a high voltage (it has been dischared a short time) the input would read as a "1", if it is discharged for a longer time till will read as a "0". This will be a much less accurate way. Read the input, guess the time, and turn on the pin as an output to re-charge the cap.

toneman
- 25th July 2009, 19:49
How bout using a I2C realtime clock/calandar like the PCA8565.
Keeps track of time ALL the time.
(that was the first item I came across after a simple google)
PIC just stores the real time in a register before shutdown;
Then, when woke up, reads RTC and compares to register.
Wham, Bam.... times up!
T