storing data in memory

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

storing data in memory

Post 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.
Attachments
neutral storage deeper memory.fcfx
(7.28 KiB) Downloaded 176 times

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: storing data in memory

Post 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.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: storing data in memory

Post 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!

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: storing data in memory

Post 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.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: storing data in memory

Post 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

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: storing data in memory

Post by kersing »

The eeprom will not handle power cuts while being written to. That is why I wouldn’t use it.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: storing data in memory

Post 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

Post Reply