Device Registers
Registers
The Harp protocol relies on registers with specific functionalities and data types, and are essentially used to exchange information with the device.
The Harp Current Driver registers are declared in the device's device.yml file.
These register names are used by the software and will be described here according with their functionality, for quick reference and easier understanding.
Some registers support multiple states, by using bit masks, where each bit represents a specific state. In contrast, group masks are typically used for configuration, allowing only one state to be active at a time.
A bit mask is a binary pattern used to manipulate specific bits within a value. It helps selectively enable, disable, or extract particular bits in the registers.
LED current
The current of each LED output is configured, in mA, through the Led0Current and Led1Current
registers. The accepted range is 0 to 500 mA. In the Manual channel mode,
the new value is applied immediately.
The Led0MaxCurrent and Led1MaxCurrent registers specify the maximum current, in mA, allowed for
the corresponding LED output, and can be used to protect LEDs rated for currents below 500 mA. The
default value is 100 mA.
Always check the maximum continuous and pulsed current of the connected LED in its datasheet before configuring the current of the output.
DAC voltage
The voltage of each DAC output is configured, in mV, through the Dac0Voltage and Dac1Voltage
registers. The accepted range is 0 to 5000 mV.
The DAC of each channel is shared between its DAC output and its LED output. For the LED output, the
DacXVoltage value corresponds to a current of:
I_LED [mA] = DacXVoltage [mV] / 10
i.e. Dac0Voltage = 2500 mV corresponds to 250 mA in the LED0 output.
LED drivers
Each LED driver can be enabled or disabled without changing its configured set point. Both drivers are disabled after power-up.
For each one of the registers LedEnable, LedDisable and LedState, you can set the correspondent
bit mask for the LED output(s) you need to configure:
| Name | Hex mask | Binary mask |
|---|---|---|
| Led0 | 0x01 | 0b00000001 |
| Led1 | 0x02 | 0b00000010 |
LedEnable: enables the LED drivers whose bits are set in the written mask.LedDisable: disables the LED drivers whose bits are set in the written mask.LedState: writes the state of both LED drivers at once (bit set enables the driver, bit cleared disables it).
Pulses
The pulse function makes a channel alternate between its configured value and zero. It is enabled
through the PulseEnable register, using the same bit mask as the LED drivers:
| Name | Hex mask | Binary mask |
|---|---|---|
| Led0 | 0x01 | 0b00000001 |
| Led1 | 0x02 | 0b00000010 |
The pulse train of each channel is configured through:
PulseFrequencyLed0/PulseFrequencyLed1: frequency of the pulse train, in Hz (1 to 255).PulseDutyCycleLed0/PulseDutyCycleLed1: percentage of each period in which the output is on (1 to 100).
Pulses are generated by the device with a time resolution of 1 ms, so the on and off times are rounded to the millisecond. At high frequencies, choose duty cycles that result in integer on times (e.g. at 100 Hz, the period is 10 ms and each 10 % of duty cycle corresponds to 1 ms).
Configure the frequency before the duty cycle, as the pulse timings are computed from both values.
Ramps
Ramps make the transitions between two different values of a channel linear over time, instead of
immediate. The duration of the ramp of each channel is configured, in ms, through the
RampLed0 and RampLed1 registers (1 to 65535 ms).
The RampConfig register selects on which transitions the ramps are applied, using the following
bit mask:
| Name | Hex mask | Binary mask | Description |
|---|---|---|---|
| Led0Rise | 0x01 | 0b00000001 | Ramp on rising transitions of LED0 |
| Led0Fall | 0x02 | 0b00000010 | Ramp on falling transitions of LED0 |
| Led1Rise | 0x04 | 0b00000100 | Ramp on rising transitions of LED1 |
| Led1Fall | 0x08 | 0b00001000 | Ramp on falling transitions of LED1 |
Ramps are only applied while the pulse function of the corresponding channel is disabled.
Channel modes
Each channel can operate in one of four modes, configured through the Channel0Mode and
Channel1Mode registers using the following group mask:
| Name | Value | Description |
|---|---|---|
Manual | 0 | The output changes as soon as a new current/voltage value is written (default). |
Protocol | 1 | The protocol is configured beforehand and triggered in software. |
StartProtocolTrigger | 2 | The protocol settings must be defined beforehand and triggered in hardware when the respective DI state changes from LOW to HIGH. |
StartAndStopProtocolTrigger | 3 | The protocol starts when the respective DI state changes from LOW to HIGH and ends when it changes from HIGH to LOW. |
Channel 0 is triggered by DI0 and channel 1 by DI1.
Changing the mode of a channel resets it and sets its output to zero. When switching back to
Manual, the configured current/voltage is applied again.
Protocols
In the protocol modes, the current/voltage, pulse and ramp configuration of the channel is stored and only applied to the output when the protocol starts. A protocol is defined by:
Protocol0Delay/Protocol1Delay: time between the start of the protocol and the moment the output goes to the configured value (0 to 65535). A value of 0 applies it immediately.Protocol0Duration/Protocol1Duration: time the output is held at the configured value before returning to zero (0 to 65535). A value of 0 keeps the output on until the protocol is stopped. The duration is ignored in theStartAndStopProtocolTriggermode, where the protocol only ends on the falling edge of the DI.
When a protocol ends, the output returns to zero, using the falling ramp if it is enabled in
RampConfig. Starting a protocol that is already running restarts it, including its delay.
In the Protocol mode, the protocols are started and stopped through the EnableProtocol and
DisableProtocol registers, using the following bit mask:
| Name | Hex mask | Binary mask |
|---|---|---|
| Led0 | 0x01 | 0b00000001 |
| Led1 | 0x02 | 0b00000010 |
EnableProtocol: starts the protocol of the channels whose bits are set in the written mask.DisableProtocol: stops the protocol of the channels whose bits are set in the written mask.
EnableProtocol and DisableProtocol only act on channels configured in the Protocol mode.
Channel state
The ChannelState event reports whether each channel output is at a non-zero value (bit set, HIGH)
or at zero (bit cleared, LOW). An event is sent every time a channel reaches one of these states,
i.e. on each pulse edge, at the end of each ramp, or when a new value is applied immediately. The
register uses the same bit mask as the LED drivers.
If no events are received from the ChannelState register, ensure that the correspondent bit of
the EnableEvents register bit mask is set, specifically ChannelState(0x2).
Digital IOs
Two digital inputs and two digital outputs are available in the device.
Digital inputs
The state of the digital inputs is reported by the DigitalInputState event, which is emitted every
time a transition is detected on an input line. The digital inputs are also used as hardware triggers
for the protocols. The register uses the following bit mask:
| Name | Hex mask | Binary mask |
|---|---|---|
| DI0 | 0x01 | 0b00000001 |
| DI1 | 0x02 | 0b00000010 |
If no events are received from the DigitalInputState register, ensure that the correspondent bit of
the EnableEvents register bit mask is set, specifically DIs(0x1).
Digital outputs
The digital outputs can be controlled through the registers OutputSet, OutputClear,
OutputToggle and OutputState.
For each one of these registers, you can set the correspondent bit mask for the digital output(s) you need to configure:
| Name | Hex mask | Binary mask |
|---|---|---|
| DO0 | 0x01 | 0b00000001 |
| DO1 | 0x02 | 0b00000010 |
OutputSet: sets the output lines whose bits are set in the written mask.OutputClear: clears the output lines whose bits are set in the written mask.OutputToggle: toggles the output lines whose bits are set in the written mask.OutputState: writes the state of all output lines at once.
State registers enable setting and clearing multiple states simultaneously, which is especially useful for precise timing, e.g. when the user needs to switch multiple outputs with different states at the same time.
Events
The events published by the device are configured through the EnableEvents register, using the
bit mask below. Only the events whose bit is set are sent by the device. Both events are enabled by
default.
| Name | Hex mask | Binary mask | Event |
|---|---|---|---|
| DIs | 0x01 | 0b00000001 | DigitalInputState |
| ChannelState | 0x02 | 0b00000010 | ChannelState |
Register summary
| Address | Register | Access | Type | Description |
|---|---|---|---|---|
| 32 | DigitalInputState | Event | U8 | State of the digital inputs. |
| 33 | OutputSet | Write | U8 | Sets the specified digital output lines. |
| 34 | OutputClear | Write | U8 | Clears the specified digital output lines. |
| 35 | OutputToggle | Write | U8 | Toggles the specified digital output lines. |
| 36 | OutputState | Write | U8 | Writes the state of all digital output lines. |
| 37 | LedEnable | Write | U8 | Enables the specified LED drivers. |
| 38 | LedDisable | Write | U8 | Disables the specified LED drivers. |
| 39 | LedState | Write | U8 | Writes the state of both LED drivers. |
| 40 | Led0Current | Write | Float | Current of LED 0 output [0:500] mA. |
| 41 | Led1Current | Write | Float | Current of LED 1 output [0:500] mA. |
| 42 | Led0MaxCurrent | Write | Float | Maximum current allowed in LED 0 output [0:500] mA. |
| 43 | Led1MaxCurrent | Write | Float | Maximum current allowed in LED 1 output [0:500] mA. |
| 44 | Dac0Voltage | Write | Float | Voltage of DAC 0 output [0:5000] mV. |
| 45 | Dac1Voltage | Write | Float | Voltage of DAC 1 output [0:5000] mV. |
| 46 | PulseEnable | Write | U8 | Enables the pulse function for the specified channels. |
| 47 | PulseDutyCycleLed0 | Write | U8 | Duty cycle of the channel 0 pulses [1:100] %. |
| 48 | PulseDutyCycleLed1 | Write | U8 | Duty cycle of the channel 1 pulses [1:100] %. |
| 49 | PulseFrequencyLed0 | Write | U8 | Frequency of the channel 0 pulses, in Hz. |
| 50 | PulseFrequencyLed1 | Write | U8 | Frequency of the channel 1 pulses, in Hz. |
| 51 | RampLed0 | Write | U16 | Duration of the channel 0 ramps, in ms. |
| 52 | RampLed1 | Write | U16 | Duration of the channel 1 ramps, in ms. |
| 53 | RampConfig | Write | U8 | Specifies on which transitions the ramps are applied. |
| 54 | Protocol0Duration | Write | U16 | Duration of the channel 0 protocol. |
| 55 | Protocol1Duration | Write | U16 | Duration of the channel 1 protocol. |
| 56 | Protocol0Delay | Write | U16 | Delay of the channel 0 protocol. |
| 57 | Protocol1Delay | Write | U16 | Delay of the channel 1 protocol. |
| 58 | EnableProtocol | Write | U8 | Starts the protocol of the specified channels. |
| 59 | DisableProtocol | Write | U8 | Stops the protocol of the specified channels. |
| 60 | Channel0Mode | Write | U8 | Mode of operation of channel 0. |
| 61 | Channel1Mode | Write | U8 | Mode of operation of channel 1. |
| 62 | ChannelState | Event | U8 | Sent when a channel reaches its LOW or HIGH state. |
| 63–67 | Reserved0–Reserved4 | Read | U8 | Reserved. |
| 68 | EnableEvents | Write | U8 | Specifies the active events in the device. |