Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keeping program STATUS in PIC

Status
Not open for further replies.

dieselvette

Electrical
Oct 6, 2006
26
Does anyone know of a way I can keep the status of my PIC in memory indefinitely in the event of a power loss?

For example, as the program is running power is lost for a month. When the system is powered up again, I want the program to pick up right where it was when it lost power.

Nic Van Engen
Electrical Technician
 
Replies continue below

Recommended for you

Frankly, given that you've given no information, such a concept is a BAD idea.

If the PIC were controlling machinery, it would immediately resume an operation that was terminated a month prior? Without knowing whether the workpiece was even still there, Or if there's someone's hand in the way?

TTFN



 
The PIC will not be controlling machinery, just heaters and a few other non-moving parts.

However, if it was controlling machinery, one would certainly incorporate a START button of some sort which would resume the system where it left off, rather than just starting it upon power-up, in order to prevent a dangerous situation.

The important thing is that all timers/counters/bits/whatever keep their values indefinitely without power, like a mechanical timer/counter would.


Nic Van Engen
Electrical Technician
 
Can you write the important stuff to eeprom? Use a voltage sensing circuit that will sense the impending low volts (while you still have some volts left) to interrupt your program and write the important stuff. Then on power up and reset the first thing it does is grab the stuff from eeprom and go to the appropriate code.
 
eeprom - would work in this scenario, although I wouldn't know how to set it up (writing to the eeprom that is). Has anyone ever tried that?

Nic Van Engen
Electrical Technician
 
You need to talk to whoever designed or procured the PIC to find out what it's capable of and what hardware it has.

TTFN



 
Let me rephrase: Are there PIC's available with those capabilities?

Nic Van Engen
Electrical Technician
 
No there is no PIC with that capability.

All EEPROM is endurance limited. This means you cannot continuously update it or it will rapidly fail. Furthermore its update rate is only a tiny fraction of the memory's functional speed so constant "backup" is impossible.

There are ways that you can do essentially what you want but they would not be "termed" the way you are stating it.

It is a relatively easy task to save "entered" values and for the controller to then "control to them". Then if power is lost and returns the system can go back to controlling to these previously saved settings.

As IRstuff said the continuation of a program from where the power failed would be a BAD idea.

Keith Cress
Flamin Systems, Inc.-
 
Write to an external battery backed ram. There's no limit to the write cycles with that. I used the ram in an IIC clock chip (DS1307) to hold non time related data in one project.

There are PICs with internal eeprom, such as the 16f84a etc.
 
This machine doesn't have any moving parts, and no matter what it does on power-up would not create a dangerous situation. Not to mention, our systems runs unattended - no one even on the site - for weeks at a time.

Once again, if it DID have moving parts, one would use a start button and some sort of warning/delay or whatever it takes to make it safe upon power-up. I can't beleive there aren't systems out there with this kind of requirement.

Our system NEEDS to restart automatically, where it stopped, if power is lost for any length of time (and it needs to start where it left off), and it needs to do this automatically WITHOUT human interaction. Having to restart it manually would be a major inconvenience.

Don't most eeproms have a rating of like 1,000,000 writes? If you were to write the timer values to it every 1/2 hour, the eeprom would last for almost 60 years before it is "worn out".

zeitghost - you said you use battery-backed ram - what is the life span of the battery (do you need to replace it every year?), and how long does it hold the memory in the event of extended power loss? I need 100% maintenance free, and I need it to hold the info indefinitely. Would your idea be able to do this?



Nic Van Engen
Electrical Technician
 
In following this post I think an important point has been missed: a program can't just restart from memory from where it left off unless its processor internal status is also saved. This is because most processors are of dynamic internal construction, requiring everything to be refreshed with a clock (apart from a few types whose clock can go down to zero Hz, where provided it has a battery backup power to maintain the internal register states, it can resume from exactly where it left off).

For "ordinary" processors the way to do this continuation / restart action (often known as "warm start") requires specific code to be written into the program to save important data when the power fails, and also to reload this data when the power comes back.
This requires interrupt action when a power fail situation is detected to save the important data. As suggested by other posts, this can be non-volatile (NVRAM) or EEPROM to save these without power, or battery backed RAM. You also need to save a warm start flag status so you know the power has been interrupted at some point.

When power returns the processor will start the program, but as part of this sequence it first checks the warm start flag status: if it's not been set then it continues startup as normal, if the flag is set then the program recovers the stored variables and execution resumes from a known programmed recovery point - but this is NOT "where it left off".
 
Battery life is down to how often it gets used.

i.e. how often it's running with no 5V rail.

Since the clock chip uses uA, a couple of AAs will last a long time.

Alternatively, a single Lithium cell will last a long time too.

As mentioned above, just saving variables doesn't save the state of the machine.

The PIC is capable of detecting the cause of a reset, whether it be a brown out, cold start or watchdog.
 
you could write the variables to the ROM on the PIC in every step of the program...ie: after any change jump to a function which write ass the variables to rom and have the pic read them from the rom when it starts up (initialization)...well that is if you pic has rom. this will be labor intensive...but if you just controling heaters time should not be an issue...it's not like you're implementing a controller for a fighter jet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor