HF-TMC9660 Driver
Hardware Agnostic C++ Driver for the TMC9660
Loading...
Searching...
No Matches
TMC9660::MotorConfig Struct Reference

Subsystem for configuring motor type and basic settings. More...

#include <TMC9660.hpp>

Collaboration diagram for TMC9660::MotorConfig:

Public Member Functions

bool setType (tmc9660::tmcl::MotorType type, uint8_t polePairs=1) noexcept
 Configure the motor type (DC, BLDC, or stepper) and basic motor settings.
 
bool setDirection (tmc9660::tmcl::MotorDirection direction) noexcept
 Set the motor direction inversion.
 
bool setPWMFrequency (uint32_t frequencyHz) noexcept
 Set the PWM frequency for the motor driver.
 
bool setCommutationMode (tmc9660::tmcl::CommutationMode mode) noexcept
 Configure the commutation mode for the motor.
 
bool setOutputVoltageLimit (uint16_t limit) noexcept
 Set the output voltage limit for the FOC controller.
 
bool setMaxTorqueCurrent (uint16_t milliamps) noexcept
 Set the maximum allowed motor current (torque limit).
 
bool setMaxFluxCurrent (uint16_t milliamps) noexcept
 Set the maximum allowed flux current for BLDC/stepper motors.
 
bool setPWMSwitchingScheme (tmc9660::tmcl::PwmSwitchingScheme scheme) noexcept
 Set the PWM switching scheme for the motor driver.
 
bool setIdleMotorPWMBehavior (tmc9660::tmcl::IdleMotorPwmBehavior pwmOffWhenIdle=tmc9660::tmcl::IdleMotorPwmBehavior::PWM_OFF_WHEN_MOTOR_IDLE) noexcept
 Configure PWM behavior when the motor is idle (System Off mode).
 

Private Member Functions

 MotorConfig (TMC9660 &parent) noexcept
 

Private Attributes

TMC9660driver
 

Friends

class TMC9660
 

Detailed Description

Subsystem for configuring motor type and basic settings.

Constructor & Destructor Documentation

◆ MotorConfig()

TMC9660::MotorConfig::MotorConfig ( TMC9660 parent)
inlineexplicitprivatenoexcept

Member Function Documentation

◆ setCommutationMode()

bool TMC9660::MotorConfig::setCommutationMode ( tmc9660::tmcl::CommutationMode  mode)
noexcept

Configure the commutation mode for the motor.

This sets how the motor is driven: e.g., open-loop or closed-loop FOC with various sensor feedback options. Typically used for BLDC or stepper motors. For DC motors, commutation modes are not applicable except for sensor feedback in velocity/position control modes.

Parameters
modeA CommutationMode value defining the motor control strategy:
  • SYSTEM_OFF: Motor disabled (default state after power-on/reset)
  • SYSTEM_OFF_LOW_SIDE_FETS_ON: All low-side FETs ON (brake)
  • SYSTEM_OFF_HIGH_SIDE_FETS_ON: All high-side FETs ON
  • FOC_OPENLOOP_VOLTAGE: Constant duty cycle (voltage) control without feedback
  • FOC_OPENLOOP_CURRENT: Constant current control without position feedback
  • FOC_ENCODER: Field-oriented control with ABN encoder feedback
  • FOC_HALL: Field-oriented control with Hall sensor feedback
  • FOC_SPI_ENCODER: Field-oriented control with SPI encoder feedback
Returns
true if the mode was applied successfully.
Note
When using SYSTEM_OFF, the behavior is controlled by IDLE_MOTOR_PWM_BEHAVIOR parameter. For open-loop modes, additional parameters must be set (OPENLOOP_VOLTAGE or OPENLOOP_CURRENT). For sensor-based modes, the appropriate sensor must be configured before enabling this mode.

◆ setDirection()

bool TMC9660::MotorConfig::setDirection ( tmc9660::tmcl::MotorDirection  direction)
noexcept

Set the motor direction inversion.

This configures the MOTOR_DIRECTION parameter which inverts the meaning of "forward" direction for the motor.

Parameters
directionMotorDirection (FORWARD or REVERSE).
Returns
true if successfully set.

◆ setIdleMotorPWMBehavior()

bool TMC9660::MotorConfig::setIdleMotorPWMBehavior ( tmc9660::tmcl::IdleMotorPwmBehavior  pwmOffWhenIdle = tmc9660::tmcl::IdleMotorPwmBehavior::PWM_OFF_WHEN_MOTOR_IDLE)
noexcept

Configure PWM behavior when the motor is idle (System Off mode).

Controls whether motor phases are driven or left floating (high-impedance) when commutation is disabled.

Parameters
pwmOffWhenIdleTrue → high-Z / disconnected phases False → all phases driven equally (same PWM output)
Returns
true if the parameter was set successfully.
Note
Motor-type idle mode selection guide:
Motor Type Idle Goal Best Setting Notes
Stepper Hold shaft position PWM on • Energizing both windings
provides full static torque
• Prevents back-driving by load
or gravity
• Always draws current at idle
• Causes heat and power waste—
disable if holding isn't needed
----------— --------------------------— -------------— -------------------------------—
BLDC Coast or passive braking PWM off • With PWM off (high-Z), stator
(3-phase) (high-Z) is electrically disconnected
• No current is drawn from the
battery, reducing heating
• Ideal when you want the rotor
to freely coast or gently stop
• If holding torque is needed
(rare for sensorless BLDC),
enable PWM or use active brake
----------— --------------------------— -------------— -------------------------------—
Brushed Let shaft coast freely PWM off • No static holding torque
DC Motor (high-Z) • Disconnecting H-bridge removes
quiescent current
• PWM on = dynamic braking →
shaft stops quickly
• Wastes power and generates
heat
• Can induce regenerative
currents—use with caution

There is no universal best setting—choose based on your application needs:

PWM_OFF_WHEN_MOTOR_IDLE: All phases set to high-Z. Motor is electrically disconnected. • PWM_ON_WHEN_MOTOR_IDLE: All bridge outputs actively driven to same potential.

Quick Decision Tree

  1. Do you need the shaft locked at idle? → Yes: PWM on → No: Continue
  2. Is battery life, idle power, or heat a concern? → Yes: PWM off
  3. Do you want the rotor to coast freely? → Yes: PWM off (high-Z) → No, you want braking: leave PWM on or use a dedicated brake feature

Rule of Thumb

Steppers: Keep coils energized only when holding torque is required. • BLDC & Brushed DC: Default to PWM off; only energize if braking or holding is needed.

Final guidance: • Holding torque needed → PWM on • Coasting, low idle power → PWM off

◆ setMaxFluxCurrent()

bool TMC9660::MotorConfig::setMaxFluxCurrent ( uint16_t  milliamps)
noexcept

Set the maximum allowed flux current for BLDC/stepper motors.

This sets the MAX_FLUX parameter which limits the flux-producing current component. Important for field-weakening operation and stepper motor control.

Parameters
milliampsMaximum flux current in milliamps.
Returns
true on success, false on error.
Note
This value can be temporarily exceeded marginally due to the operation of the current regulator.

◆ setMaxTorqueCurrent()

bool TMC9660::MotorConfig::setMaxTorqueCurrent ( uint16_t  milliamps)
noexcept

Set the maximum allowed motor current (torque limit).

This sets the MAX_TORQUE parameter which limits the peak current/torque that the controller will deliver to the motor.

Parameters
milliampsMaximum current in milliamps.
Returns
true on success, false on error.
Note
This value can be temporarily exceeded marginally due to the operation of the current regulator.

◆ setOutputVoltageLimit()

bool TMC9660::MotorConfig::setOutputVoltageLimit ( uint16_t  limit)
noexcept

Set the output voltage limit for the FOC controller.

This parameter limits the maximum Uq/ Ud output of the FOC controller (PID output circular limiter).

Parameters
limitOutput voltage limit (0 ... 32767, default 8000).
Returns
true if the parameter was set successfully.

◆ setPWMFrequency()

bool TMC9660::MotorConfig::setPWMFrequency ( uint32_t  frequencyHz)
noexcept

Set the PWM frequency for the motor driver.

Parameters
frequencyHzPWM frequency in Hertz (allowed range 10kHz to 100kHz).
Returns
true if set successfully, false if an error occurred.

◆ setPWMSwitchingScheme()

bool TMC9660::MotorConfig::setPWMSwitchingScheme ( tmc9660::tmcl::PwmSwitchingScheme  scheme)
noexcept

Set the PWM switching scheme for the motor driver.

This configures how the PWM signals are generated for driving the motor phases. Different schemes offer varying trade-offs between voltage utilization, switching losses, and current measurement windows.

Parameters
schemePWM switching scheme: 0: STANDARD - Standard PWM modulation (86% max voltage for BLDC) 1: SVPWM - Space Vector PWM (100% max voltage for BLDC, balanced load on FETs) 2: FLAT_BOTTOM - Flat bottom PWM (100% max voltage for BLDC, extended current measurement window)
Returns
true if set successfully, false if an error occurred.
Note
For BLDC motors, SVPWM and Flat Bottom schemes allow full voltage utilization. For Stepper/DC motors, only standard and flat bottom modes are available with 100% duty cycle.

◆ setType()

bool TMC9660::MotorConfig::setType ( tmc9660::tmcl::MotorType  type,
uint8_t  polePairs = 1 
)
noexcept

Configure the motor type (DC, BLDC, or stepper) and basic motor settings.

This sets the MOTOR_TYPE parameter and optionally related parameters like pole pairs for BLDC or microstep settings for steppers. Note that the BLDC option also covers PMSM motors since they use the same three-phase commutation scheme.

Parameters
typeMotorType (DC, BLDC/PMSM, STEPPER).
polePairsFor BLDC motors, number of pole pairs. For stepper or DC, this can be set to 1.
Returns
true if the motor type was set successfully, false if communication or device error.

Friends And Related Symbol Documentation

◆ TMC9660

friend class TMC9660
friend

Member Data Documentation

◆ driver

TMC9660& TMC9660::MotorConfig::driver
private

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