Set clock
In generator mode, the Timestamp Generator Gen3 sends the current timestamp on its onboard clock to all connected devices as a synchronization signal, so setting the device clock also sets the clock of every connected device. This is useful for resetting the timestamps at the start of every experiment. Refer to the connections article to set up the device in generator mode with the Harp devices it will synchronize, which we will use for the rest of these examples.
This article covers how to visualize the heartbeat events to read the device clock and how to set the device clock in Bonsai.
The complete workflow is shown below. Copy and paste it into Bonsai to get started immediately, or build each section by following the step-by-step instructions in the following sections.
Note
Reading and setting the device clock is a core functionality shared by all Harp devices. Thus, the operators marked with a (Harp) suffix in this article come from the Bonsai.Harp base library (installed automatically as a dependency) instead of the device-specific package.
Warning
The internal clock also resets whenever the device restarts, including after switching between generator and repeater mode with the OPTION button, and if the device is powered off (if it is disconnected from USB while the BATTERY switch is off or if the battery is depleted).
Visualize heartbeat events
By default, the Timestamp Generator Gen3 does not report the timestamps it generates. Enabling the Heartbeat property of the Device operator makes the device report a TimestampSeconds event every second, mirroring the synchronization signal that is sent to the connected devices.
- Click on the
Deviceoperator in the Harp device pattern and set theHeartbeatproperty toEnabled.
The workflow below will show you how to decode and visualize the heartbeat events:
- Insert a
SubscribeSubjectoperator namedTimestampGeneratorGen3 Events. - Insert a
Parse (Harp)operator and set theRegisterproperty toTimestampSeconds. - Insert a
VisualizerWindowoperator.
Run the workflow. The visualizer will display the timestamp on the device clock every second, in whole seconds:
345
346
Set clock with KeyDown
Writing a value to TimestampSeconds sets the device clock, in whole seconds.
- Insert a
KeyDownoperator and set theFilterproperty toA. - Insert a
CreateMessage (Harp)operator and configure the following properties:Payload- SelectTimestampSecondsPayload.TimestampSeconds- Enter0to reset the clock.
- Insert a
MulticastSubjectoperator namedTimestampGeneratorGen3 Commands.
Run the workflow and press A to set the clock. The timestamp in the visualizer window restarts from zero.
Warning
Make sure the device clock is unlocked before setting the clock. If the clock is locked, the device will throw an error:
Runtime error
The device reported an erroneous write command.
Payload: 0, Address: 8, Type: U32.
Alternative: set clock with Timer
You can replace KeyDown with other operators in Bonsai, for instance, a Timer (Reactive) operator that sets the clock after the Bonsai workflow has been running for a certain duration.
- Insert a
Timer (Reactive)operator and configure the following properties:DueTime- Set the number of seconds to wait after the workflow starts to set the clock (e.g.00:00:02for two seconds).Period- Leave this unspecified so that theTimer (Reactive)only triggers once.
- Insert a
CreateMessage (Harp)operator and configure the following properties:Payload- SelectTimestampSecondsPayload.TimestampSeconds- Enter0to reset the clock.
- Insert a
MulticastSubjectoperator namedTimestampGeneratorGen3 Commands.
Run the workflow. The clock is set 2 seconds after the workflow starts.
Documentation for release v1.4.0