I have a problem concerning time synchronization with two devices. Both devices has the following interrupt routine:
And on the reception device:
INTERVAL = 10;
slotInterval = 1000;
time = time + INTERVAL;
if((time - mark) > slotInterval)
//SEND MSG by radio
mark = time;
My problem becomes when the time overflows and mark is still a higher value. What I want to do is average their both devices time value so that it doesn't differ too much for time synchronization. They should be exactly the same. Anyone has a suggestion how to fix this or even another solution that is better?
//Note rTime is designated as uint16_t as well
// and is what is sent from the other device when timer fires
newTime = ((uint32)rTime + (uint32_t)time) / 2;
if(newTime > MAX_VALUE)
newTime = newtime - MAX VALUE;
time = (uint16_t)newTime;
Thanks a million.