Pages: [1]   Go Down
Author Topic: Reading hours meter from generator  (Read 1225 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm in the process of restoring an old Onan emergency generator to working order as well as adding an arduino (mega w/ etherent) to it to control remote start and stop operations as well as reporting oil pressure and water temperature of the engine.  The unit has an hours meter installed on the control panel that I would like to "mirror" on the arduino. 

When the generator is running one of the digital inputs goes HIGH.  I want the accrued hours to be stored in non volatile memory so it can survive a reboot and updated once the generator shuts down.  Any ideas?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46291
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
When the generator is running one of the digital inputs goes HIGH.
So, you simply want the Arduino to keep track of how long this pin is HIGH?

Quote
I want the accrued hours to be stored in non volatile memory so it can survive a reboot and updated once the generator shuts down.
How often? How is the Arduino powered? If you store the time in EEPROM (there's a library and functions to do this), you can read it again next time the Arduino starts up. You want to minimize how often you write to EEPROM, because it has a finite number of writes (100,000+ guaranteed; a lot more than that is quite likely). Writing on every pass through loop WILL wear it out in a hurry, though. Writing every time 5 additional minutes has accrued will take a long time to wear out the EEPROM (cell).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The arduino is powered by a DC-DC power supply that is tied into the generators starting batteries.  When the generator is not running a 120volt "battery minder" keeps the generator's batteries charged and the generator's alternator provides DC power when utility power has failed.

I am already reading the running time of the generator from the time the input goes HIGH till it goes LOW but this data is lost once the arduino resets.  The accrued running time is currently around 1100 hours and 50 minutes.  I would not worry about writing to the eprom too many times, the generator runs a self test once a month for 15 minutes then shuts down until the next test or a power outage. 

What I need to be able to do is store the current accrued hours into eprom then update those fields when the generator has shutdown with the new time.

Should I read and write back to the same memory location each time?  Since each location can only hold a number up to 255 should I break the accrued time up and use a different memory location for each character?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46291
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Should I read and write back to the same memory location each time?
Yes.

Quote
Since each location can only hold a number up to 255 should I break the accrued time up and use a different memory location for each character?
No. You should look at the EEPROM_readAnything and EEPROM_writeAnything functions (google if you need to) to see how to read and write ints, floats, structs, etc. There is no reason to convert the number to and from a string.

Writing additional accrued time appropriately (once a minute, every 30 seconds, etc.) will allow you to achieve a balance between wear and loss of data.

If the power supply to the Arduino is stable enough, you could write only when the pin went LOW again, but I don't recommend that. Any accrued time since the last save would be lost if the Arduino lost power.

Writing every 5 minutes while the pin is high and again when it goes LOW should be a reasonable compromise.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, I'll dig into that today and after the 4th holiday.
Logged

Pages: [1]   Go Up
Jump to: