Searching \ for '[PIC]Storing values in a PIC when shutting down' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Storing values in a PIC when shutting down'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]Storing values in a PIC when shutting down'
2010\03\12@005514 by Jason Hsu

picon face
The application I have in mind is providing a voltage output in order
to simulate a sensor.

I have data sets, and I need to incorporate them into the
microcontroller so that it can provide the simulated sensor voltages.

What kind of memory do I need for this?  Is this where EEPROM comes
in?  Or is there another type of memory for this?

--
Jason Hsu
http://www.jasonhsu.com/swrwatt.html
http://www.jasonhsu.com/swrwatt-c.txt
http://www.jasonhsu.com/swrwatt-asm.txt

2010\03\12@012138 by Bob Blick

face
flavicon
face

On Thu, 11 Mar 2010 23:55:09 -0600, "Jason Hsu" said:
> The application I have in mind is providing a voltage output in order
> to simulate a sensor.
>
> I have data sets, and I need to incorporate them into the
> microcontroller so that it can provide the simulated sensor voltages.
>
> What kind of memory do I need for this?  Is this where EEPROM comes
> in?  Or is there another type of memory for this?

Yes, the EEPROM area is intended for non-volatile storage of data. It is
writeable many many times(actual number depends on device).

Most PICs can also store data in program memory, but the number of times
you can write to program memory is more limited.

Preferably you would do the writing BEFORE shutting down, not WHILE
shutting down. EEPROM writes are only guaranteed down to a
certain(dependent on device) operating voltage and they are not
instantaneous.

Lots of different methods have been used to increase confidence in
storing data so as not to end up with corrupt data in case of power
failure during the write process. Many involve writing to alternating or
multiple locations.

Cheerful regards,

Bob

--
http://www.fastmail.fm - Access all of your messages and folders
                         wherever you are

2010\03\12@030149 by ivp

face picon face
>> I have data sets, and I need to incorporate them into the
>> microcontroller so that it can provide the simulated sensor voltages
>>
>> What kind of memory do I need for this?  Is this where EEPROM
>> comes in?  Or is there another type of memory for this?

This sounds like a use for Flash tables. If you've got an 18F or later,
tables have their own instructions

For example, to retrieve a byte from an 18F table, where "t_base" is
a 24-bit address

        mov     upper(t_base),tblptru ;table base address <23:16>
        mov     high(t_base),tblptrh ;table base address <15:8>
        mov     low(t_base),tblptrl ;table base address <7:0>
        tblrd*+               ;read, increment pointer
        movff   tablat,temp   ;retrieve data from address, copy to temp

tblptrx can have W added to them. It's all in the datasheet

If you have something like the 16F, a table stored in Flash can be
accessed with eecon1,eepgd set, target address in eeadr and eeadrh
and data in eedata and eedath. Note that for the 16F it's one byte
of 14-bits, for the 18F it's 2 bytes of 8-bits

> Preferably you would do the writing BEFORE shutting down, not
> WHILE shutting down. EEPROM writes are only guaranteed down
> to a certain(dependent on device) operating voltage and they are not
> instantaneous

Bob, despite the Subject, Jason didn't actually mention shutting
down !!! Had me wondering there for a sec

Joe

2010\03\12@090506 by Isaac Marino Bavaresco

flavicon
face
Em 12/3/2010 02:55, Jason Hsu escreveu:
> The application I have in mind is providing a voltage output in order
> to simulate a sensor.
>
> I have data sets, and I need to incorporate them into the
> microcontroller so that it can provide the simulated sensor voltages.
>
> What kind of memory do I need for this?  Is this where EEPROM comes
> in?  Or is there another type of memory for this?
>  


I use an early power loss interrupt, and in the interrupt routine I save
all the needed data (usually a few bytes):

Connect an interrupt pin (with appropriated protection circuit of
course) to your board's DC input, before your voltage regulator.
For this to work well, your input voltage must be some volts above your
circuit's VDD, so you have enough room for the input voltage to drop
before your circuit goes brown-out. Use a large storage capacitor so the
voltage takes several milliseconds (hundreds preferably) before brown-out.

In your interrupt routine, save all the bytes and wait until the power
goes off or the interrupt pin signals that the power was restored.
It is good if in the interrupt routine you can power down most of the
circuits, so the power consumption gets reduced and you gain some more
time to save the data.

To ensure data integrity, I use a system with two blocks (flip-flop). I
have two blocks of EEPROM to save the data plus one indicator o what
block contains the latest data.

On power-up, check the flag and read the data from the EEPROM.
On power-off (interrupt), first save the data to the other block and
after all the data is saved, invert the flag and save it. This way, if
for some reason your circuit cannot write the on time, then the flag is
not written and you have the old block with good data (although old) to
use in the next power up.

It is a good practice to use a "dirty" flag also, so if in the interrupt
routine the dirty flag is not set, you don't need to save anything.
Don't forget to set the dirty flag when you change your data in RAM, and
clear after finishing to save the flip-flop flag in the interrupt
routine, because a power glitch may generate an interrupt but the power
may be restored before the board powers down.


Best regards,

Isaac
__________________________________________________
Faça ligações para outros computadores com o novo Yahoo! Messenger
http://br.beta.messenger.yahoo.com/

2010\03\12@110248 by Bob Ammerman

picon face

----- Original Message -----
From: "ivp" <spam_OUTjoecolquittTakeThisOuTspamclear.net.nz>
To: "Microcontroller discussion list - Public." <.....piclistKILLspamspam@spam@mit.edu>
Sent: Friday, March 12, 2010 3:01 AM
Subject: Re: [PIC]Storing values in a PIC when shutting down


{Quote hidden}

er, not quite right...

should be:

   movlw upper(t_base)
   movwf tblptru
   movlw high(t_base)
   movwf tblptrh
   movlw low(t_base)
   movwf tblptrl

   etc.

{Quote hidden}

> --

2010\03\12@161437 by ivp
face picon face
>>         mov     upper(t_base),tblptru ;table base address <23:16>

> er, not quite right...
>
> should be:
>
>    movlw upper(t_base)
>    movwf tblptru

mov      macro   litval,file
        movlw   litval
        movwf   file
        endm

cf MOV Wn,f of newer PICs or MOVLF

wbr, Joe

2010\03\12@164748 by ivp

face picon face
> mov      macro   litval,file
>         movlw   litval
>         movwf   file
>         endm

PS, completely understand why you called me on that. Did make
a mental note to include the macro in the original post and then
promptly didn't !

wbr, Joe


2010\03\13@110229 by Bob Ammerman

picon face

>>>         mov     upper(t_base),tblptru ;table base address <23:16>
>
>> er, not quite right...
>>
>> should be:
>>
>>    movlw upper(t_base)
>>    movwf tblptru
>
> mov      macro   litval,file
>         movlw   litval
>         movwf   file
>         endm
>
> cf MOV Wn,f of newer PICs or MOVLF
>
> wbr, Joe

I can see calling such a macro MOVLF, but MOV is just asking for trouble.
And actually, I don't like either because they hide the fact that W is being
trashed.

-- Bob Ammerman
RAm Systems

More... (looser matching)
- Last day of these posts
- In 2010 , 2011 only
- Today
- New search...