-
Notifications
You must be signed in to change notification settings - Fork 6
Dev/sync time validity #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d99f5f9
4fca7cc
3fa8382
4ac5782
0b7d0d8
dda0bb4
d31ae7d
6f4a9b5
32956cc
65efd96
886ce32
c72551a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,15 +14,14 @@ The `Harp Synchronization Clock` is a dedicated bus that disseminates the curren | |||||
|
||||||
* The packet is composed of 6 bytes (`header[2]` and `timestamp_s[4]`): | ||||||
- `header[2] = {0xAA, 0xAF)` | ||||||
- `timestamp_s` is of type U32, little-endian, and contains the current second. | ||||||
- `timestamp_s` is of type U32, little-endian, and contains the previous elapsed second. | ||||||
|
||||||
> **Important** | ||||||
> | ||||||
> To avoid unexpected behaviors, only one bit at a time should be written to register `R_RESET_DEV`. | ||||||
A sample logic trace is shown below: | ||||||
 | ||||||
|
||||||
## Example code | ||||||
|
||||||
Example of a microcontroller C code: | ||||||
Example of a microcontroller C code dispatching the serialized data: | ||||||
|
||||||
```C | ||||||
|
||||||
|
@@ -49,18 +48,58 @@ ISR(TCD0_OVF_vect, ISR_NAKED) | |||||
case 7: | ||||||
USARTD1_DATA = *timestamp_byte2; | ||||||
break; | ||||||
// The final byte is dispatched much later than the previous 5. | ||||||
case 1998: | ||||||
USARTD1_DATA = *timestamp_byte3; | ||||||
break; | ||||||
} | ||||||
} | ||||||
``` | ||||||
|
||||||
Example of a microcontroller C++ code for converting the four received encoded bytes to the timestamp: | ||||||
````C | ||||||
#define HARP_SYNC_OFFSET_US (672) | ||||||
|
||||||
// Assume 4 bytes of timestamp data (without header) have been written to this array. | ||||||
alignas(uint32_t) volatile uint8_t sync_data_[4]; | ||||||
|
||||||
// reinterpret 4-byte sequence as a little-endian uint32_t. | ||||||
uint32_t encoded_sec = *(reinterpret_cast<uint32_t*>(self->sync_data_)); | ||||||
// Convert received timestamp to the current time in microseconds. | ||||||
// Add 1[s] per protocol spec since 4-byte sequence encodes the **previous** second. | ||||||
uint64_t curr_us = ((static_cast<uint64_t>(encoded_sec) + 1) * 1e6) - HARP_SYNC_OFFSET_US; | ||||||
```` | ||||||
|
||||||
A full example demonstrating a state machine receiving the 6-byte sequence can be found in the [Pico Core](https://github.com/AllenNeuralDynamics/harp.core.rp2040/blob/main/firmware/src/harp_synchronizer.cpp). | ||||||
|
||||||
--- | ||||||
|
||||||
|
||||||
## Physical connection | ||||||
|
||||||
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. | ||||||
The physical connection is made by a simple 3.5mm audio cable. | ||||||
|
||||||
The connector pinout for a device *receiving* the timestamp is shown below: | ||||||
|
||||||
 | ||||||
|
||||||
A TVS diode is also suggested for ESD protection. | ||||||
|
||||||
> [!IMPORTANT] | ||||||
> The device receiving the timestamp must provide 3.3-5V (~10mA) on the audio jack **R** pin. | ||||||
|
||||||
The schematic snippet for a device *sending* the timestamp is shown below: | ||||||
|
||||||
 | ||||||
|
||||||
> [!NOTE] | ||||||
> The device *sending* the timestamp isolates each clock output port, preventing ground loops from forming when connecting the audio jack between sender and receiver. | ||||||
|
||||||
A supplementary PDF [example](./assets/PhysicalConnector/PhysicalConnector.pdf) of the sender and the receiver is also available. | ||||||
The connector used is from `Switchcraft Inc.` with PartNo. `35RASMT2BHNTRX`. | ||||||
|
||||||
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). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Similar to above, it might be useful to transfer the pico template repository to harp-tech. Not sure whether it should be named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this idea! Per Kicad-9 improvements, I may make some changes and add a secondary hardware library to this template, but I haven't settled on that just yet. The big change in V9 was the ability to create schematic "snippets" called Design Blocks and reuse them within and across projects. I paste snippets across projects manually for various power supply designs, so I may do further reading on how to tease them into a repository. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Short term, I think the docs changes are usable and an improvement as-is, so I'd motion for pico hardware template repo migration later. |
||||||
|
||||||
## Release Notes | ||||||
|
||||||
- v1.0 | ||||||
|
@@ -73,4 +112,4 @@ The connector used is from `Switchcraft Inc.` with PartNo. `35RASMT2BHNTRX`. | |||||
* Adopt semantic versioning. | ||||||
|
||||||
- v1.1.1 | ||||||
* Remove table of contents to avoid redundancy with doc generators. | ||||||
* Remove table of contents to avoid redundancy with doc generators. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a missing version increment here? We can discuss what is our convention for incrementing standard document versions going forward. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might have to fill me in what you mean here. Do I need to bump a version somewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a release notes section at the bottom of the document where for other updates we have been bumping release versions. That said, this feels like it is becoming increasingly legacy, and I don't feel these really add anything on top of the versioning git provides. If the proposal in https://github.com/orgs/harp-tech/discussions/129#discussioncomment-12664412 is accepted, then I would actually motion for us to stop adding manual release notes in the files, and actually have all notes in PRs which can then be used to automatically generate notes for new releases. If necessary we could generate back tags and create releases for older versions to keep track of when which bit was introduced, but going forward I feel it would be much simpler for everyone if there was a single version of everything protocol related. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Poofjunior These changes look great, thanks for the greatly improved documentation! If you think we are close to transferring the pico repository I would adapt the URL of this example as suggested above.
You will notice I am implicitly suggesting a naming convention for the core repos which should be consistent with yours, but I have opened a discussion for us to review it together: https://github.com/orgs/harp-tech/discussions/120