Table of Contents

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.

Generate counter events

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.

Enable Timer events

  • Insert a KeyDown operator and set the Filter property to A.
  • Insert a CreateMessage operator and configure the following properties:
    • Payload - Select TimerFrequencyPayload.
    • TimerFrequency - Select the event frequency (e.g. Timer50Hz to generate 50 counts per second). To disable the events in the future, select Disabled.
  • Insert a MulticastSubject operator named TimestampGeneratorGen3 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:

Visualize Timer events

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.

Set counter value

  • Insert a KeyDown operator and set the Filter property to S.
  • Insert a CreateMessage operator and configure the following properties:
    • Payload - Select TimerPayload.
    • Timer - Enter 0 to reset the counter.
  • Insert a MulticastSubject operator named TimestampGeneratorGen3 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.

Timestamp software events

  • Insert a KeyDown operator and set the Filter property to D. This is the software event that will be timestamped.
  • Insert a WithLatestFrom operator.

In a separate branch:

  • Insert a SubscribeSubject operator named TimestampGeneratorGen3 Events.
  • Insert a Parse operator and set the Register property to TimestampedTimer.

To combine the two branches:

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