SSI - Digital encoder input

The SSI block instantiates a Synchronous Serial Interface (SSI) master to communicate with SSI-compatible digital encoders and similar digital sensors, typically in motor drive applications.

This block is only compatible with the B-Box4, which provides two RS-485-based serial ports (SERIAL A and SERIAL B). Both ports can interface with sensors using three widely adopted communication protocols: SSI (this page), BiSS-C and EnDat2.2.

Along with the single-turn position, this block supports the reception of a multi-turn counter and follows the common assumption that the single-turn and multi-turn values are placed side by side in the frame received from the sensor, as illustrated below.

SSI frame with multi-turn and single-turn data side by side, as assumed by the SSI block.

As the SSI protocol does not define separate versions, this driver is compatible with any sensor that uses binary-encoded SSI. Gray encoding is currently not supported.

SSI protocol in a nutshell

The SSI protocol is a master-slave serial interface standard created by Max Stegmann GmbH in 1984. Nowadays, it is widely used in industrial applications. Designed for a single master and a single slave, the SSI protocol creates a direct, point-to-point communication link.

The interface is composed of two unidirectional signals, CLOCK (driven by the master) and DATA (driven by the slave), regardless of the resolution (i.e., number of bits per revolution) of the sensor. Differential signaling improves the noise immunity and allows for longer cable runs, making it suitable for industrial environments.

The transmission of a frame starts when the controller (master) starts the CLOCK. Then, the sensor (slave) sends back the data – usually the encoder position – bit by bit on DATA, synchronously with the CLOCK. The transmission ends by the time-out (DATA signal maintained to LOW by the slave) and the pause (mandatory idle state before the next transmission starts).

Strengths and limitations

The SSI protocol is valued for its simple and robust design. With only two differential digital lines, it can be easily integrated and performs reliably even in electrically noisy environments. The synchronous data transfer provides accurate, low-latency position feedback, making it well suited for real-time control.

On the downside, SSI is a one-way protocol with no automatic configuration or diagnostic capability. The master must know the frame structure of the sensor, and the maximum cable length decreases as the clock frequency increases.

Simulink block

Signal specification

  • The θ output is the single-turn position, in radians, in [0, 2π].
  • The cnt output is the multi-turn counter, as received from the sensor. This port is hidden by default but it can be shown using the Output multi-turn counter checkbox.
  • The v output is the data valid signal, set to 1 each time a new data are available.
  • The sim input is a 2-dimensional vector used in simulation and represents the angle value (in radians) and multi-turn counter (-) computed by the simulation plant model.
  • The > input signal needs to be connected to the sampling clock generated by the CONFIG block.

Parameters

  • Device ID selects which device to address when used in a multi-device configuration.
  • Serial port selects the serial port.
  • Clock frequency specifies the transmission clock frequency for the SSI communication, in MHz. The clock frequency cannot exceed 2 MHz, as defined by the SSI standard.
  • Direction specifies the direction as clockwise or counterclockwise. When counterclockwise is selected, the output angle θ is 2π-θ’, where θ’ is the angle received from the sensor.
  • Single-turn resolution specifies the resolution (i.e., number of bits) for the single-turn position. The single-turn resolution cannot exceed 32 bits.
  • Multi-turn resolution specifies the resolution (i.e., number of bits) for the multi-turn counter. The multi-turn resolution cannot exceed 32 bits.
  • Additional first clock delay specifies the delay, in us, added to the first half clock period.
  • Pause delay specifies the duration, in us, of the recovery time after each transmission.
  • Output multi-turn counter shows or hides the multi-turn counter output cnt.

PLECS block

Signal specification

  • The θ output is the single-turn position, in radians, in [0, 2π].
  • The cnt output is the multi-turn counter, as received from the sensor. This port is hidden by default but it can be shown using the Output multi-turn counter checkbox.
  • The v output is the data valid signal, set to 1 each time a new data are available.
  • The sim input is a 2-dimensional vector used in simulation and represents the angle value (in radians) and multi-turn counter (-) computed by the simulation plant model. This input is visible in the parent level.
  • The > input signal needs to be connected to the sampling clock generated by the CONFIG block.

Parameters

  • Device ID selects which device to address when used in a multi-device configuration.
  • Serial port selects the serial port.
  • Clock frequency specifies the transmission clock frequency for the SSI communication, in MHz. The clock frequency cannot exceed 2 MHz, as defined by the SSI standard.
  • Direction specifies the direction as clockwise or counterclockwise. When counterclockwise is selected, the output angle θ is 2π-θ’, where θ’ is the angle received from the sensor.
  • Single-turn resolution specifies the resolution (i.e., number of bits) for the single-turn position. The single-turn resolution cannot exceed 32 bits.
  • Multi-turn resolution specifies the resolution (i.e., number of bits) for the multi-turn counter. The multi-turn resolution cannot exceed 32 bits.
  • Additional first clock delay specifies the delay, in us, added to the first half clock period.
  • Pause delay specifies the duration, in us, of the recovery time after each transmission.
  • Output multi-turn counter shows or hides the multi-turn counter output cnt.

C++ functions

void Ssi_Init(unsigned int port, unsigned int device);Code language: C++ (cpp)

Initializes a given serial port (A or B) for SSI communication protocol.

Can only be called in UserInit().

Parameters

  • port: the serial port to initialize (0 for Port A, 1 for Port B)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)
void Ssi_ConfigureClkFrequency(float clk_frequency, unsigned int port, unsigned int device);Code language: C++ (cpp)

Configures the SSI clock speed for a given serial port (A or B), in MHz.

The clock frequency should not exceed 2 MHz, as defined by the SSI standard.

Can only be called in UserInit().

Parameters

  • clk_frequency: the SSI clock frequency, in MHz
  • port: the serial port to configure (0 for Port A, 1 for Port B)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)
void Ssi_ConfigureDirection(tRs485Direction direction, unsigned int port, unsigned int device);Code language: C++ (cpp)

Configures the angular direction (clockwise or counterclockwise) of the SSI communication protocol for a given serial port (A or B). If counterclockwise is selected, the output angle θ is 2π-θ’, where θ’ is the angle received from the sensor.

Can only be called in UserInit().

Parameters

  • direction: the angular direction (RS485_CW or RS485_CCW)
  • port: the serial port to configure (0 for Port A, 1 for Port B)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)
void Ssi_ConfigurePayload(unsigned short n_bit_before, unsigned short n_bit_multiturn, unsigned short n_bit_singleturn, unsigned short n_bit_after, unsigned int port, unsigned int device);Code language: C++ (cpp)

Configures the SSI frame structure, as expected to be received from the sensor. The frame structure considers that the single-turn and multi-turn values are placed side by side in the frame received from the sensor.

The single-turn and multi-turn resolution fields are each limited to 32 bits, with a maximum payload length of 64 bits (i.e., n_bit_before + n_bit_multiturn + n_bit_singleturn + n_bit_after ≤ 64).

The n_bit_before and n_bit_after fields accommodate sensors that include auxiliary bits surrounding the position data. Correctly configuring these parameters ensures proper alignment of the position data and avoid bit-shifted readings.

For instance, an E36CM-SSI-1211-1012 (Hohner) encoder, which transmits a leading bit before the 12-bit multi-turn and 10-bit single-turn values, is configured using Ssi_ConfigurePayload(1, 12, 10, 0, <port>, <device>).

Can only be called in UserInit().

Parameters

  • n_bit_before: the number of leading bits in the frame
  • n_bit_multiturn: the multi-turn resolution (number of bits of the multi-turn counter)
  • n_bit_singleturn: the single-turn resolution (number of bits of the single-turn position)
  • n_bit_after: the number of trailing bits in the frame
  • port: the serial port to configure (0 for Port A, 1 for Port B)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)
void Ssi_ConfigureAdditionalFirstClockDelay(float delay, unsigned int port, unsigned int device);Code language: C++ (cpp)

Configures delay, in us, to be added to the first half clock period sent by the master to the slave when starting a new transmission.

Can only be called in UserInit().

Parameters

  • delay: the delay added to the first half clock period, in us
  • port: the serial port to configure (0 for Port A, 1 for Port B)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)
void Ssi_ConfigurePauseDelay(float delay, unsigned int port, unsigned int device);Code language: C++ (cpp)

Configures the duration, in us, of the recovery time after each transmission.

Can only be called in UserInit().

Parameters

  • delay: the recovery time after each transmission, in us
  • port: the serial port to configure (0 for Port A, 1 for Port B)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)
void Ssi_ReadFrame(unsigned int port, unsigned int device);Code language: C++ (cpp)

Reads and interprets the latest SSI frame received from the sensor.

Can only be called in the interrupt routine.

Parameters

  • port: the serial port to configure (0 for Port A, 1 for Port B)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)
float Ssi_GetPosition(unsigned int port, unsigned int device);Code language: C++ (cpp)

Returns the single-turn position received from the sensor as an angle, in radians within [0, 2π].

Can only be called in the interrupt routine, after Ssi_ReadFrame().

Parameters

  • port: the serial port to configure (0 for Port A, 1 for Port B)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)

Return value

  • Returns the single-turn position in radians within [0, 2π].
unsigned int Ssi_GetMultiturnCounter(unsigned int port, unsigned int device);Code language: C++ (cpp)

Returns the multi-turn counter received from the sensor.

Can only be called in the interrupt routine, after Ssi_ReadFrame().

Parameters

  • port: the serial port to configure (0 for Port A, 1 for Port B)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)

Return value

  • Returns the multi-turn counter.
unsigned int Ssi_GetDataValid(unsigned int port, unsigned int device);Code language: C++ (cpp)

Returns the data valid flag, which indicates whether new sensor data has been received. A value of 1 means the single-turn position and the multi-turn counter were updated since last interruption. A value of 0 indicates that no new data was received and the previous values have been retained.

Can only be called in the interrupt routine, after Ssi_ReadFrame().

Parameters

  • port: the serial port to configure (0 for Port A, 1 for Port B)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)

Return value

  • Returns 1 if the single-turn position and multi-turn counter have been updated since the last interrupt; returns 0 if the outputs remain unchanged.
void Ssi_ErrorCheck(unsigned int port, unsigned int device);Code language: C++ (cpp)

Checks the communication status and raises warnings in the logs in Cockpit in case of communication error(s).

Can only be called in the interrupt routine.

Parameters

  • port: the serial port to configure (0 for Port A, 1 for Port B)
  • device: the ID of the addressed device (optional, used in multi-device configuration only)