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.
>> 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
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/
>>> 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
>>> 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.