eeprom based program counter in case of power failure

Changster

New Member
Hi all,

I'm building a 'PLC' type controller based on a 20M2 for a small chemical industrial process which a batch will take about 6 hours. It will have 4-5 switches, temperature sensor, a colour sensor (with a 18M2) and 5-6 motorised valves.

There's going to be 12-14 separate steps in the operation with small delays of up to an hour between operations so a step could be stored in case of interruption, reset etc.

How easy is it to write a small program within the main program to increment a 'program counter' into eeprom (either internal or external) so if there's a power failure, reset or a need to pause the operation for maintenance etc, it can carry on from where it left off?

Regards
Mark
 

premelec

Senior Member
One of the first things to do is define the number of variables that need to be stored for resumption to happen correctly and how often these need to be stored - if not very often and not very many then probably not too hard - if lots of variables and very short times not so easy - also may need to compare "present" readings on restart with recorded last readings and note time interval - a lot depends on critical nature of processes! [sounds like fun] - second thought - could be much easier to add uninteruptible power source to keep stuff running... :)
 
Last edited:

srnet

Senior Member
And remember that the EEPROM is only rated for 100,000 writes.

Sounds a lot, but writing at once per second and you will exceed that count in around 28 hours.
 

Janne

Senior Member
It may be easier to add a battery backup power supply to retain the program state while the mains are off. That way you can also monitor the length of the power outage, and decide from there if the process can continue after the power returns, or if the batch is ruined.
 

Jeremy Harris

Senior Member
There's a relatively easy way to do this. You presumably have a mains-fed power supply and a voltage regulator that supplies the regulated supply for the Picaxe. With a modest reservoir capacitor in this power supply, you will find that the 5V Picaxe supply probably doesn't dip for maybe a few hundred mS after the power failing. You can sense this dip before the Picaxe supply drops and use it to trigger a save to EEPROM only when there is a power failure, which saves doing too many EEPROM writes over the lifetime of the unit.

The way I did this for an electric bike battery energy meter, where I wanted to store the battery state of charge remaining even over a power down, was to use a resistive potential divider to drop the raw supply from the reservoir capacitor down to a safe level that's within the Picaxe ADC range. Then just read the ADC and if it drops below a critical level initiate a save to EEPROM. I found this to work very reliably, and have used the technique on a few other projects.
 

geezer88

Senior Member
There's a relatively easy way to do this. You presumably have a mains-fed power supply and a voltage regulator that supplies the regulated supply for the Picaxe. With a modest reservoir capacitor in this power supply, you will find that the 5V Picaxe supply probably doesn't dip for maybe a few hundred mS after the power failing. You can sense this dip before the Picaxe supply drops and use it to trigger a save to EEPROM only when there is a power failure, which saves doing too many EEPROM writes over the lifetime of the unit.

The way I did this for an electric bike battery energy meter, where I wanted to store the battery state of charge remaining even over a power down, was to use a resistive potential divider to drop the raw supply from the reservoir capacitor down to a safe level that's within the Picaxe ADC range. Then just read the ADC and if it drops below a critical level initiate a save to EEPROM. I found this to work very reliably, and have used the technique on a few other projects.
I used this same technique on a fuel flow meter for an airplane. The eeprom held the calibration constants and the fuel remaining in the tanks. When power was turned off, it did the same thing that Jeremy does with his projects. This system was installed in an amateur build plane and worked like a charm for over 1000 hours.
tom
 
Top