• AVR Freaks

Helpful ReplyHot!Use register to perform as EEPROM

Page: < 12 Showing page 2 of 2
Author
pcbbc
Super Member
  • Total Posts : 1703
  • Reward points : 0
  • Joined: 2014/03/27 07:04:41
  • Location: 0
  • Status: offline
Re: Use register to perform as EEPROM 2020/05/29 06:02:50 (permalink)
+3 (3)
NKurzman
Just a note.
Check the life on the HEF. Make sure you’re not going to burn it out in your design.

As a suggestion for that, and if you only need to store ON and OFF states, a simplistic but very effective form of wear leaving would be...
 
If you're not using it for anything else, start with it erased to all 1's.
 
When the light is supposed to be ON, write the first bit to a zero.
When the light is supposed to be OFF, write the second bit to a zero.
etc for third, fourth bits.
 
When the device gets a POR or BOR, read the number of consecutive zero bits.
ODD = Light state was ON
EVEN = Light state was OFF
 
When you reach the end of the HEF (all bits programmed 0's), erase it and start over.
 
However I expect if you are only writing when the user changes state, 100,000 erase/write cycles is probably enough.  Roughly 30 years at 10 power cycles a day.
#21
Jordiw
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2020/05/21 02:58:55
  • Location: 0
  • Status: offline
Re: Use register to perform as EEPROM 2020/05/29 06:22:59 (permalink)
+1 (1)
Zenforker, I didn't know the chip has writeable flash during run time. Since it has, you can follow the other suggestions using HEF.
Just make sure you set write protection on your program memory.
Also you might need to consider what if the unit loses power while writing to HEF, so you need to verify if the data is written successfully.
#22
ric
Super Member
  • Total Posts : 27951
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Use register to perform as EEPROM 2020/05/29 14:50:05 (permalink)
+2 (2)
pcbbc
When the light is supposed to be ON, write the first bit to a zero.
When the light is supposed to be OFF, write the second bit to a zero.
etc for third, fourth bits.

The OP has three states to encode.
OFF, ON, FLASHING.
I was going to suggest a scheme using 2 bits.
i.e.
00 ignore
01 on
10 flash
11 off
 
So, scan the memory until you find a pair that are not both zero, and use that.
When the state changes, if it was OFF, just program the new bits, otherwize zero both bits and move on to the next pair.
When you get to the end of HEF, erase the lot and go back to the start.
 
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#23
zenforker
Starting Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2020/05/24 17:08:09
  • Location: Australia
  • Status: offline
Re: Use register to perform as EEPROM 2020/06/03 16:55:03 (permalink)
+2 (2)
Hi guys,
 
I have been busy been locked down grin: grin and only returned to office this week.  I will finish the job at hand then experiment the HEF solution.
 
You are really great people. Thanks heaps.
#24
zenforker
Starting Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2020/05/24 17:08:09
  • Location: Australia
  • Status: offline
Re: Use register to perform as EEPROM 2020/06/30 21:14:13 (permalink)
+2 (2)
Hi guys,
 
Just got time to complete the project. Great that it works as expected.
 
The HEF code is taken from AN1673. As I only need one row data, I reserved the last row of the HEF and leave the rest for code program. 
 
Thanks all for the help.  Really appreciated.
 
Cheers,
Scott
 
#25
Page: < 12 Showing page 2 of 2
Jump to:
© 2020 APG vNext Commercial Version 4.5