Changing eeprom by on-off-on power

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I need some ideas how to change some settings on a device by on-off-on power dance; e.g. by turning power on-off-on-off-on in a specific time-frame makes the device enter a "setting mode" and somehow turning it off and on again retains a specific setting that is written into eeprom. If the device enters the setting mode accidentally, it exit without modifying the setting after a certain amount of time and enters normal operation

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which AVR? It does matter.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Attiny44

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your REAL problem is that the MCU cannot determine anything while it has no power. You could turn it on for 2 seconds, turn it off for 2 seconds, then turn it back on. The MCU cannot tell if it was off for 2 seconds or 2 days.

It is also very difficult to store the on-off pattern so that it knows how many times it has turned on recently. One could do something in the EEPROM, but that is the ONLY thing that will retain any history.

The rest is up to your imagination plus you ought to know about the MCUSR.

Jim

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you had an battery backed RTC, you could save the "turn on" time in EEPROM.
Every time it is turned on, it checks to see when it was turned on last and if it was turned on less then 3 seconds ago, it increments a counter in EEPROM else it clears that counter.
When the counter reaches say 3, you enter setting mode and do whatever you want.
Remember though, that the EEPROM has a limited number of erase/writes. This will not be a problem if the equipment is rarely turned off Ie, say a refrigerator.
If it is frequently turned on & off you could add some wear leveling to the boot-up process.

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Agree on the battery-backed RTC. Often, external RTCs even have battery backed memory so that you would have to mess with EEPROM.

It would still be necessary, however, to determine

(1) How do you know when the power is turned off early enough to do anything? If you rely on the BOD, its too late.

(2) You have to allow for the time to write to what ever memory you are using. If its external RTC, then you have to have time for the serial data message to that chip. If its internal EEPROM, you have to allow for the milliseconds of write time.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm a newbie with electronics so this is probably a silly idea, but anyway - what if you put a cleverly calculated cap on VCC ? That way you could perhaps detect a voltage drop and if the power is turned back on quickly enough the chip won't turn off.

Or would the detectable part of the discharge cycle be too short for this to be useful ?

Sid

Life... is a state of mind

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can, pretty easily detect the 2 short on's.

Store a byte in EProm.
At reset, look to see if the byte contains a 2. If so, it's been turned on - off - on - off - on. If not, increment the byte.

Then, on a timer interrupt or something a few seconds after reset, set the byte back to 0. You're actually counting "short on's."

The largest known prime number: 282589933-1

It's easy to stop breaking the 10th commandment! Break the 8th instead. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Along with the Capacitor idea:

In the attached schematic I have a voltage source (V) connected through a diode(D1) to a supercap(C1) then to the AVR Vcc pins.

In the schematic I have one of the comparators inputs connected to the anode side of the diode to sense power being removed from the circuit.

The supercap keeps the AVR running while you do your morse code sequence on 'V'. In this case by using the analog comparator input you could create an interrupt routine to count the number of on-off's.
I did not do a complete comparator circuit, but you could just as easily use the PCINT as well. This is just an example.

R1, makes sure the pin does not float giving false triggers. Diode D1 prevents the rest of your circuit from feeding off the cap C1

You will have to design anything attached to the AVR that will get power from the switched side to handle the loss of power unless the current consumption is low enough not to drain the cap to quickly.

Attachment(s): 

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How about reading, increasing and writing EEPROM location as the almost first thing at boot? And if software has been running for long enough, like 1 second, then write EEPROM location to 0.

If you reboot many times without waiting long enough, the EEPROM count will increase, and if there is long enough time from last reboot, it is zero. Perhaps that tells something?

Then wait for the EEPROM to die, unless you figure out some clever wear leveling algorithm to this.

Edit: oh this was already said. Sorry.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Believe it or not almost everything has already been discussed here at Freaks already. I clearly remember a thread discussing the options for implementing an almost identical idea within maybe the last couple of years. I guess the trick is going to be guessing what keywords will find it in a search but it's probably worth looking for.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I do this on a Tiny 25 design.
On power up,I check an eeprom'flag'. If it is 'set' I go into a setup routine.When all is done, I clear the 'flag'and do a restart.If the eeprom'flag' is NOT set I go into a 2 second delay loop.
On entry to the loop, I set the eeprom 'flag'.
After two seconds, I clear the 'flag' and continue with the program.
Simple....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks guys, very helpful ideas.
Although the capacitor and RTC sounds good, in my particular case I do not have them on board and if I could modify the hardware the most easiest would be to add a button to change the settings.
A good option I thing is what chartman is suggesting:

Quote:

I do this on a Tiny 25 design.
On power up,I check an eeprom'flag'. If it is 'set' I go into a setup routine.When all is done, I clear the 'flag'and do a restart.If the eeprom'flag' is NOT set I go into a 2 second delay loop.
On entry to the loop, I set the eeprom 'flag'.
After two seconds, I clear the 'flag' and continue with the program.

How do you prevent accidentally entering and modifying the settings? E.g. by a bad battery connection. Also what would happen if the power is turned off in the middle of eeprom writing? It could end with random data in there right?.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, so I modified the thing a bit:
On power up check an eeprom variable, let's call it E
1. If E==3 then enter setting. If setting is not changed in 10 seconds exit setting.
2. If E<3 wait one second E++; wait another second;
3. make E=0 and normal operation
This will assure a low probability to enter settings accidentally and deal with random data in eeprom. It does not deal with eeprom leveling, but in my case I think it's acceptable, I foresee the setting to be changed maybe 10 times on the life of the product, so about 40 eeprom writes. Every power up would make 2 writes, batteries should last 1 year. Taking into account accidental resets I think it should be good. Opinions?

Last Edited: Thu. Jan 10, 2013 - 04:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, theoretically, one could switch off right at the 2 second point and corrupt the EEPROM data being written. All this would do is force an entry into setup at next power on, at which point the user can just exit...