This is common algorithm used to queue up to a certain amount of data. N= o,=20 you really don't want to move all the EEPROM data around every time. Wha= t=20 you need is 2 variables for pointing to the "head" and "tail" of the queu= e. =20 These will actually hold an index to the eeprom data locations, and will = be=20 "rotated" thru the 10 data locations. I'll assume you have locations=20 EEPROM_BASE_ADDR thru EEPROM_BASE_ADDR+9 allocated for the queue. (1) Start with both head and tail set to the same value, 0. (2) When you get a new measurement, increment head using head =3D (head = +1)=20 modulo 10, and store the data there (EEPROM_BASE_ADDR + (new head value).= =20 The modulo 10 will ensure that you don't overrun the data locations and w= ill=20 cycle the head pointer back to the start. (2.1) For the next measurement, increment head again and store there. E= tc. (3) However, when doing this, check for the condition (head+1 =3D=3D tai= l) each=20 time. This means that you've caught up to your 10th-to-last measurement. (3.1) If you don't want to overwrite a measurement until it has been rea= d,=20 then stop writing new measurements here, until data is read back (tail wi= ll=20 move). (3.2) However, since you stated/implied that you don't care about overwr= iting=20 the oldest measurement, then write the new measurement as before, and=20 increment tail (modulo 10 again) when this condition is reached, so that = you=20 keep an accurate count of how many measurements in the queue are valid. = head=20 alone will not tell you this. (head+10 - tail) modulo 10 will actually t= ell=20 you how many measurements are valid at any time. (4) As a clarification, if you've read/stored at least 10 measurements, = at=20 any time you want to read the measurements, ((head + 10) modulo 10) is th= e=20 newest/latest measurement. Then ((head-1 + 10) modulo 10), etc until=20 ((head-9) + 10) modulo 10) which is the oldest. It's easier to think of this as a circle divided into 10 pie-slices, with= =20 movement only in one direction for head and tail (both in the same=20 direction). It's easier to see when one "catches" the other. Cheers, -Neil. On Friday 16 May 2003 09:21, Mccauley, Daniel H scribbled: > For my project I wish to do the following: > > For each measurement I take with this electronic timing device (my PIC > controlled device), I want to store the result as following: > > Measurement 1 - Result 1 > > For the next measurement, the data would be stored in: > > Measurement 2 - Result 2 > > This would go so on until 10 Results are stored. Since I am only stori= ng > 10 results, for the 11th measurement, I want to discard the oldest > datapoint and store the new datapoint at location Result 10. > > So basically I'm only storing the last 10 Results and always dropping t= he > oldest to allow room for the newest result. > > My question is, what is the best way to code this??? (I'm using CCS C > compiler) Do I move actual data through EEPROM everytime > the 11th, 12th, so on results are being stored, or is it better to chan= ge > the actual EEPROM storage address. > > Any help appreciated!!! > > D -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu