This is basically the same problem as using sequence numbers in TCP/IP messages to locate a lost or misplaced packet. As long as the number of buffers in your EEROM is less than half the period of your sequence numbers, then it will be possible to unambiguously find the discontinuity in your buffer -- it will be the only spot where the difference between two successive sequence numbers is not 1 modulo 256. It will in fact be -n modulo 256 where n is the number of records your buffer will hold. It is, of course possible for that discontinuity to occur at the end of the buffer -- i.e. where the two "ends" of the buffer are "pasted" together to make a circle. > -----Original Message----- > From: Dwayne Reid [SMTP:dwayner@PLANET.EON.NET] > Sent: Tuesday, November 30, 1999 3:17 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: challenge - which number is higher > > I have an interesting problem that I'd like to throw to the gurus. > > I am storing a number of records in eeprom - kind of a circular buffer > arrangement. Part of each record is a 1 byte number used as a 'sequence' > counter - its purpose is to tell me which record is the newest. The > counter > will start at 00, increment to FF, then roll over back to 00. > > This is the challenge: how to tell which number is highest. The records > are stored in a fixed sequence, with the oldest record being overwritten > by > the current record. Again, the sequence number is part of the record > being > stored. > > When the system powers up, I need to retreive the newest record and stick > it > into RAM. > > Eg. Read the sequence number from 8 records and find the most recent > record. > > 00 01 02 03 04 05 06 07 (easy) > F9 FA FB FC FD FE FF 00 (harder) > FE FF 00 01 02 03 04 05 (harder) > > The problem is dealing with the wrap from FF to 00. > > Thoughts, ideas? > > dwayne > > > > Dwayne Reid > Trinity Electronics Systems Ltd Edmonton, AB, CANADA > (780) 489-3199 voice (780) 487-6397 fax > > Celebrating 15 years of Engineering Innovation (1984 - 1999) > > * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * > Do NOT send unsolicited commercial email to this email address. > My posting messages to Usenet neither grants consent to receive > unsolicited commercial email nor is intended to solicit commercial > email.