Non volitile storage
Non volitile storage
I need to store four 8 bit calibration parameters for my temperature sensors, even after a reset or power off. Is this what the EPROM component is for? If not how can I specify that these variables are to be stored in non volatile memory, separate from the programme memory, as they are not specified by my programme but entered using a menu? I assume all other variables are wiped to zero by a reset/power down.
I got confused about the EPROM component because when I added it, it had no connections to the PIC. Is it in fact representing an internal area of the PIC? Also is it supported in my Student/Home version of Flowcode? Apologies if all this is in the Help file for EPROM.
I got confused about the EPROM component because when I added it, it had no connections to the PIC. Is it in fact representing an internal area of the PIC? Also is it supported in my Student/Home version of Flowcode? Apologies if all this is in the Help file for EPROM.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
If you need a constant value then you can just assign a variable with a value at the start of your program.
EG VAR1 = 23
You will need to make sure that you do not change the value of the variable.
EG VAR1 = 23
You will need to make sure that you do not change the value of the variable.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
EEPROM
Having now upgraded to Professional I can use the EEPROM component. It talks of storing byte variables. What happens if they are integer variables though? Will it put them in 2 bytes? Do I need to do anything special to set it up?
If I write a variable to an EPROM location with EEPROMWrite(addr, data) command will it always write to that location even if I don’t repeat the EEPROMWrite(addr, data) before every time that variable is called?
Same question for ReadEEPROM(addr). Indeed do I have to use ReadEEPROM(addr) at all, as the program should know where the data is once an EEPROMWrite(addr, data ) is used?
If I write a variable to an EPROM location with EEPROMWrite(addr, data) command will it always write to that location even if I don’t repeat the EEPROMWrite(addr, data) before every time that variable is called?
Same question for ReadEEPROM(addr). Indeed do I have to use ReadEEPROM(addr) at all, as the program should know where the data is once an EEPROMWrite(addr, data ) is used?
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
The EEPROM component currently does not "know" about INT (or STRING) data types. To store an INT variable, you will need to break it into a high byte and a low byte and save it to two adjacent locations within the EEPROM memory.
As for the other questions, I'm not sure exactly what you mean. The <EEPROMWrite> macro takes 2 parameters - "addr" is the addrss within the EEPROM memory where the data is written, and "data" is a BYTE value or variable that is to be stored. If a variable is used, the value of the variable at the time of the macro call is stored. If the variable value subsequently changes within your program, the EEPROM value is not updated (unless you then call the <EEPROMWrite> macro again).
The reason for storing data into EEPROM is that the values stored will be retained even when the PICmicro is turned off.
As for the other questions, I'm not sure exactly what you mean. The <EEPROMWrite> macro takes 2 parameters - "addr" is the addrss within the EEPROM memory where the data is written, and "data" is a BYTE value or variable that is to be stored. If a variable is used, the value of the variable at the time of the macro call is stored. If the variable value subsequently changes within your program, the EEPROM value is not updated (unless you then call the <EEPROMWrite> macro again).
The reason for storing data into EEPROM is that the values stored will be retained even when the PICmicro is turned off.
Ah I understand. I need to either
1) Use variables in RAM as normal and then only store the values in EEPROM before shutting down. Need to trigger on something like the brownout limit to detect when to do this storage. Any suggestions of how to detect immanent shutdown other than by using a spare A/D input (run out of pins) to measure falling supply voltage? I have a battery backup so shutdown would be gradual.
2) Or store them in EEPROM every single time they change using the write command, which conceivably could exceed the read/write life of the EEPROM.
1) Use variables in RAM as normal and then only store the values in EEPROM before shutting down. Need to trigger on something like the brownout limit to detect when to do this storage. Any suggestions of how to detect immanent shutdown other than by using a spare A/D input (run out of pins) to measure falling supply voltage? I have a battery backup so shutdown would be gradual.
2) Or store them in EEPROM every single time they change using the write command, which conceivably could exceed the read/write life of the EEPROM.
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
I'm not sure how to detect shut-down without using a free i/o pin.
I suppose your strategy for saving EEPROM data depends on the application you are designing and the data you are saving. If you can, please explain more about your program and I'll think about a possible solution.
One possible strategy would be to set up a timer interrupt and store your data every second (or any time period that is appropriate). Of course, you may not always be saving the latest set of data - but that may not be critical.
I suppose your strategy for saving EEPROM data depends on the application you are designing and the data you are saving. If you can, please explain more about your program and I'll think about a possible solution.
One possible strategy would be to set up a timer interrupt and store your data every second (or any time period that is appropriate). Of course, you may not always be saving the latest set of data - but that may not be critical.
Data to be kept only changes every 30 mins and a 30 min loop is already set. So maybe I could save it every 30min. Loss of one 30min value is not critical.
Would it run for 10-20 years without exceeding EEPROM read/write life? If there is a crash or battery goes flat the system upon reboot would read the EPROM values.
How easy to split integers into 2 bytes? Is they a forum topic on this?
Would it run for 10-20 years without exceeding EEPROM read/write life? If there is a crash or battery goes flat the system upon reboot would read the EPROM values.
How easy to split integers into 2 bytes? Is they a forum topic on this?
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Hello
It is very easy to split an int into two bytes.
First we have two byte variable BLow and BHigh
And an Int variable Int1
To convert from an Int to two bytes.
BLow = Int1 & 0xFF
BHigh = ( Int1 >> 8 ) & 0xFF
To covert back from two bytes to an Int
Int1 = BLow
Int1 = Int1 + ( BHigh << 8 )
It is very easy to split an int into two bytes.
First we have two byte variable BLow and BHigh
And an Int variable Int1
To convert from an Int to two bytes.
BLow = Int1 & 0xFF
BHigh = ( Int1 >> 8 ) & 0xFF
To covert back from two bytes to an Int
Int1 = BLow
Int1 = Int1 + ( BHigh << 8 )
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
If you are concerned about EEPROM life, you could build in a check within your program so that data written to the EEPROM is immediately read back to make sure the data has been transferred ok.
If it has not been transferred, your program could begin to use a different part of the EEPROM instead. You would need to update a specific address within the EEPROM so your program knows the new location to store data.
This technique will work if the amount of data stored is relatively low.
Another thing you could do to minimise data writes is to only write new data if the data has changed.
If it has not been transferred, your program could begin to use a different part of the EEPROM instead. You would need to update a specific address within the EEPROM so your program knows the new location to store data.
This technique will work if the amount of data stored is relatively low.
Another thing you could do to minimise data writes is to only write new data if the data has changed.