Hi,
I have a problem concerning time synchronization with two devices. Both devices has the following interrupt routine:
Code:
uint16_t time;
uint16_t mark;
INTERVAL = 10;
slotInterval = 1000;
Timer.fired()
{
time = time + INTERVAL;
if((time - mark) > slotInterval)
{
//SEND MSG by radio
mark = time;
}
}
And on the reception device:
Code:
ReceiveMsg.receive(TOS_MsgPtr msg)
{
//Note rTime is designated as uint16_t as well
// and is what is sent from the other device when timer fires
uint32_t newTime:
newTime = ((uint32)rTime + (uint32_t)time) / 2;
if(newTime > MAX_VALUE)
newTime = newtime - MAX VALUE;
time = (uint16_t)newTime;
}
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?
Thanks a million.
Inderjit