time synchronization problem

This is a discussion on time synchronization problem within the C Programming forums, part of the General Programming Boards category; Hi, I have a problem concerning time synchronization with two devices. Both devices has the following interrupt routine: Code: uint16_t ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    20

    time synchronization problem

    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

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    45
    Not precisely sure what you're doing, but..

    Code:
       if(newTime > MAX_VALUE)
          newTime = newtime - MAX VALUE;
    Do you mean :

    Code:
       if(newTime > MAX_VALUE)
          newTime = MAX VALUE;
    ?

    we are one

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer problem... i think
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 11-30-2005, 03:45 PM
  2. another problem with catstr() this time
    By the_winky_files in forum C Programming
    Replies: 19
    Last Post: 09-22-2005, 05:20 PM
  3. time problem
    By sand_man in forum C Programming
    Replies: 9
    Last Post: 09-13-2005, 06:59 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM
  5. Problem with time on the board, or is it just me?
    By biosninja in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 10-23-2002, 06:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21