Generate counter events
Besides the heartbeat event, the Timestamp Generator Gen3 can also report a high-frequency counter (50–1000 Hz) as Timer events. Each event carries an incrementing value timestamped with the device clock, which is useful for inspecting the clock and detecting dropped messages. It can also be used to assign Harp timestamps to data that are not generated by Harp devices, such as software-generated events, thereby timestamping them on the same clock as the Harp devices.
This article covers how to enable and visualize the Timer events, set the counter value, and assign Harp timestamps to software events.
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
The Timer event is different from the Timer (Reactive) Bonsai operator used in the Set clock article. Timer is an event from a hardware counter on the device, whereas Timer (Reactive) is a software trigger in Bonsai that uses the operating system clock to count elapsed time.
Warning
For the rest of these workflows, use the device-specific versions of the operators, e.g. Device (Harp.TimestampGeneratorGen3) instead of Device (Harp). If correctly selected, the names of these operators in the workflow panel will change to reflect either the name of the device or the selected register/payload.
Enable Timer events
The Timer events are disabled by default, so set the TimerFrequency to start them.
- Insert a
KeyDownoperator and set theFilterproperty toA. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectTimerFrequencyPayload.TimerFrequency- Select the event frequency (e.g.Timer50Hzto generate 50 counts per second). To disable the events in the future, selectDisabled.
- Insert a
MulticastSubjectoperator namedTimestampGeneratorGen3 Commands.
Run the workflow and press A. The device starts reporting Timer events at 50 Hz (covered in the next section).
Visualize Timer events
Each Timer event carries the current counter value and the timestamp at which it was generated. The workflow below will show you how to decode and visualize the Timer events:
- Insert a
SubscribeSubjectoperator namedTimestampGeneratorGen3 Events. - Insert a
Parseoperator and set theRegisterproperty toTimestampedTimer. - Insert a
VisualizerWindowoperator.
Run the workflow and press A to enable the counter. The visualizer will display:
4778@95.563344
4779@95.583344
The first number is the counter value, and the second number is the timestamp on the device clock.
Note
To detect dropped messages, analyze the logged data to check that the counter is increasing sequentially by one without any skipped numbers.
Set counter value
Writing a value to Timer sets the value of the counter. This is useful for resetting the counter to zero at the start of a session.
- Insert a
KeyDownoperator and set theFilterproperty toS. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectTimerPayload.Timer- Enter0to reset the counter.
- Insert a
MulticastSubjectoperator namedTimestampGeneratorGen3 Commands.
Run the workflow and press S. The counter value in the visualizer window resets to zero, like this:
0@99.563344
1@99.583344
Tip
To reset the onboard clock that timestamps the events, see the Set clock article.
Timestamp software events
Software events, such as key presses, can be assigned Harp timestamps by pairing them with the latest Timer event.
- Insert a
KeyDownoperator and set theFilterproperty toD. This is the software event that will be timestamped. - Insert a
WithLatestFromoperator.
In a separate branch:
- Insert a
SubscribeSubjectoperator namedTimestampGeneratorGen3 Events. - Insert a
Parseoperator and set theRegisterproperty toTimestampedTimer.
To combine the two branches:
- Connect the
Parseoperator to theWithLatestFrom. Each key press will now be paired with the latestTimerevent. - Insert a
VisualizerWindowoperator to display the paired events.
Run the workflow and press D. Each key press appears in the visualizer window paired with the latest counter and timestamp:
(D, 141404@19990.36)
(D, 146440@20000.66)
Note
The timestamp resolution with this strategy is set by the TimerFrequency (e.g. 20 ms at 50 Hz). Use a higher frequency for finer resolution. The pairing is done in software by Bonsai, and Windows is not a real-time operating system, so it is not ideal for high-precision timing applications. For that, log the events on a hardware clock instead, such as a digital input on another Harp device.
Documentation for release v1.4.0