I would recommend keep several sets of your data in the EEPROM along with a pointer to last verified set.
Depending on the amount and types of data, you may want to temporarily storage the data in typedef struct, at the 10 minute interval you write the struct byte by byte to the EEPROM, read the data back and verify it with the original struct in RAM and then update the pointer.
If this processes is interrupted before the data is verified and pointer updated, upon reset the pointer will still point to the last valid data set and the process can continue as before. Using this technique there is no need to revalidate any previous stored data set.
The EEPROM data memory of the PIC16F87XA allows single byte read and writes, rather than specific block/sector writes. So there is little danger of previously written data being corrupted during a power outage.
BigDog
You would store the pointer to the last valid data set in the EEPROM as well.
Upon reset the pointer would be retrieved from EEPROM and your process could restart where it left off.
A question I have is the data set variable in length or fixed?
BigDog
The data set is of fixed variable length.
But then consider a situation wherein the EEPROM is already full of data, and it starts writing into the eeprom over the older data from the start location of the eeprom. So now in this condition how would I know which is the latest data, as the latest data set is surrounded by the old data as well as the new data.
And how could the process start from where it left off, because it has to find the last location where it wrote the data in the eeprom.
Good, that simplifies things.
You're missing the point of the pointer in EEPROM. You are basically creating a linked list of only two or three links or data sets. After a link is update with the current data and verified the pointer in EEPROM is then and only then the pointer is updated to point to that link of the data set just updated. If the process is interrupted the pointer in EEPROM will still point to the last viable data set in the list. Since the data set length is fixed, when the process restarts upon reset, the next link is updated with the current data based on the current pointer plus the fixed length of the datasets, once the pointer in EEPROM is pointing at the second or third link, the updating processes starts back at the first link of the chain, similar to a circular buffer.
The most recent data set is always pointed to by the pointer in EEPROM, the next data set to write and verify the data is known by the pointer plus the fixed length.
With only two or three links or data sets you could even simplify the process further by storing the current link number in EEPROM address 0x00 followed by the pointer to each link in address 0x01, 0x02 and 0x03 sequentially. When the time comes to update the data set, you simply retrieve the next pointer in the sequence and the update the data, verify it, and then and only then update the link number contained in address 0x00. Once the process updates the last link whether it be #2 or #3 the process begins again at the top of the chain.
It's rather a straight forward procedure and should be easy to implement. I've used the same scheme on several projects to hold various types of calibration and position data.
BigDog
Is this pointer user defined?
Wont the pointer value be erased after the above interruption occurs?
And if we are saving the pointer in the eeprom then, how can we find it from the rest of the data?
Could you please the concept in a code..?
Yes, you can use whatever section of the EEPROM you wish, as long as it contains enough bytes to store two or three copies of the typedef structure.
The location of the pointer itself is also at your discretion as well.
No, it's contained in EEPROM which is nonvolatile, unaffected by loss of power.
You'll effective by creating a constant pointer to a pointer in the code itself, which is stored in the program flash, also nonvolatile storage. The constant pointer to the EEPROM pointer will remain intact until you rewrite the program flash.
Do you want me to do everything for you?
You need to attempt to write the routine yourself. If you have problems, post your code and I can assist you with particular issues.
After all this is your project, not mine and you will have to maintain the code in the future.
And to do so requires an understanding of the code, which you will not acquire if I write it for you.
BigDog
#include <pic.h>
#include <eeprom_routines.h>
void delay_time(unsigned int cnt);
void valid_data_check(char address);
unsigned int data[5]={0x34,0x55,0x12,0x0a};
unsigned int eeprom_input_data,i;
char memory_address=0x01,maximum_memory_address=0xff,temp_address,first_loc=0x00,loc; // startin_memory_address
unsigned int size_of_data=0,counter=0,data_to_be_written=0,checksum=0;
void main()
{
// if(counter>0)
// {
// loc=eeprom_read(first_loc);
// memory_address=loc;
// }
// else
// {
// eeprom_write(0x00,0x01);
// delay_time(10);
// }
//
data[4] = data[0]+data[1]+data[2]+data[3]; // Checksum calucated and stored in the data 5th location
if (memory_address >= maximum_memory_address) // we already have the maximum memory address value
{
delay_time(10);
memory_address=0x01; // always starts from the 2nd location of the eeprom
}
else
{
temp_address=0x00;
temp_address=memory_address;
for(i=0;i<5;i++)
{
data_to_be_written=data[i];
eeprom_write(temp_address,data_to_be_written); // stores the data at the appropriate
delay_time(10); // memory location
temp_address++;
}
memory_address+=temp_address;
eeprom_write(first_loc,temp_address); // stores the last written address location
delay_time(10); // in the first location of eeprom
}
}
void valid_data_check(char address) //function for chcking the validity of data whenver required
{ // by providing the starting location
int flag=0,check[5],j=0;
char tmp;
char mem_add=0x01;
do
{
for(j=0;j<5;j++)
check[i]=eeprom_read(memory_address);
tmp=check[0]+check[1]+check[2]+check[3]; //determining the checksum value
if(check[4]==tmp) //verifying the checksum
flag=1;
else
flag=0;
mem_add+=5; // moving onto the next data set
}
while(mem_add == maximum_memory_address || flag == 0);
}
void delay_time(unsigned int cnt)
{
unsigned int i,j;
for(i=0;i<cnt;i++)
for(j=0;j<10000;j++);
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?