Quadrature Encoder#

Introduction#

A Quadrature Encoder (QE), also known as a 2-channel incremental encoder, converts angular displacement into two pulse signals. These two pulses are positioned 90 degrees out of phase. By monitoring both the number of pulses and the relative phase of the two signals, the user code can track the position, direction of rotation, and velocity. The index signal can also be used to reset the position counter.

The quadrature encoder decodes the digital pulses from a quadrature encoder wheel to integrate position over time and determine direction of rotation. Additionally, the QEI can capture the velocity of the encoder wheel. The QEI is present in MCU HP peripherals.

Features of QEI

  1. Tracks encoder wheel position sl_si91x_qei_get_position_counter()

  2. Programmable for 1x, 2x, or 4x position counting, incrementing or decrementing depending on direction sl_si91x_qei_set_encoding_mode()

  3. Includes an index counter for revolution counting sl_si91x_qei_get_index_counter()

  4. Captures velocity using a built-in timer sl_si91x_qei_get_velocity()

  5. Supports position counter reset for rollover/underflow or index pulse sl_si91x_qei_set_configuration()

  6. Provides position, index, and velocity compare registers with interrupts sl_si91x_qei_register_callback()

  7. Allows logically swapping the A and B inputs sl_si91x_qei_swap_a_b()

  8. Accepts decoded signal inputs (clock and direction) in timer mode sl_si91x_qei_configure_timer_mode()

Modules#

sl_qei_version_t

sl_qei_config_t

sl_qei_intr_ack_t

sl_qei_intr_mask_t

sl_qei_intr_unmask_t

sl_gpio_pin_config_t

sl_qei_init_t

Enumerations#

enum
SL_QEI_RESET
SL_QEI_SET
SL_QEI_STATE_LAST
}

Enumeration to control the QEI module.

enum
SL_QEI_NO_SWAP_AB
SL_QEI_SWAP_AB
SL_QEI_SWAP_LAST
}

Enumeration for QEI phase swap control.

enum
SL_QEI_ENCODER_MODE
SL_QEI_TIMER_MODE
SL_QEI_MODE_LAST
}

Enumeration for QEI timer modes.

enum
SL_QEI_ENCODE_MODE_1X
SL_QEI_ENCODE_MODE_2X
SL_QEI_ENCODE_MODE_4X
SL_QEI_ENCODE_MODE_LAST
}

Enumeration for QEI encoding modes.

enum
SL_QEI_NEG_DIRECTION
SL_QEI_POS_DIRECTION
SL_QEI_DIRECTION_LAST
}

Enumeration for QEI direction.

enum
SL_QEI_POS_CNT_32
SL_QEI_POS_CNT_16
SL_QEI_POS_CNT_LAST
}

Enumeration for QEI position counting modes.

enum
SL_QEI_DIGITAL_FILTER
SL_QEI_BYPASS_FILTER
SL_QEI_DIGITAL_FILTER_LAST
}

Enumeration for QEI digital filter settings.

enum
SL_QEI_POS_CNT_RESET_INTR_UNMASK = BIT(0)
SL_QEI_IDX_CNT_MATCH_INTR_UNMASK = BIT(1)
SL_QEI_POS_CNT_ERR_INTR_UNMASK = BIT(2)
SL_QEI_VELOCITY_LESS_INTR_UNMASK = BIT(3)
SL_QEI_POS_CNT_MATCH_INTR_UNMASK = BIT(4)
SL_QEI_VELOCITY_COMP_OVER_INTR_UNMASK = BIT(5)
SL_QEI_PARAM_UNMASK_LAST
}

Enumeration for unmasking QEI interrupts.

enum
SL_QEI_POS_CNT_RESET_INTR_MASK = BIT(0)
SL_QEI_IDX_CNT_MATCH_INTR_MASK = BIT(1)
SL_QEI_POS_CNT_ERR_INTR_MASK = BIT(2)
SL_QEI_VELOCITY_LESS_INTR_MASK = BIT(3)
SL_QEI_POS_CNT_MATCH_INTR_MASK = BIT(4)
SL_QEI_VELOCITY_COMP_OVER_INTR_MASK = BIT(5)
SL_QEI_PARAM_MASK_LAST
}

Enumeration for masking QEI interrupts.

enum
SL_QEI_POS_CNT_RESET_INTR_LVL = BIT(0)
SL_QEI_IDX_CNT_MATCH_INTR_LVL = BIT(1)
SL_QEI_POS_CNT_ERR_INTR_LVL = BIT(2)
SL_QEI_VELOCITY_LESS_INTR_LVL = BIT(3)
SL_QEI_POS_CNT_MATCH_INTR_LVL = BIT(4)
SL_QEI_VELOCITY_COMP_OVER_INTR_LVL = BIT(5)
SL_QEI_PARAM_CLEAR_LAST
}

Enumeration for clearing QEI interrupts.

enum
SL_QEI_UNIDIRECTIONAL_VELOCITY = QEI_UNIDIRECTIONAL_VELOCITY
SL_QEI_UNIDIRECTIONAL_INDEX = QEI_UNIDIRECTIONAL_INDEX
SL_QEI_INDEX_COUNT_INIT = QEI_INDEX_CNT_INIT
SL_QEI_CTRL_INIT_LAST
}

Enumeration for QEI control initialization configuration.

enum
SL_QEI_DIGITAL_FILTER_BYPASS = QEI_DIGITAL_FILTER_BYPASS
SL_QEI_INDEX_COUNT_RESET = QEI_IDX_CNT_RST
SL_QEI_IDX_CNT_RST_EN = QEI_IDX_CNT_RST_EN
SL_QEI_POS_CNT_16_BIT_MDE = QEI_POS_CNT_16_BIT_MDE
SL_QEI_POS_CNT_DIR_FRM_REG = QEI_POS_CNT_DIR_FRM_REG
SL_QEI_POS_CNT_DIR_CTRL = QEI_POS_CNT_DIR_CTRL
SL_QEI_POS_CNT_RST = QEI_POS_CNT_RST
SL_QEI_POS_CNT_RST_WITH_IDX_EN = QEI_POS_CNT_RST_WITH_IDX_EN
SL_QEI_START_VELOCITY_CNTR = QEI_START_VELOCITY_CNTR
SL_QEI_STOP_IN_IDLE = QEI_STOP_IN_IDLE
SL_QEI_SWAP_PHASE_AB_B = QEI_SWAP_PHASE_AB_B
SL_QEI_INTERFACE_TIMER_MODE = QEI_TIMER_MODE
SL_QEI_CONTROL_CONFIG_LAST
}

Enumeration for QEI control configuration.

enum
SL_QEI_CLK_DIV_1 = QEI_CLK_DIV_1
SL_QEI_CLK_DIV_2 = QEI_CLK_DIV_2
SL_QEI_CLK_DIV_4 = QEI_CLK_DIV_4
SL_QEI_CLK_DIV_8 = QEI_CLK_DIV_8
SL_QEI_CLK_DIV_16 = QEI_CLK_DIV_16
SL_QEI_CLK_DIV_32 = QEI_CLK_DIV_32
SL_QEI_CLK_DIV_64 = QEI_CLK_DIV_64
SL_QEI_CLK_DIV_128 = QEI_CLK_DIV_128
SL_QEI_CLK_DIV_256 = QEI_CLK_DIV_256
SL_QEI_CLK_DIV_512 = QEI_CLK_DIV_512
SL_QEI_CLK_DIV_1024 = QEI_CLK_DIV_1024
SL_QEI_CLK_DIV_LAST
}

Enumeration for QEI digital filter clock divide select bits.

Typedefs#

typedef void(*
sl_qei_callback_t)(void *callback_flag)

Callback function type for QEI events.

Functions#

sl_status_t
sl_si91x_qei_init(sl_qei_init_t *qei_init)

Initialize the QEI module.

void

De-initialize the QEI module.

sl_status_t
sl_si91x_qei_set_position_counter(uint32_t pos_cnt_value)

Set the position counter value.

sl_status_t

Start the velocity counter.

__STATIC_INLINE uint32_t

Get the current position counter value.

sl_status_t
sl_si91x_qei_set_encoding_mode(sl_qei_encoding_mode_t mode)

Set the encoding mode for the QEI.

__STATIC_INLINE sl_qei_encoding_mode_t

Get the current encoding mode.

sl_status_t
sl_si91x_qei_set_pos_direction(sl_qei_direction_t direction)

Set the direction for the QEI.

__STATIC_INLINE sl_qei_direction_t

Get the current direction of the QEI.

sl_status_t
sl_si91x_qei_set_index_counter(uint32_t index_count)

Set the index counter value.

__STATIC_INLINE uint32_t

Get the current index counter value.

sl_status_t
sl_si91x_qei_configure_delta_time_frequency(uint32_t freq, uint32_t period)

Configure the delta time frequency for velocity calculation.

sl_status_t
sl_si91x_qei_set_delta_time(uint32_t delta_time)

Set the delta time for velocity calculation.

__STATIC_INLINE uint32_t

Get the current delta time.

__STATIC_INLINE void

Configure the stop state for the velocity counter.

__STATIC_INLINE uint32_t

Get the current velocity value.

sl_status_t

Set the position match value.

__STATIC_INLINE uint32_t

Get the current position match value.

sl_status_t

Set a value for velocity comparison.

sl_status_t

Set the maximum value for the index counter.

__STATIC_INLINE uint32_t

Get the current maximum value for the index counter.

__STATIC_INLINE uint32_t

Get the current interrupt status.

sl_status_t
sl_si91x_qei_swap_a_b(sl_qei_swap_ab_t swap_select)

Swap phases A and B for the QEI.

sl_status_t
sl_si91x_qei_configure_timer_mode(sl_qei_timer_mode_t timer_mode)

Configure the QEI to operate in timer mode.

sl_status_t
sl_si91x_qei_clear_interrupt(uint32_t int_mask)

Clear the interrupt set.

__STATIC_INLINE uint32_t

Get the current interrupt clear settings.

__STATIC_INLINE uint32_t

Get the status of the QEI module.

sl_status_t

Set the frequency for the QEI module.

__STATIC_INLINE uint32_t

Get the current frequency of the QEI module.

sl_status_t
sl_si91x_qei_set_digital_filter_clock_division(sl_qei_clk_div_t clock_division)

Set the digital filter clock division.

__STATIC_INLINE sl_qei_clk_div_t

Get the current digital filter clock division.

sl_status_t
sl_si91x_qei_register_callback(sl_qei_callback_t callback, void *callback_flag_value, sl_qei_intr_unmask_t *intr_flags)

Register a callback function for QEI events.

sl_status_t
sl_si91x_qei_unregister_callback(sl_qei_intr_mask_t *intr_mask)

Unregister a callback function for QEI events.

sl_status_t

Set the maximum position counter value.

__STATIC_INLINE uint32_t

Get the current maximum position counter value.

sl_status_t
sl_si91x_qei_set_configuration(sl_qei_control_t state, sl_qei_config_t *config)

Set configuration parameters for the QEI module.

sl_status_t
sl_si91x_qei_get_configuration(sl_qei_control_t state, sl_qei_config_t *config)

Get configuration parameters for the QEI module.

To get the API version of the QEI module.

Macros#

#define
QEI_SOFT_RST_MASK 0

software reset of the QEI bit

#define
QEI_SWAP_PHASE_AB_MASK 1

swapping phase A and B signals bit

#define
QEI_POS_CNT_RST_WITH_INDEX_EN_MASK 2

position count reset with index signal bit

#define
QEI_POS_CNT_DIRECTION_CTRL_MASK 4

position count direction bit

#define
QEI_POS_CNT_DIR_FROM_REG_MASK 5

position count direction from a register bit

#define
QEI_INDEX_CNT_RST_EN_MASK 8

enable index count reset bit

#define
QEI_DIGITAL_FILTER_BYPASS_MASK 9

bypass the digital filter bit

#define
QEI_TIMER_MODE_MASK 10

setting the timer mode of the QEI bit

#define
QEI_START_VELOCITY_CNTR_MASK 11

starting the velocity counter bit

#define
QEI_STOP_IN_IDLE_MASK 12

stop the QEI in idle state bit

#define
QEI_POS_CNT_MODE_MASK 13

selecting the position count mode bit

#define
QEI_POS_CNT_RST_MASK 14

resetting the position count bit

#define
QEI_INDEX_CNT_RST_MASK 15

resetting the index count bit

#define
QEI_ENCODING_MODE_MASK (0x3 << 0)

Encoding mode (2 bits)

#define
QEI_INDEX_MATCH_VALUE_MASK (0x3 << 4)

Index match value (2 bits)

#define
QEI_DIGITAL_FILTER_DIV_MASK (0xF << 6)

Digital filter division (4 bits)

#define
QEI_UNIDIRECTIONAL_VELOCITY_MASK 10

Unidirectional velocity (1 bit)

#define
QEI_UNIDIRECTIONAL_INDEX_MASK 11

Unidirectional index (1 bit)

#define
QEI_INDEX_CNT_INIT_MASK 12

Index count initialization (1 bit)

Enumeration Documentation#

sl_qei_control_t#

sl_qei_control_t

Enumeration to control the QEI module.

This enumeration manages the setting and clearing of the module and control configuration registers.

Enumerator
SL_QEI_RESET

Reset the configurations of the module and control registers.

SL_QEI_SET

Set the configurations of the module and control registers.

SL_QEI_STATE_LAST

Last member of the enum for validation purposes.


sl_qei_swap_ab_t#

sl_qei_swap_ab_t

Enumeration for QEI phase swap control.

This enumeration manages the phase A and phase B input swap select bit.

Enumerator
SL_QEI_NO_SWAP_AB

No swap for phase A and B.

SL_QEI_SWAP_AB

Swap phase A and B.

SL_QEI_SWAP_LAST

Last member of the enum for validation purposes.


sl_qei_timer_mode_t#

sl_qei_timer_mode_t

Enumeration for QEI timer modes.

This enumeration selects the mode for the quadrature encoder or timer.

Enumerator
SL_QEI_ENCODER_MODE

Set QEI to encoder mode.

SL_QEI_TIMER_MODE

Set QEI to timer mode.

SL_QEI_MODE_LAST

Last member of the enum for validation purposes.


sl_qei_encoding_mode_t#

sl_qei_encoding_mode_t

Enumeration for QEI encoding modes.

This enumeration controls the encoding modes for programmable 1x, 2x, or 4x position counting.

Enumerator
SL_QEI_ENCODE_MODE_1X

1x position counting mode.

SL_QEI_ENCODE_MODE_2X

2x position counting mode.

SL_QEI_ENCODE_MODE_4X

4x position counting mode.

SL_QEI_ENCODE_MODE_LAST

Last member of the enum for validation purposes.


sl_qei_direction_t#

sl_qei_direction_t

Enumeration for QEI direction.

This enumeration defines the possible directions for the Quadrature Encoder Interface (QEI).

Enumerator
SL_QEI_NEG_DIRECTION

Negative direction of rotation (e.g., counterclockwise).

SL_QEI_POS_DIRECTION

Positive direction of rotation (e.g., clockwise).

SL_QEI_DIRECTION_LAST

Last member of the enum for validation purposes.


sl_qei_pos_cnt_mode_t#

sl_qei_pos_cnt_mode_t

Enumeration for QEI position counting modes.

This enumeration defines the position counting mode(16/32-bit) in the Quadrature Encoder Interface (QEI).

Enumerator
SL_QEI_POS_CNT_32

Mode for 32-bit position counting.

SL_QEI_POS_CNT_16

Mode for 16-bit position counting.

SL_QEI_POS_CNT_LAST

Last member of the enum for validation purposes.


sl_qei_digital_filter_t#

sl_qei_digital_filter_t

Enumeration for QEI digital filter settings.

This enumeration defines the settings for digital filtering in the Quadrature Encoder Interface (QEI).

Enumerator
SL_QEI_DIGITAL_FILTER

Enable digital filtering.

SL_QEI_BYPASS_FILTER

digital filtering (bypass mode).

SL_QEI_DIGITAL_FILTER_LAST

Last member of the enum for validation purposes.


sl_qei_intr_unmask_config_t#

sl_qei_intr_unmask_config_t

Enumeration for unmasking QEI interrupts.

This enumeration manages the unmasking of QEI interrupts.

Enumerator
SL_QEI_POS_CNT_RESET_INTR_UNMASK

Unmask position counter reset interrupt.

SL_QEI_IDX_CNT_MATCH_INTR_UNMASK

Unmask index count match interrupt.

SL_QEI_POS_CNT_ERR_INTR_UNMASK

Unmask position counter error interrupt.

SL_QEI_VELOCITY_LESS_INTR_UNMASK

Unmask velocity less than interrupt.

SL_QEI_POS_CNT_MATCH_INTR_UNMASK

Unmask position count match interrupt.

SL_QEI_VELOCITY_COMP_OVER_INTR_UNMASK

Unmask velocity computation overflow interrupt.

SL_QEI_PARAM_UNMASK_LAST

Last member of the enum for validation purposes.


sl_qei_intr_mask_config_t#

sl_qei_intr_mask_config_t

Enumeration for masking QEI interrupts.

This enumeration manages the masking of QEI interrupts.

Enumerator
SL_QEI_POS_CNT_RESET_INTR_MASK

Mask position counter reset interrupt.

SL_QEI_IDX_CNT_MATCH_INTR_MASK

Mask index count match interrupt.

SL_QEI_POS_CNT_ERR_INTR_MASK

Mask position counter error interrupt.

SL_QEI_VELOCITY_LESS_INTR_MASK

Mask velocity less than interrupt.

SL_QEI_POS_CNT_MATCH_INTR_MASK

Mask position count match interrupt.

SL_QEI_VELOCITY_COMP_OVER_INTR_MASK

Mask velocity computation overflow interrupt.

SL_QEI_PARAM_MASK_LAST

Last member of the enum for validation purposes.


sl_qei_intr_clear_config_t#

sl_qei_intr_clear_config_t

Enumeration for clearing QEI interrupts.

This enumeration manages the clearing of QEI interrupts.

Enumerator
SL_QEI_POS_CNT_RESET_INTR_LVL

Clear position counter reset interrupt.

SL_QEI_IDX_CNT_MATCH_INTR_LVL

Clear index count match interrupt.

SL_QEI_POS_CNT_ERR_INTR_LVL

Clear position counter error interrupt.

SL_QEI_VELOCITY_LESS_INTR_LVL

Clear velocity less than interrupt.

SL_QEI_POS_CNT_MATCH_INTR_LVL

Clear position count match interrupt.

SL_QEI_VELOCITY_COMP_OVER_INTR_LVL

Clear velocity computation overflow interrupt.

SL_QEI_PARAM_CLEAR_LAST

Last member of the enum for validation purposes.


sl_qei_ctrl_init_config_t#

sl_qei_ctrl_init_config_t

Enumeration for QEI control initialization configuration.

This enumeration specifies the initialization configuration for QEI control.

Enumerator
SL_QEI_UNIDIRECTIONAL_VELOCITY

Enable unidirectional velocity.

SL_QEI_UNIDIRECTIONAL_INDEX

Enable unidirectional index.

SL_QEI_INDEX_COUNT_INIT

Initialize index counter.

SL_QEI_CTRL_INIT_LAST

Last member of the enum for validation purposes.


sl_qei_control_config_t#

sl_qei_control_config_t

Enumeration for QEI control configuration.

This enumeration specifies the control configuration parameters for QEI.

Enumerator
SL_QEI_DIGITAL_FILTER_BYPASS

Bypass digital filter.

SL_QEI_INDEX_COUNT_RESET

Index counter reset.

SL_QEI_IDX_CNT_RST_EN

Enable index counter reset.

SL_QEI_POS_CNT_16_BIT_MDE

Set position counter to 16-bit mode.

SL_QEI_POS_CNT_DIR_FRM_REG

Set position counter direction from register.

SL_QEI_POS_CNT_DIR_CTRL

Control direction of the position counter.

SL_QEI_POS_CNT_RST

Reset position counter.

SL_QEI_POS_CNT_RST_WITH_IDX_EN

Reset position counter with index enable.

SL_QEI_START_VELOCITY_CNTR

Start velocity counter.

SL_QEI_STOP_IN_IDLE

Stop in idle state.

SL_QEI_SWAP_PHASE_AB_B

Swap phases A and B.

SL_QEI_INTERFACE_TIMER_MODE

Set to timer mode.

SL_QEI_CONTROL_CONFIG_LAST

Last member of the enum for validation purposes.


sl_qei_clk_div_t#

sl_qei_clk_div_t

Enumeration for QEI digital filter clock divide select bits.

This enumeration specifies the control configuration digital filter clock divide parameter for QEI.

Enumerator
SL_QEI_CLK_DIV_1

1:1 Clock divide for Index, position A & B

SL_QEI_CLK_DIV_2

1:2 Clock divide for Index, position A & B

SL_QEI_CLK_DIV_4

1:4 Clock divide for Index, position A & B

SL_QEI_CLK_DIV_8

1:8 Clock divide for Index, position A & B

SL_QEI_CLK_DIV_16

1:16 Clock divide for Index, position A & B

SL_QEI_CLK_DIV_32

1:32 Clock divide for Index, position A & B

SL_QEI_CLK_DIV_64

1:64 Clock divide for Index, position A & B

SL_QEI_CLK_DIV_128

1:128 Clock divide for Index, position A & B

SL_QEI_CLK_DIV_256

1:256 Clock divide for Index, position A & B

SL_QEI_CLK_DIV_512

1:512 Clock divide for Index, position A & B

SL_QEI_CLK_DIV_1024

1:1024 Clock divide for Index, position A & B

SL_QEI_CLK_DIV_LAST

Last member of the enum for validation purposes.


Typedef Documentation#

sl_qei_callback_t#

typedef void(* sl_qei_callback_t) (void *callback_flag) )(void *callback_flag)

Callback function type for QEI events.


Function Documentation#

sl_si91x_qei_init#

sl_status_t sl_si91x_qei_init (sl_qei_init_t * qei_init)

Initialize the QEI module.

Parameters
TypeDirectionArgument NameDescription
sl_qei_init_t *[in]qei_init

Pointer to the structure of type sl_qei_init_t.

This function initializes the QEI module, setting it up for operation. It should be called before using any other QEI functions.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_deinit#

void sl_si91x_qei_deinit (void )

De-initialize the QEI module.

Parameters
TypeDirectionArgument NameDescription
voidN/A
  • Pre-conditions:

    • sl_si91x_qei_init

      This function cleans up and deinitializes the QEI module, ensuring that all resources are released and the module is no longer active.


sl_si91x_qei_set_position_counter#

sl_status_t sl_si91x_qei_set_position_counter (uint32_t pos_cnt_value)

Set the position counter value.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]pos_cnt_value

Position counter value to set.

This function sets the value of the position counter. The position counter is used to track the current position in applications such as rotary encoders.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_start_velocity#

sl_status_t sl_si91x_qei_start_velocity (uint32_t period)

Start the velocity counter.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]period

Delta time value to set. This timing information is essential for calculating the velocity of a rotating shaft or moving part by determining how quickly the position changes over a specified period.

This function starts the velocity counter. This is required for managing when velocity calculations should take place.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_get_position_counter#

__STATIC_INLINE uint32_t sl_si91x_qei_get_position_counter (void )

Get the current position counter value.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function retrieves the current value of the position counter, which reflects the position state of the QEI module.

Returns

  • Returns the current position counter value.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_set_encoding_mode#

sl_status_t sl_si91x_qei_set_encoding_mode (sl_qei_encoding_mode_t mode)

Set the encoding mode for the QEI.

Parameters
TypeDirectionArgument NameDescription
sl_qei_encoding_mode_t[in]mode

Encoding mode to set of type sl_qei_encoding_mode_t.

This function configures the encoding mode of the Quadrature Encoder Interface (QEI). Different encoding modes can impact how position and direction are computed.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_get_encoding_mode#

__STATIC_INLINE sl_qei_encoding_mode_t sl_si91x_qei_get_encoding_mode (void )

Get the current encoding mode.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function retrieves the currently configured encoding mode for the QEI. This is useful for understanding how the position and direction are being interpreted.

Returns

  • Returns the current encoding mode.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_set_pos_direction#

sl_status_t sl_si91x_qei_set_pos_direction (sl_qei_direction_t direction)

Set the direction for the QEI.

Parameters
TypeDirectionArgument NameDescription
sl_qei_direction_t[in]direction

Direction to set of type sl_qei_direction_t.

This function sets the direction of the QEI. This is critical for applications where direction affects how the position is interpreted (e.g., clockwise vs. counterclockwise).

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_get_direction#

__STATIC_INLINE sl_qei_direction_t sl_si91x_qei_get_direction (void )

Get the current direction of the QEI.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function retrieves the current direction setting of the QEI, indicating whether the encoder is configured to interpret movement as forward or backward.

Returns

  • Returns the current direction.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_set_index_counter#

sl_status_t sl_si91x_qei_set_index_counter (uint32_t index_count)

Set the index counter value.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]index_count

Index counter value to set.

This function sets the index counter value, which can be used in applications that require indexing or referencing specific positions.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_get_index_counter#

__STATIC_INLINE uint32_t sl_si91x_qei_get_index_counter (void )

Get the current index counter value.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function retrieves the current index counter value, which can be useful for tracking indexed positions or for synchronization purposes.

Returns

  • Returns the current index counter value.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_configure_delta_time_frequency#

sl_status_t sl_si91x_qei_configure_delta_time_frequency (uint32_t freq, uint32_t period)

Configure the delta time frequency for velocity calculation.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]freq

Frequency for delta time.

uint32_t[in]period

Period for delta time.

This function sets up the delta time frequency and period to be used in velocity calculations. Proper configuration ensures accurate velocity readings.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_set_delta_time#

sl_status_t sl_si91x_qei_set_delta_time (uint32_t delta_time)

Set the delta time for velocity calculation.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]delta_time

Delta time to set.

This function sets the delta time value, which is critical for calculating velocity based on the position changes over time.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_get_delta_time#

__STATIC_INLINE uint32_t sl_si91x_qei_get_delta_time (void )

Get the current delta time.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function retrieves the current delta time value being used for velocity calculations, providing insight into the timing configuration.

Returns

  • Returns the current delta time.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_stop_velocity#

__STATIC_INLINE void sl_si91x_qei_stop_velocity (void )

Configure the stop state for the velocity counter.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function stops the velocity counter.


sl_si91x_qei_get_velocity#

__STATIC_INLINE uint32_t sl_si91x_qei_get_velocity (void )

Get the current velocity value.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function retrieves the current calculated velocity, which can be used in applications requiring real-time speed monitoring.

Returns

  • Returns the current velocity.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_set_position_match#

sl_status_t sl_si91x_qei_set_position_match (uint32_t pos_match)

Set the position match value.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]pos_match

Position match value to set.

This function sets a specific position match value. The QEI can generate interrupts or events when this position is reached.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_get_position_match#

__STATIC_INLINE uint32_t sl_si91x_qei_get_position_match (void )

Get the current position match value.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function retrieves the currently set position match value, which helps in understanding the QEI's tracking and event generation capabilities.

Returns

  • Returns the current position match value.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_set_velocity_value_to_compare#

sl_status_t sl_si91x_qei_set_velocity_value_to_compare (uint32_t velocity_value)

Set a value for velocity comparison.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]velocity_value

Velocity value to compare against.

This function sets a threshold velocity value, which can be used for comparing against the current velocity to trigger events or actions.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_set_index_maximum_counter#

sl_status_t sl_si91x_qei_set_index_maximum_counter (uint32_t max_index)

Set the maximum value for the index counter.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]max_index

Maximum index counter value to set.

This function sets the maximum allowable value for the index counter, which can prevent overflow and ensure proper operation.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_get_index_maximum_counter#

__STATIC_INLINE uint32_t sl_si91x_qei_get_index_maximum_counter (void )

Get the current maximum value for the index counter.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function retrieves the current maximum index counter value, which helps in validating the index counter's limits and configuration.

Returns

  • Returns current maximum index counter value.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_get_interrupt_status#

__STATIC_INLINE uint32_t sl_si91x_qei_get_interrupt_status (void )

Get the current interrupt status.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function retrieves the status of the interrupts related to the QEI module, providing insights into any triggered conditions or events.

Returns

  • Returns the current interrupt status.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_swap_a_b#

sl_status_t sl_si91x_qei_swap_a_b (sl_qei_swap_ab_t swap_select)

Swap phases A and B for the QEI.

Parameters
TypeDirectionArgument NameDescription
sl_qei_swap_ab_t[in]swap_select

Selection for swapping phases of type sl_qei_swap_ab_t

This function allows swapping the A and B phases of the encoder signals. This can be useful for correcting phase issues without hardware changes.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_configure_timer_mode#

sl_status_t sl_si91x_qei_configure_timer_mode (sl_qei_timer_mode_t timer_mode)

Configure the QEI to operate in timer mode.

Parameters
TypeDirectionArgument NameDescription
sl_qei_timer_mode_t[in]timer_mode

Timer mode to set of type sl_qei_timer_mode_t

This function sets the QEI to operate in timer mode, allowing for more precise timing and position tracking applications.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_clear_interrupt#

sl_status_t sl_si91x_qei_clear_interrupt (uint32_t int_mask)

Clear the interrupt set.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]int_mask

Masked interrupt to clear

This function clears interrupts in the QEI module.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_get_interrupt_clear#

__STATIC_INLINE uint32_t sl_si91x_qei_get_interrupt_clear (void )

Get the current interrupt clear settings.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function retrieves the current settings for clearing interrupts in the QEI module, useful for managing event handling.

Returns

  • Returns the current interrupt clear settings.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_get_status#

__STATIC_INLINE uint32_t sl_si91x_qei_get_status (void )

Get the status of the QEI module.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function retrieves the operational status of the QEI module, which can be useful for diagnostics and monitoring its state.

Returns

  • Returns the current module status. This will read direct value from position signal geneartor, position counter direction, counter error status flag.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_set_module_frequency#

sl_status_t sl_si91x_qei_set_module_frequency (uint32_t frequency)

Set the frequency for the QEI module.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]frequency

Frequency value to set.

This function sets the operational frequency for the QEI module. The frequency affects the responsiveness and timing accuracy of the module.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_get_module_frequency#

__STATIC_INLINE uint32_t sl_si91x_qei_get_module_frequency (void )

Get the current frequency of the QEI module.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function retrieves the current operational frequency for the QEI module, which can help in performance tuning and analysis.

@return Returns the current frequency value.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_set_digital_filter_clock_division#

sl_status_t sl_si91x_qei_set_digital_filter_clock_division (sl_qei_clk_div_t clock_division)

Set the digital filter clock division.

Parameters
TypeDirectionArgument NameDescription
sl_qei_clk_div_t[in]clock_division

Clock division value to set sl_qei_clk_div_t

This function sets the clock division factor for the digital filter in the QEI module, which can help in reducing noise and improving signal integrity.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_get_digital_filter_clock_division#

__STATIC_INLINE sl_qei_clk_div_t sl_si91x_qei_get_digital_filter_clock_division (void )

Get the current digital filter clock division.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function retrieves the current clock division value for the digital filter in the QEI module, useful for validating filter settings.

@return current clock division value.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_register_callback#

sl_status_t sl_si91x_qei_register_callback (sl_qei_callback_t callback, void * callback_flag_value, sl_qei_intr_unmask_t * intr_flags)

Register a callback function for QEI events.

Parameters
TypeDirectionArgument NameDescription
sl_qei_callback_t[in]callback

Callback function to register of type sl_qei_callback_t

void *[in]callback_flag_value

Pointer to value passed to the callback.

sl_qei_intr_unmask_t *[in]intr_flags

Pointer to interrupt unmask settings of type sl_qei_intr_unmask_t

This function allows users to register a callback function that will be called on specific QEI events. This is essential for responsive applications that need to react to state changes.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer.

    • SL_STATUS_BUSY (0x0004) - Busy

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_unregister_callback#

sl_status_t sl_si91x_qei_unregister_callback (sl_qei_intr_mask_t * intr_mask)

Unregister a callback function for QEI events.

Parameters
TypeDirectionArgument NameDescription
sl_qei_intr_mask_t *[in]intr_mask

Pointer to interrupt mask settings of type sl_qei_intr_mask_t

This function removes a previously registered callback function, stopping it from being called on QEI events.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_set_maximum_position_counter#

sl_status_t sl_si91x_qei_set_maximum_position_counter (uint32_t max_pos_cnt)

Set the maximum position counter value.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]max_pos_cnt

Maximum position counter value to set.

This function sets a maximum value for the position counter, helping to prevent overflow and ensuring reliable operation of the QEI in applications. Position match value to compare the position counter. When it is matched with position counter, interrupt is raised.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_get_maximum_position_counter#

__STATIC_INLINE uint32_t sl_si91x_qei_get_maximum_position_counter (void )

Get the current maximum position counter value.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function retrieves the maximum position counter value that has been set, which can be useful for validating limits and configurations.

@return Returns the current maximum position counter value.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_set_configuration#

sl_status_t sl_si91x_qei_set_configuration (sl_qei_control_t state, sl_qei_config_t * config)

Set configuration parameters for the QEI module.

Parameters
TypeDirectionArgument NameDescription
sl_qei_control_t[in]state

State to reset/set module configurations of type sl_qei_control_t.

sl_qei_config_t *[in]config

Pointer to configuration structure of type sl_qei_config_t.

This function applies specific configuration parameters to the QEI module, allowing for customized operation based on the needs of the application.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

    • SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_get_configuration#

sl_status_t sl_si91x_qei_get_configuration (sl_qei_control_t state, sl_qei_config_t * config)

Get configuration parameters for the QEI module.

Parameters
TypeDirectionArgument NameDescription
sl_qei_control_t[in]state

Get module configurations of type sl_qei_control_t.

sl_qei_config_t *[out]config

Pointer to store configuration parameters sl_qei_config_t

This function retrieves the current configuration parameters of the QEI module, enabling verification of settings and operational parameters.

Returns

  • sl_status_t Status code indicating the result:

    • SL_STATUS_OK (0x0000) - Success.

    • SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument.

    • SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer.

For more information on status codes, see SL STATUS DOCUMENTATION.


sl_si91x_qei_get_version#

sl_qei_version_t sl_si91x_qei_get_version (void )

To get the API version of the QEI module.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This API retrieves the version information of the QEI module, which includes the release, SQA, and DEV version numbers.

Returns