Non-volatile memory

19 views
Skip to first unread message

zags...@hotmail.com

unread,
Apr 4, 2012, 9:34:07 AM4/4/12
to jal...@googlegroups.com
Hello,


I need information about non-volatile memory.

Firstly, this is one part of my program. It'll be easier to explain my problem :

if (SAU_A == high & SAN_A == high) then
   n = 1
   repeat
   if (n==1 & SAD_A == high) then
      repeat
      first = adc_read(0)               <---<---<---
      until(SAD_A == low)
      n = n+1
   end if
   fd = first - ramin
   fu = first + ramax
   until(SAU_A == low)
end if

So when I push on the buttons (SAN_O, SAU_O and SAD_O), it allow to read the analog input and save the value into variable first (var dword first) (see line with the arrows).
The problem is that when I turn off the micro-controller (remove the battery) it looses the variable first. I would like to keep in memory the variable even if I turn off the micro-controller.
Do you know how can I put the value in the eeprom or something equivalent ?


Kind regards,

Sébastien

Oliver Seitz

unread,
Apr 4, 2012, 12:45:08 PM4/4/12
to jal...@googlegroups.com

> Do you know how can I put the value in the eeprom or something equivalent ?

If the PIC has data eeprom, use the library pic_data_eeprom.jal

Greets,
Kiste

vasile surducan

unread,
Apr 4, 2012, 2:26:26 PM4/4/12
to jal...@googlegroups.com
Analyze also which will be the sampling rate stored in the eeprom. If you need only one eeprom_put before shutting down the whole stuff, then is OK, but you will need a flag to validate the operation. Once data has been stored, the flag should be set (or reset). At power on time, the same flag will allow loading the last stored data into the eeprom location.


--
You received this message because you are subscribed to the Google Groups "jallib" group.
To post to this group, send email to jal...@googlegroups.com.
To unsubscribe from this group, send email to jallib+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jallib?hl=en.


Oliver Seitz

unread,
Apr 4, 2012, 3:31:28 PM4/4/12
to jal...@googlegroups.com

>If you need only one eeprom_put before shutting down the whole stuff, then is OK,

I did deliberately not go to much into detail about write cycles and the like... As in this case it seems to be irrelevant. It should be stored on a button press. The data eeprom is specified for 1 million write cycles. Simple pushbuttons are specified for 100 000 or 1 million presses. So that's a good match: One write per button press, both will last the same time. Which is three years, if you press the button once a second, 8 hours a day, five days a week :-)

Greets,
Kiste

mattschinkel

unread,
Apr 5, 2012, 7:51:50 AM4/5/12
to jallib
There is also a sample:

18f4550_data_eeprom.jal

zags...@hotmail.com

unread,
Apr 5, 2012, 11:04:44 AM4/5/12
to jal...@googlegroups.com
Thanks for the advice everybody :-)

I use pic_data_eeprom.jal librery and it work very well.

Actually, I use the microcontroller for a gear controls. The EEPROM memory is use to store the gears break point and others parameters. So, I will write on the EEPROM maximum a hundred times depending on the test which will be do.

Now, I've got another question about the offset (data_eeprom_write_dword(<offset>,<dword>)). How long have to be the offset for a dword ?
I mean, in the example, the storage is every 1 offset ( i = i + 1 ) and the counter is stored in a byte. So if I want to write a dword in the EEPROM memory, I need a 4 offset ?

Kind regards,
Sébastien.

Oliver Seitz

unread,
Apr 6, 2012, 2:53:58 AM4/6/12
to jal...@googlegroups.com
>So if I want to write a dword in the EEPROM memory, I need a 4 offset ?

Unsigned variables in jal are defined as

var byte*[n] name

where [n] is a positive integer number above zero. There are aliases defined "word" for "byte*2" and "dword" for "byte*4". Just "byte" can be written instead of "byte*1".

So, yes. To store multiple consecutive byte*4 variables, a pointer has to be incremented by four to point to the next free space.

Greets,
Kiste

zags...@hotmail.com

unread,
Apr 6, 2012, 3:23:48 AM4/6/12
to jal...@googlegroups.com
ok, thanks for information
Reply all
Reply to author
Forward
0 new messages