I have a simple appliance timer that powers on my Arduino for several hours each day, and then trips it off. I have a written program that uses the MsTimer2 to create a tick each second and use it to count up in minutes. When the minutes reach past a delay, the program performs for several minutes time, and then stops (or the timer turns off the power.) While in the delay the length of the performance can be changed from 1-10 hours and stored in EEPROM for use on next power up. I would like to be able to keep track of the total minutes that the program has performed for (not including the delay minutes) so that when it has reached 500 minutes it can switch the way it performs. My start delay can be anywhere from 0-1380 minutes, and the performance time from 60-600 minutes. My minutes reset at 1440 so that if the appliance timer fails on, the arduino will still perform once a day.
Here is the timer code
void increment_time() { //Second counting timer function
seconds++; // We're counting UP
if (seconds > 59) { // If seconds have rolled over
seconds = 0; // Reset seconds
minutes++; // and increment the minutes
if (minutes > 1439) { // Minutes in a Day have rolled over
minutes = 0; // Reset minutes
}
}
tick++; // indicate that the time has been updated
}
and here is the performance control code
//If minutes < delay, then check for button input to change run time
if (minutes < (StartDelay)) {
Mode = 0;
SetTime(); //Check to see if the performance time length (Rcount)is changed
}
if (minutes == (StartDelay)) {CycleTime = Rcount * 60;} // Start-up delay is over, Now use Input Count for Cycle Time
if (minutes > (StartDelay) && minutes < ((CycleTime) + (StartDelay))) {
if (Rcount != ctRead) //Was Count for Hours of Operation changed?
{EEPROM.write(0, int(Rcount)); // Then Write NEW count to the EEPROM
delay(20);}
ForwardPower();
} //Perform for Rcount hours
if (minutes > ((CycleTime) + (StartDelay))) {
Idle();
Mode = 3;
}
}
else {
Idle();
Any ideas on how to track the ON time with out too frequent writing to the EEPROM?
So, just to check I understand. You want to track how long the Arduino is on, and record it, without continuously writing to EEPROM (I assume because that would 'wear out' the EEPROM quite quickly)?
Have you got a spare input pin?
If you can detect power shutdown a few milliseconds before all power disappears, then you could write the value to EEPROM.
You could give yourself time to write to EEPROM with a large value capacitor across the power supply to the ATmega.
This would only write to EEPROM when power is disappearing.
Is that the sort of thinking you are looking for, or is that way off?
Thank You for the reply! I have already connected the Arduino to my project, and would prefer not to change the hardware, but that is a great idea that I will try to remember for future use!
I want to track how long the process has been turned ON by the Arduino. When the Arduino is powered ON it starts counting, and after the delay it starts the process. The process then runs. Writing to the EEPROM every 30-60 minutes would probably be close enough for tracking ON time, but I keep getting myself confused as to how to determine how to save "it", recall "it" and use "it", where "it" is a count of minutes. I mean I know how to save it and recall it, but I can't figure out how to manipulate the count to operate the process. I thought that using an "old count" from the EEPROM to set a "new count" for the process might work, but again I confuse myself.
In thinking about what I just wrote a little clarity crept in! I think that what I need to do is use the "old count" as a starting point and reference all of the other times to it, by setting minutes = old time in the void increment_time and using that as a start time, and then storing the minutes count every 30 minutes. I fear that it will look ugly, though!
Working will be nice! Thanks for the replies! I am going to call it a time stamp, look at it in the beginning and then reference everything off of it. I will probably go to doing it once an hour just to prolong memory life, and because if I set the timer periods right, it will finish the program before the power is removed, unless there is a utility outage.
I went in another direction. Instead of trying to keep track of a count, I decided that I really just wanted to cut down the number of reversals. I posted my complete revised code here - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1269366253/5 if any one is interested in what I am up to.
Cheers!