I'm working on a simple logic probe project using the ATmega168 and for the most part it works. Except that every now an then I get a time stamp that is "earlier" than the previous time stamp. I have done various tests to determine that the sample data is being sent in order so I am down to the assumption either the sample data is being corrupted or incorrectly captured. With this in mind I have combed the code for possible causes and I'm now at a loss to explain what causes this.
The three byte time stamp is generated by the 16 bit counter and an eight bit overflow count.
As I've already mentioned 99.9% of samples have the correct time stamp but every now and then (I can see no pattern to it) one of the time stamps is earlier than the previous couple of samples. Note that this is not the counter rolling over.... here's the code: