You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improved specification of sync clock protocol (#192)
* Add sender/receiver schematic
* Specify audio cable size
* Add link to pico hardware template
* Move physical connector PDF to assets
* Adopt requirement key words from RFC 2119
* Reorganize document sections for consistency and improve wording
* Add explicit transmission packet diagram
* Moved voltage requirement into main specification
* Replace oscilloscope picture with logic trace
* Clarify the sender MUST isolate the clock output
* Clarify how the receiver should adjust their clock
---------
Co-authored-by: Sonya Vasquez <sonya.vasquez@alleninstitute.org>
Copy file name to clipboardExpand all lines: SynchronizationClock.md
+84-17Lines changed: 84 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,60 @@
1
1
<imgsrc="./assets/HarpLogo.svg"width="200">
2
2
3
-
# Synchronization Clock Protocol (1.0)
3
+
# Synchronization Clock Protocol
4
4
5
-
## Introduction
6
-
The `Harp Synchronization Clock` is a dedicated bus that disseminates the current time to/across Harp devices. It is a serial communication protocol that relays the time information. The last byte in each message can be used as a trigger, and allows a `Device`` to align itself with the current `Harp` time.
5
+
This document provides the specification for the Harp Synchronization Clock, a dedicated bus used to synchronize the current time across Harp devices with sub-millisecond accuracy.
7
6
8
-
## Serial configuration
7
+
## Requirements Language
9
8
10
-
* The Baud rate used is 100kbps;
11
-
* The last byte starts *exactly* 672 us before the elapse of the current second (e.g.:)
9
+
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt).
* The packet is composed of 6 bytes (`header[2]` and `timestamp_s[4]`):
16
-
-`header[2] = {0xAA, 0xAF)`
17
-
-`timestamp_s` is of type U32, little-endian, and contains the current second.
13
+
The Harp Synchronization Clock is a serial communication protocol for relaying time information over RS-232. Each message transmits the current time, in whole seconds. The transmission of the last byte in each message is used as a synchronization signal, allowing Harp devices to align their clocks with sub-millisecond accuracy.
18
14
19
-
> **Important**
20
-
>
21
-
> To avoid unexpected behaviors, only one bit at a time should be written to register `R_RESET_DEV`.
15
+
### Baud Rate
16
+
17
+
The baud rate for all transmitted data MUST be 100 kbps.
18
+
19
+
### Transmission Packet (6 bytes)
20
+
21
+
Each transmission packet encodes the current time, in whole seconds. All Harp Synchronization Clock messages MUST use Little-Endian byte ordering and follow the structure below:
22
+
23
+
<table>
24
+
<tr>
25
+
<th align="center">0</th>
26
+
<th align="center">1</th>
27
+
<th align="center">2</th>
28
+
<th align="center">3</th>
29
+
<th align="center">4</th>
30
+
<th align="center">5</th>
31
+
</tr>
32
+
<tr>
33
+
<td align="center">0xAA</td>
34
+
<td align="center">0xAF</td>
35
+
<td align="center" colspan="4">U32</td>
36
+
</tr>
37
+
<tr>
38
+
<td align="center" colspan="2">Header</td>
39
+
<td align="center" colspan="4">Current Time</td>
40
+
</tr>
41
+
</table>
42
+
43
+
### Transmission Timing
44
+
45
+
Transmission of the last byte MUST start exactly 672 μs before the current second lapses.
46
+
47
+
Receivers MUST align their clocks so the next whole second starts exactly 672 μs following reception of the last byte, ensuring any fractional part of the timestamp is zero. Receivers SHOULD complete the initial alignment over as few transmission events as possible, and thereafter MUST keep updating the whole second in sync with successfully transmitted Harp Synchronization Clock messages as long as the whole second is incremented sequentially.
48
+
49
+
## Example Logic Trace
50
+
51
+
Example traces of the transmission signals are shown below from both a logic analyzer and an oscilloscope:
Example microcontroller C code dispatching the serialized data:
26
58
27
59
```C
28
60
@@ -49,18 +81,53 @@ ISR(TCD0_OVF_vect, ISR_NAKED)
49
81
case 7:
50
82
USARTD1_DATA = *timestamp_byte2;
51
83
break;
84
+
// The final byte is dispatched much later than the previous 5.
52
85
case 1998:
53
86
USARTD1_DATA = *timestamp_byte3;
54
87
break;
55
88
}
56
89
}
57
90
```
58
91
59
-
## Physical connection
92
+
Example of microcontroller C++ code for converting the four received encoded bytes to the timestamp:
93
+
94
+
````C
95
+
#define HARP_SYNC_OFFSET_US (672)
96
+
97
+
// Assume 4 bytes of timestamp data (without header) have been written to this array.
98
+
alignas(uint32_t) volatile uint8_t sync_data_[4];
60
99
61
-
The physical connection is made by a simple audio cable. In the same folder of this file, you can find an [example](./PhysicalConnector.pdf) of the sender and the receiver.
100
+
// reinterpret 4-byte sequence as a little-endian uint32_t.
A full example demonstrating a state machine receiving the 6-byte sequence can be found in the [Pico Core](https://github.com/harp-tech/core.pico/blob/main/firmware/src/harp_synchronizer.cpp).
108
+
109
+
## Physical Connection
110
+
111
+
The physical connection for transmission of the Harp Synchronization Clock SHOULD be made by a 3.5 mm audio cable.
112
+
113
+
The connector pinout for a device *receiving* the timestamp is shown below:
> The device *sending* the timestamp MUST isolate each clock output port, preventing ground loops from forming when connecting the audio jack between sender and receiver.
125
+
126
+
A supplementary PDF [example](./assets/PhysicalConnector.pdf) of the sender and the receiver is also available.
62
127
The connector used is from `Switchcraft Inc.` with PartNo. `35RASMT2BHNTRX`.
63
128
129
+
A KiCAD schematic template for creating a Harp device based on the [RP2040](https://www.raspberrypi.com/products/rp2040/) microcontroller with circuitry for receiving the timestamp is provided through the [Pico Template](https://github.com/AllenNeuralDynamics/harp.device.pico-template).
130
+
64
131
## Release Notes
65
132
66
133
- v1.0
@@ -73,4 +140,4 @@ The connector used is from `Switchcraft Inc.` with PartNo. `35RASMT2BHNTRX`.
73
140
* Adopt semantic versioning.
74
141
75
142
- v1.1.1
76
-
* Remove table of contents to avoid redundancy with doc generators.
143
+
* Remove table of contents to avoid redundancy with doc generators.
0 commit comments