I'm trying to store the running time of an Arduino Mega 2560. I have in a loop a long var increasing every second. The idea was to write in the RTC memory (DS3232) and when I reboot the arduino the variable should be stored to continue this running time. The problem comes when the data is higher than 255 so it can't be stored and I should move to other memory position, but it does not seem the good way to store it.
Before you get too excited, check the number of write cycles supported by the memory.
Writing every second may toast the RAM sooner than you think.
There are solutions, but you. we'd to understand the problem if it affects your project.
I thought I should have some problems about lifetime if i store in the arduino eeprom, but in RTC RAM should be stored every second with no problems, nevertheless it continues failling when it's over 255...
ok, while i haven't looked at the library you're using, i suspect it's only ever writing single bytes (unless there's a function to write larger types), so you need to break the unsigned long apart before storing and retrieving the 4-bytes of the time stamp value.
riki_val:
I thought I should have some problems about lifetime if i store in the arduino eeprom, but in RTC RAM should be stored every second with no problems, nevertheless it continues failling when it's over 255...
See reply 2
you need the library I referenced there, or you have to split up your timestamp byte by byte and use your library.
Just to clarify terminology, up time usually refers to the time since the last boot. It has on any system I've ever seen that kept track of it. I think what we're talking about here is running time, or cumulative up time, or something like that.
in some case , if you want to store the time , the craziest way is to use a capacitor why?
Let say you want to save time , but if you write to EEPROM , it will kill the EEPROM, if you write it to RAM , it will be lost,
so the hardware way is to use a cap and a diode, vcc(to adc also)->diode->cap-> avr
use 1 analog pin to measure the voltge of vcc, the cap must be big enough to power the avr when the vcc goes off
crazy idea not tested and need more contribution comment.
curlyz:
in some case , if you want to store the time , the craziest way is to use a capacitor why?
Let say you want to save time , but if you write to EEPROM , it will kill the EEPROM, if you write it to RAM , it will be lost,
so the hardware way is to use a cap and a diode, vcc(to adc also)->diode->cap-> avr
use 1 analog pin to measure the voltge of vcc, the cap must be big enough to power the avr when the vcc goes off
crazy idea not tested and need more contribution comment.
No need to store the time every second - you can make a UPS with a diode running into a biggish cap. Take a digital input from in front of the diode to sense when the power goes off. The cap will power the board for a few millis after that - long enough to write out the up time.
PaulMurrayCbr:
No need to store the time every second - you can make a UPS with a diode running into a biggish cap. Take a digital input from in front of the diode to sense when the power goes off. The cap will power the board for a few millis after that - long enough to write out the up time.
But the OP said, "when I reboot". Hitting the reset button will bypass that. We need more information about shutdown conditions.
Also how it is powered. If it uses the onboard regulator, it might be easy to monitor the 9-12V that is powering it, and trigger if it falls below a threshold.
The OP has DS3232 battery backed RAM. What is difficult about just incrementing a counter in it while the system is running? This was in reply #2.
aarg:
Also how it is powered. If it uses the onboard regulator, it might be easy to monitor the 9-12V that is powering it, and trigger if it falls below a threshold.
The OP has DS3232 battery backed RAM. What is difficult about just incrementing a counter in it while the system is running? This was in reply #2.
Nothing really. EEPROM burns out if you write to it too frequently, but battery-backed RAM is a different thing. So realistically, it would be perfectly ok.