PDA

View Full Version : Saving variable(s) contents before power is removed



emavil
- 3rd February 2007, 00:37
Hi,

I have this notion of saving memory variable(s) before power is cut-off. Anybody who has an idea. I'm using PIC16F628A with internal RC osc enabled and PICBasic Pro.

BobK
- 3rd February 2007, 02:25
Hi Emavil,

You could monitor the PICs voltage supply for a loss and as soon as the PIC sees the voltage dropping write the variables to the EEPROM built-in to the PIC. As soon as the power up occurs you read back the vairables as part of your INIT routine.

As for monitoring the power, I would put a 100uF capacitor on the PICs Vdd to ground and monitor the power coming into the power supply using something like an opto-isolator that will signal the loos of power coming in.

HTH,

BobK

emavil
- 3rd February 2007, 02:49
Hi Emavil,

You could monitor the PICs voltage supply for a loss and as soon as the PIC sees the voltage dropping write the variables to the EEPROM built-in to the PIC. As soon as the power up occurs you read back the vairables as part of your INIT routine.

As for monitoring the power, I would put a 100uF capacitor on the PICs Vdd to ground and monitor the power coming into the power supply using something like an opto-isolator that will signal the loos of power coming in.

HTH,

BobK

thanks BobK,

yeah, an opto-isolator is a good option.

Do i need to waste one I/O just to monitor power loss. Is there a hardware built-in to 648A that automatically detects power loss so that i can power simple housekeeping. How long does it take to perform this simple housekeeping?

can u share to me a simple schematic for that opto-isolator solution?

ronsimpson
- 3rd February 2007, 03:08
The PIC16F628 has voltage comparators that can cause an interrupt. In the schematic the programmable reference is compared against a division of the input voltage. If input power falls dangerously low then an interrupt is generated.

I do not see a way of monitoring supply voltage with out using a pin.

Good luck!

peterdeco1
- 4th February 2007, 11:39
Hi Emavil. This is a snippet of code I use with a 16F872 with eeprom. In case of power interruption it will go back to the mode it was in. The line at the top "IF MODE > 2 Then LET MODE = 0" is only valid with a newly programmed PIC. Once a write is performed, it will read a 0 or 1 or 2. Hope this helps.



address VAR WORD 'address variable
TRISA = %00110000
TRISB = %11111101
TRISC = %00000000
Read 1,MODE
IF MODE > 2 Then LET MODE = 0

START:
MAIN PROGRAM HERE


CHANGEMODE:
LET MODE = (MODE + 1) 'ADVANCE MODE
IF MODE > 2 Then LET MODE = 0
Write 1,MODE
GoTo START

Acetronics2
- 4th February 2007, 13:04
The PIC16F628 has voltage comparators that can cause an interrupt. In the schematic the programmable reference is compared against a division of the input voltage. If input power falls dangerously low then an interrupt is generated.

I do not see a way of monitoring supply voltage with out using a pin.

Good luck!

Hi, Ron

Good analysis ...

you can even avoid using a comparator input, as the Schmitt trigger inputs High/Low thresolds of the pic are quite precise ( you can use pin polling instead of interrupts ).
If no comparator available, you also can use a To 92 case MC 33064 P5 or equivalent which will drive its output pin LOW for voltage < 4.65 v.

Alain

weirdjim
- 15th July 2007, 17:26
Drat. I hate doing this stuff without a blackboard.

Large (several dozen uf) capacitor directly from Vcc of the uP to ground. Schottky diode in series between power supply and Vcc of uP. 10k resistor from power supply to ground.

Bipolar PNP transistor emitter to Vcc, base to power supply through 10k resistor, collector to ground through 10k resistor. Collector will go to Vcc and slowly drop to zero when power is removed and capacitor slowly discharges. Use the Vcc pulse from the collector to an input port and check as many times as you like in your code as to whether or not this port has gone high.

And I freely admit (see elsewhere in this section) that I am an absolute newbie at microcontrollers but can generally hold my own in the analog world.

Jim