• AVR Freaks

Helpful ReplyHot!Use register to perform as EEPROM

Page: 12 > Showing page 1 of 2
Author
zenforker
Starting Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2020/05/24 17:08:09
  • Location: Australia
  • Status: offline
2020/05/27 04:09:08 (permalink)
0

Use register to perform as EEPROM

hi all,
 
My first post here.
 
I am using PIC10LF322 for a simple battery powered LED strap project. The task is to switch a LED between modes: On-Flash-Off. Due to bad spring selection which we cannot rectify, the LED may lose power briefly if the strap accidentally hits a hard object.  It then recovers to the default mode: ON, no matter whatever previous mode was, could be OFF or Flash.  Customer is not happy.
 
PIC10LF322 doesn't have EEPROM to remember the previous mode.  As some registers retain their value after a brown-out reset (I don't know how this works after losing power), I thought I may be able to utilize top two bits of the BORON to hold LED modes. I enabled BOREN, Power UP Timer, Low Power Brown-Out and Low Trip Point Brown-out reset. 
 
To validate the idea, I use an external power supply to provide 3V to a development board which has been setup the same as the real circuit. I turned off the power then turned back on after a second or two.  It only worked once in hundreds of tests.  So it's a failure.
 
Has anyone tried the idea yet?  Is it possible? Anything did I do wrong? 
 
I may be on the wrong direction.  Please enlighten me on the issue.  
 
Thanks!
#1
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11935
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: Use register to perform as EEPROM 2020/05/27 10:24:07 (permalink) ☄ Helpfulby zenforker 2020/05/27 20:12:23
+4 (4)
There aren't any RAM bits that will be retained across a power failure.  Your PIC has high-endurance flash, use that.
#2
crosland
Super Member
  • Total Posts : 2017
  • Reward points : 0
  • Joined: 2005/05/10 10:55:05
  • Location: Warks, UK
  • Status: offline
Re: Use register to perform as EEPROM 2020/05/27 10:56:00 (permalink)
+3 (3)
zenforker
As some registers retain their value after a brown-out reset (I don't know how this works after losing power), 

It doesn't.
#3
NorthGuy
Super Member
  • Total Posts : 6228
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online
Re: Use register to perform as EEPROM 2020/05/27 13:48:03 (permalink)
+3 (3)
zenforker
the LED may lose power briefly if the strap accidentally hits a hard object.



If it is really brief, this may be cured by a capacitor on VDD.
#4
ric
Super Member
  • Total Posts : 28006
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Use register to perform as EEPROM 2020/05/27 14:02:10 (permalink) ☄ Helpfulby zenforker 2020/05/27 20:12:02
+2 (2)
zenforker
Due to bad spring selection which we cannot rectify, the LED may lose power briefly if the strap accidentally hits a hard object.

Are you saying your PIC loses power?
Why say "the LED", when it is the PIC that matters?
 
  As some registers retain their value after a brown-out reset (I don't know how this works after losing power),

This is where you made a bad guess.
 

I thought I may be able to utilize top two bits of the BORON to hold LED modes. I enabled BOREN, Power UP Timer, Low Power Brown-Out and Low Trip Point Brown-out reset.

You appear to be talking about the CONFIG word, which is stored in FLASH.
You cannot change this from a running program.
There is no feature in this PIC called "BORON". Did you mean "BOREN", which you mention in the next sentence?
 

To validate the idea, I use an external power supply to provide 3V to a development board which has been setup the same as the real circuit. I turned off the power then turned back on after a second or two.  It only worked once in hundreds of tests.  So it's a failure.

It's not clear what it was you were actually testing.
No writable registers in the PIC can be depended upon to keep their values if power is removed.
 
As already mentioned, the only nonvolatile memory you have is the "HEF FLASH", which resides in the top 128 words of your FLASH memory. The datasheet explains how to write and erase this area.
 

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!
#5
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/05/27 18:53:51 (permalink)
0
hi guys,
 
Thanks for your help. Obviously you have confirmed my fear, the register bits can change after power down. even though the datasheet says they are "u", unchanged after brown-out reset.
 
I read HEF before and thought it is not suitable because of the voltage requirements. I will definitely read again hoping I am wrong :). I have already ordered 47uF capacitor, the largest I can find for my PCB.
 
I will provide updates for my findings. Once again, appreciate your help.
 
Scott
 
 
 
#6
ric
Super Member
  • Total Posts : 28006
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Use register to perform as EEPROM 2020/05/27 19:20:55 (permalink)
+3 (3)
"Brown out" means just that power sags, not that it is lost altogether.
You should be looking at "Power on reset" values for that.
 

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!
#7
Aussie Susan
Super Member
  • Total Posts : 3736
  • Reward points : 0
  • Joined: 2008/08/18 22:20:40
  • Location: Melbourne, Australia
  • Status: offline
Re: Use register to perform as EEPROM 2020/05/27 19:29:12 (permalink) ☄ Helpfulby zenforker 2020/05/27 20:11:40
+2 (2)
Which registers specifically are you talking about?
If you are talking about POR/BOR resets, then Table 2-3 of the datasheet shows virtually all register bits has having '1', '0' or 'x' as their reset condition - 'x' being "unknown". "u" only appears in the "...other resets" column.
Also do you mean the BORCON register? If so the top two bits of that register are set to '1' and '0' respectively on POR/BOR so they won't help you.
Susan
#8
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11935
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: Use register to perform as EEPROM 2020/05/27 19:59:02 (permalink) ☄ Helpfulby zenforker 2020/05/27 20:11:35
+2 (2)
they are "u", unchanged after brown-out reset.

 
They are not unchanged after a BOR, they are unchanged by a BOR.  For example, a brownout reset will set the BOR bit to 0, but it will not change the value of the POR bit.
#9
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/05/27 20:08:33 (permalink)
0
Ric, what happened is that the battery shifted briefly after the box get hit, the power loss is about 20ms to 100ms.
 
Susan, you are absolutely right.  This is exactly the case :).
 
I will see if HEF can help with 3.3V power. 
#10
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/05/27 20:13:40 (permalink)
+1 (1)
jtemples
they are "u", unchanged after brown-out reset.

 
They are not unchanged after a BOR, they are unchanged by a BOR.  For example, a brownout reset will set the BOR bit to 0, but it will not change the value of the POR bit.


I should have come here to ask long time ago,  thanks mate.
#11
ric
Super Member
  • Total Posts : 28006
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Use register to perform as EEPROM 2020/05/27 20:15:51 (permalink)
+2 (2)
The electrical specifications say "VDD for Write or Row Erase" is "Vdd min" to "Vdd max"
i.e. you can erase and write to the FLASH under the full range of Vdd that is supported to run the chip.
 

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!
#12
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/05/27 20:23:44 (permalink)
0
ric
The electrical specifications say "VDD for Write or Row Erase" is "Vdd min" to "Vdd max"
i.e. you can erase and write to the FLASH under the full range of Vdd that is supported to run the chip.
 


It would solve my problem if I can write to HEF with 3.3V power. I will give it a go for sure. 
 
Thanks for your help.
#13
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/27 22:36:39 (permalink)
+2 (2)
Is there a diode to stop the capacitor from powering the LED?
#14
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/28 00:43:39 (permalink)
+1 (3)
RAM will not hold it's current value once it loses power.  From experience the RAM could not hold any value after it loses power although sometimes it's unchanged .  My suggestion is you store your current value to 5 different address in your ram.  Let's say you store value of 0x55 for OFF,  0xAA for FLASH.  On power up you check these five addresses, if any of them shows 0x55 that's more likely to be your OFF state,  or if 0xAA to be your FLASH state.  Any other value will be regarded as ON state (default).  
This will give you better chances of getting the correct status.
For more robust checking, you need to write two bytes for each address with 2nd byte as the complement checksum.
For example  for OFF state you write 0x55,0xAB  . While FLASH state 0xAA,0x56
So on power up you need to verify if you get 0x55,0xAB for Off   or  0xAA,0x56 for Flash.
While this solution does not guarantee to work every time at least it will show the correct Off  and Flash state.
 
 
post edited by Jordiw - 2020/05/28 00:45:36
#15
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/05/28 01:17:05 (permalink)
0
pcbbc
Is there a diode to stop the capacitor from powering the LED?


No, there isn't. The circuit has been certified so cannot change any hardware apart from the code.
#16
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/05/29 04:01:11 (permalink)
+1 (1)
Jordiw
RAM will not hold it's current value once it loses power.  From experience the RAM could not hold any value after it loses power although sometimes it's unchanged .  My suggestion is you store your current value to 5 different address in your ram.  Let's say you store value of 0x55 for OFF,  0xAA for FLASH.  On power up you check these five addresses, if any of them shows 0x55 that's more likely to be your OFF state,  or if 0xAA to be your FLASH state.  Any other value will be regarded as ON state (default).  
This will give you better chances of getting the correct status.
For more robust checking, you need to write two bytes for each address with 2nd byte as the complement checksum.
For example  for OFF state you write 0x55,0xAB  . While FLASH state 0xAA,0x56
So on power up you need to verify if you get 0x55,0xAB for Off   or  0xAA,0x56 for Flash.
While this solution does not guarantee to work every time at least it will show the correct Off  and Flash state.
 
 


Wow, you are really creative Smile. I never thought about it.  Let me give HEF a go (was busy today so didn't have time to try it out). I definitely have learnt something from you.
post edited by zenforker - 2020/05/29 04:03:46
#17
ric
Super Member
  • Total Posts : 28006
  • 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 04:05:11 (permalink)
+1 (1)
Have you ever worked with FLASH before?
Are you aware that ERASE sets all the bits to "1", so you get 0xFF in each location.
You can then program bits individually from "1" to "0", so you can overwrite 0xFF with anything.
You can overwrite existing values with new values that only change "1" to "0", but the only way to return a "0" back to a "1" is to erase a whole row.
A "row" is only 16 bytes on that PIC.
 
post edited by ric - 2020/05/29 04:06:26

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!
#18
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 05:43:31 (permalink)
+2 (2)
zenforker
pcbbc
Is there a diode to stop the capacitor from powering the LED?


No, there isn't. The circuit has been certified so cannot change any hardware apart from the code.


You're the one who said....
zenforkerI have already ordered 47uF capacitor, the largest I can find for my PCB.

 
Suggest you add one to your next design.
#19
NKurzman
A Guy on the Net
  • Total Posts : 18858
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: Use register to perform as EEPROM 2020/05/29 05:49:14 (permalink)
+2 (2)
Just a note.
Check the life on the HEF. Make sure you’re not going to burn it out in your design.
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2020 APG vNext Commercial Version 4.5