Clock synchronization method
A system and method of synchronizing the clocks between two connected BLUETOOTH® devices is disclosed. The two devices exchange packets that contain a timestamp that is indicative of the time that each device received a packet from the other device. By exchanging this information, each device may determine the offset between its internal clock and the internal clock of the other device. Once clock synchronization is achieved, the central device may transmit packets to the peripheral requesting that particular actions be taken at specific times.
1 . A method of synchronizing internal clocks between a first wireless network device having a first clock and a second wireless network device having a second clock, the method comprising:
transmitting, from the first wireless network device, a request for synchronization;
receiving, at the second wireless network device, the request for synchronization;
determining, at the second wireless network device, a value of the second clock when the request for synchronization was received, referred to as Timestamp B;
transmitting a first packet from the second wireless network device to the first wireless network device that contains a value of Timestamp B;
receiving, at the first wireless network device, the first packet with Timestamp B;
determining, at the first wireless network device, a value of the first clock when the first packet was received, referred to as Timestamp A;
transmitting a second packet from the first wireless network device to the second wireless network device that contains the value of Timestamp A;
saving, at the second wireless network device, a previous value of Timestamp B, referred to as PrevTimeB;
determining, at the second wireless network device, a value of the second clock when the second packet was received, referred to as Timestamp B;
generating a value, referred to as B Intervals, based on a difference between Timestamp B and PrevTimeB and a duration of a connection interval;
transmitting from the second wireless network device a third packet containing a value of Timestamp B and B Intervals to the first wireless network device;
saving a previous value of Timestamp A, referred to as PrevTimeA, at the first wireless network device;
receiving the third packet from the second wireless network device containing a value of Timestamp B and the value of B Intervals;
determining, at the first wireless network device, a value of the first clock when the third packet was received, referred to as Timestamp A;
generating a value, referred to as A Intervals, based on a difference between Timestamp A and PrevTimeA and the duration of the connection interval;
comparing a value of A Intervals and B Intervals each to a predetermined number to determine if retries occurred; and
if retries did not occur, calculating, at the first wireless network device and the second wireless network device, an offset between the first clock and the second clock using Timestamp A and Timestamp B.
2 . The method of claim 1 , wherein the second wireless network device transmits the first packet during a different connection interval than the connection interval during which it received the request for synchronization.
3 . The method of claim 2 , wherein, prior to the second wireless network device transmitting the first packet, the first wireless network device transmits a dummy packet and the second wireless network device waits an idle time after receipt of the dummy packet prior to transmitting the dummy packet.
4 . The method of claim 3 , wherein a duration of time used to transmit the dummy packet is used in calculating the offset.
5 . The method of claim 3 , wherein a duration of time used to transmit the dummy packet and the idle time are used in calculating the offset.
6 . The method of claim 1 , wherein the first wireless network device transmits the second packet during the same connection interval as receipt of the first packet, and wherein a value of A Intervals and B Intervals greater than 1 indicates that retries occurred.
7 . The method of claim 1 , wherein the first wireless network device transmits the second packet during a next connection interval after receipt of the first packet, and wherein a value of A Intervals and B Intervals not equal to 2 indicates that retries occurred.
8 . The method of claim 1 , wherein the first wireless network device transmits another packet containing a value of Timestamp A if it determines that retries occurred.
9 . The method of claim 1 , wherein, after calculating the offset, the first wireless network device transmits a packet to the second wireless network device, wherein the packet includes an action to performed at a desired time, wherein the desired time is referenced to the first clock; and wherein the second wireless network device receives the packet, converts the desired time to a value referenced to the second clock and performs the action at the desired time.
10 . A system comprising:
a first wireless network device having a first clock; and
a second wireless network device having a second clock;
wherein the first wireless network device transmits a request for synchronization;
wherein the second wireless network device receives the request for synchronization; determines a value of the second clock when the request for synchronization was received, referred to as Timestamp B, and transmits a first packet to the first wireless network device that contains a value of Timestamp B;
wherein the first wireless network device receives the first packet with Timestamp B, determines a value of the first clock when the first packet was received, referred to as Timestamp A, and transmits a second packet to the second wireless network device that contains the value of Timestamp A;
wherein the second wireless network device saves a previous value of Timestamp B, referred to as PrevTimeB, determines a value of the second clock when the second packet was received, referred to as Timestamp B, generates a value, referred to as B Intervals, based on a difference between Timestamp B and PrevTimeB and a duration of a connection interval, and transmits a third packet containing a value of Timestamp B and a value of B Intervals to the first wireless network device;
wherein the first wireless network device saves a previous value of Timestamp A, referred to as PrevTimeA, receives the third packet from the second wireless network device containing a value of Timestamp B and the value of B Intervals, determines a value of the first clock when the third packet was received, referred to as Timestamp A, generates a value, referred to as A Intervals, based on a difference between Timestamp A and PrevTimeA and the duration of the connection interval, compares a value of A Intervals and B Intervals each to a predetermined number to determine if retries occurred; and
if retries did not occur, the first wireless network device and the second wireless network device calculate an offset between the first clock and the second clock using Timestamp A and Timestamp B.
11 . The system of claim 10 , wherein the second wireless network device transmits the first packet during a different connection interval than the connection interval during which it received the request for synchronization.
12 . The system of claim 11 , wherein, prior to the second wireless network device transmitting the first packet, the first wireless network device transmits a dummy packet and the second wireless network device waits an idle time after receipt of the dummy packet before transmitting the first packet.
13 . The system of claim 12 , wherein a duration of time used to transmit the dummy packet is used in calculating the offset.
14 . The system of claim 12 , wherein a duration of time used to transmit the dummy packet and the idle time are used in calculating the offset.
15 . The system of claim 10 , wherein the first wireless network device transmits the second packet during the same connection interval as receipt of the first packet, and wherein a value of A Intervals and B Intervals greater than 1 indicates that retries occurred.
16 . The system of claim 10 , wherein the first wireless network device transmits the second packet during a next connection interval after receipt of the first packet, and wherein a value of A Intervals and B Intervals not equal to 2 indicates that retries occurred.
17 . The system of claim 10 , wherein the first wireless network device transmits another packet containing a value of Timestamp A if it determines that retries occurred.
18 . The system of claim 10 , wherein, after calculating the offset, the first wireless network device transmits a packet to the second wireless network device, wherein the packet includes an action to performed at a desired time, wherein the desired time is referenced to the first clock; and wherein the second wireless network device receives the packet, converts the desired time to a value referenced to the second clock and performs the action at the desired time.