Page 1 of 1

storing data in memory

Posted: Sun Mar 01, 2020 9:45 pm
by Dutch
Hi all,
with the help of a great contributing member of this forum I made a display showing me some data from my motorcycle. just fun stuff! I don't want to bother him unnecessary with all my small questions.

I'm testing it now and besides other things it shows also the gearbox being in neutral. of coarse there is already a perfectly working neutral light but that is not the fun. A data signal when I switch on the ignition tells other components its in neutral.
Soo here is the challenge. now in colder weather when turn ignition on it shows nicely a neutral, but when I start the engine the voltage drops so far the unit restarts and misses the neutral signal (its only send ones). Is there a way to store a local variable somehow in a deeper memory so it would be there at startup.? I need to store other data too later but this is a good start.

I made a very simplistic fictive example.. if somebody could point me in the right direction I would be very grateful!

im using a Atmega328P

Thanks, Angelo.

Re: storing data in memory

Posted: Sun Mar 01, 2020 10:26 pm
by kersing
It would be better to find a way to keep the controller powered while starting. You could use a super cap to try and bridge the low power period.

The controller has no ‘deeper memory’ to store variables, external memory could be used but that would require battery backup or something like it and you would need to make sure there is never a power interruption while writing to it. That is why I would first try to keep the controller powered as that is a much more robust solution.

Re: storing data in memory

Posted: Sun Mar 01, 2020 10:41 pm
by Dutch
agreed, a goldcap from an old video recorder memory i must have somewhere could be an idea.
I feed a BCD display on it too so that draws a bit. I had a 2200uF 6,3v and that already dyed out pretty quick. also though about measuring voltage and shutting pwm to the bcd off below a threshold. hm.. back to the drawingboard.. Thanks!

Re: storing data in memory

Posted: Sun Mar 01, 2020 11:10 pm
by kersing
Use something like a diode in the power feed to the controller and add the capacitor between the diode and the controller. That way only the controller draws power from the capacitor.

Re: storing data in memory

Posted: Mon Mar 02, 2020 8:35 am
by mnf
Also take a look at using the eeprom in the mcu. You can store up to 1024 bytes on the atmega328 and these values survive power 'cuts '.
The memory has a limited number of write cycles (100000)- so don't write the value too often and always read the value and check if the new value is different before writing if necessary..

Martin

Re: storing data in memory

Posted: Mon Mar 02, 2020 9:00 am
by kersing
The eeprom will not handle power cuts while being written to. That is why I wouldn’t use it.

Re: storing data in memory

Posted: Mon Mar 02, 2020 10:09 am
by mnf
Writes are not 'atomic' (to use a database analogy) - however, if the data is only written occasionally the risk of corruption is be pretty small..

For example 'ignition turned off' (5s capacitor power available) - write data. Read on startup...

It depends how 'mission critical' the data is too?

Martin