PDA

View Full Version : Storing a variable in EEPROM



Tissy
- 28th October 2005, 01:48
I'm trying to store a numeric variable into a PIC18F2550 EEPROM.

I would like to store the variable and then call it later on.

This is what i use to store the variable


DelayIn VAR WORD
Delayin = 120 ' This is in Seconds

Write 5, Delayin.Byte0
Write 6, Delayin.Byte1

And to Read


Procedure:
Read 5, DelayOut.byte0
Read 6, DelayOut.Byte1
Pause DelayOut * 1000 ' Multiply DelayIn by 1000 to give seconds
For Loop = 1 to 5
Red = 1
Pause 100
Red = 0
Pause 100
Next Loop
Return

If the variable was set at 120, i would expect the pause around 120seconds (2mins) before the LED flashed, but its only around 53 seconds. Therefore i am guessing i am not storing the variable correctly.

I've checked the manual and this is the example it gives.

Is there a better way of completing this type of task?

Thanks

DynamoBen
- 28th October 2005, 02:27
Why not store your delay time as a single byte in eeprom? As long as you don't plan on exceeding 255 that should work fine.

DelayIn VAR byte
Delayin = 120 ' This is in Seconds

Write 5, Delayin

Procedure:
Read 5, DelayOut
Pause DelayOut * 1000 ' Multiply DelayIn by 1000 to give seconds
For Loop = 1 to 5
Red = 1
Pause 100
Red = 0
Pause 100
Next Loop
Return

Tissy
- 28th October 2005, 02:42
Tried that, it is still only pausing for around 54-55seconds and not 120 as expected.

I've tried with both the DelayIn and DelayOut VAR BYTE and WORD.

Still no luck.

Any other suggestion?

Regards,

Steve

dmairspotter
- 28th October 2005, 02:54
PAUSE is limited to 65535 milliseconds (65.534) seconds

mytekcontrols
- 28th October 2005, 03:31
Do you have an LCD or RS232 connection? If you have either one of these I would suggest sending out the value you are retrieving from the EEprom using the DIG command to display it as it's individual digits.

Example:


Read eeadr,data
For x = 2 To 0 Step -1
Hserout[data DIG x]
Next x


This will give you a way to confirm the value you are getting out of the EEPROM, and help you troubleshoot the problem by elimination.

Bruce
- 28th October 2005, 06:15
PAUSE works with up to a 16-bit period. If you use an expression that attempts to load anything greater than 65535 into the registers used for the delay period, they will overflow.

65535 + 54465 = 120,000. You're probably getting a delay of 1mS * 54465 due to the overflow. That would explain the ~54 S delay period.

Put together a loop like the one you're using for the LED. You could get several hours (or more) if needed.

mytekcontrols
- 29th October 2005, 13:53
My previous example for viewing your eeprom data for verification was a bit abbreviated, and wouldn't work as stated. So here it is in a more usable form.


DEFINE HSER_TXSTA 20h ' enable RS232 transmission
DEFINE HSER_BAUD 19200 ' set to required baud rate on your system

eeadr con 100 ' set to eeprom address for data of interest
eedata var byte ' eeprom data storage

getdata
Read eeadr,eedata ' retrieve data byte from eeprom
For x = 2 To 0 Step -1 ' extract 3 digits for display
eedata = (eedata DIG x) + $30 ' convert to "decimalized" ascii number
Hserout[eedata] ' send ascii out RS232
Next x ' do it for all 3 digits of byte


With this code added to your program, you can send out, and verify the value of any byte stored in your internal eeprom as a decimalized 3 digit number (readable on any RS232 terminal program).