HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
tmc51x0::EncoderConfig Struct Reference

Encoder configuration structure. More...

#include <tmc51x0_types.hpp>

Public Member Functions

 EncoderConfig ()=default
 Default constructor.
 

Public Attributes

ReferenceSwitchActiveLevel n_channel_active
 
bool require_a_high {false}
 
bool require_b_high {false}
 
bool ignore_ab_polarity {true}
 
EncoderNSensitivity n_sensitivity
 N channel event sensitivity (edge/level detection)
 
EncoderClearMode clear_mode {EncoderClearMode::DISABLED}
 Clear mode for encoder counter on N events.
 
bool clear_enc_x_on_event {false}
 
bool latch_xactual_with_enc {false}
 
EncoderPrescalerMode prescaler_mode
 Encoder prescaler divisor mode (enc_sel_decimal)
 
int32_t allowed_deviation_steps
 Allowed encoder deviation in steps.
 
uint16_t pulses_per_rev {0}
 Encoder pulses per revolution.
 
bool invert_direction {false}
 Invert encoder direction.
 

Detailed Description

Encoder configuration structure.

Configuration parameters for encoder interface operation. Uses enum-based API for intuitive configuration similar to ReferenceSwitchConfig.

Note
All fields must be explicitly set. Register values are calculated automatically.
See also
Datasheet section 20: ABN Incremental Encoder Interface

Constructor & Destructor Documentation

◆ EncoderConfig()

tmc51x0::EncoderConfig::EncoderConfig ( )
default

Default constructor.

Initializes with safe defaults:

  • N channel: ACTIVE_HIGH, ACTIVE_LEVEL sensitivity
  • A/B polarity: ignored
  • Clear mode: DISABLED
  • Prescaler: BINARY
  • Allowed deviation: 0 (disabled)
  • Pulses per rev: 0 (not configured)
  • Invert direction: false

Member Data Documentation

◆ allowed_deviation_steps

int32_t tmc51x0::EncoderConfig::allowed_deviation_steps
Initial value:
{
0}

Allowed encoder deviation in steps.

Maximum number of steps deviation between motor position (XACTUAL) and encoder position (X_ENC) before a deviation warning is triggered.

The deviation is automatically converted to microsteps using the current microstep setting. The register value is calculated as: deviation_microsteps = allowed_deviation_steps × current_microsteps

Range: 0 to 1048575 steps (0 = deviation detection disabled)

Note
The actual register value is in microsteps, so the effective range depends on microstep resolution.
Setting to 0 disables deviation detection (no warnings).
Typical values: 1-10 steps for tight control, 10-100 steps for normal operation.
This is automatically configured during Initialize() if set in EncoderConfig. Allowed encoder deviation in steps (0 = disabled, automatically converted to microsteps)

◆ clear_enc_x_on_event

bool tmc51x0::EncoderConfig::clear_enc_x_on_event {false}

Clear encoder counter X_ENC upon N-event (clr_enc_x) true = latch and clear, false = latch only

◆ clear_mode

EncoderClearMode tmc51x0::EncoderConfig::clear_mode {EncoderClearMode::DISABLED}

Clear mode for encoder counter on N events.

◆ ignore_ab_polarity

bool tmc51x0::EncoderConfig::ignore_ab_polarity {true}

Ignore A and B polarity for N channel event (ignore_AB) true = ignore A/B, false = validate A/B polarity

◆ invert_direction

bool tmc51x0::EncoderConfig::invert_direction {false}

Invert encoder direction.

Whether the encoder direction should be inverted relative to motor direction. When true, the encoder counts in the opposite direction from the motor.

Default: false (encoder direction matches motor direction)

Note
This is automatically configured during Initialize() if pulses_per_rev is set. Whether encoder direction is inverted

◆ latch_xactual_with_enc

bool tmc51x0::EncoderConfig::latch_xactual_with_enc {false}

Also latch XACTUAL position together with X_ENC (latch_x_act) true = latch both, false = latch X_ENC only

◆ n_channel_active

ReferenceSwitchActiveLevel tmc51x0::EncoderConfig::n_channel_active
Initial value:
{
ReferenceSwitchActiveLevel::
ACTIVE_LOW}

N channel active level (determines pol_N) ACTIVE_LOW = low active (pol_N=0), ACTIVE_HIGH = high active (pol_N=1)

◆ n_sensitivity

EncoderNSensitivity tmc51x0::EncoderConfig::n_sensitivity
Initial value:

N channel event sensitivity (edge/level detection)

◆ prescaler_mode

EncoderPrescalerMode tmc51x0::EncoderConfig::prescaler_mode
Initial value:

Encoder prescaler divisor mode (enc_sel_decimal)

◆ pulses_per_rev

uint16_t tmc51x0::EncoderConfig::pulses_per_rev {0}

Encoder pulses per revolution.

Number of encoder pulses per revolution (PPR). Used to calculate encoder resolution and set up the ENC_CONST register for position tracking.

Range: 0 to 65535 (0 = encoder resolution not configured)

Note
This is automatically configured during Initialize() if set.
For quadrature encoders, this is typically the PPR value (e.g., 4096 for AS5047U).
The driver calculates ENC_CONST based on motor steps, microsteps, and this value. Encoder pulses per revolution (0 = not configured)

◆ require_a_high

bool tmc51x0::EncoderConfig::require_a_high {false}

Require A channel HIGH for N event validation (pol_A) true = A must be HIGH, false = A must be LOW

◆ require_b_high

bool tmc51x0::EncoderConfig::require_b_high {false}

Require B channel HIGH for N event validation (pol_B) true = B must be HIGH, false = B must be LOW


The documentation for this struct was generated from the following file: