Subsystem for configuring motor type and basic settings.
More...
#include <TMC9660.hpp>
Subsystem for configuring motor type and basic settings.
◆ MotorConfig()
TMC9660::MotorConfig::MotorConfig |
( |
TMC9660 & |
parent | ) |
|
|
inlineexplicitprivatenoexcept |
◆ setCommutationMode()
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
-
mode | A 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()
Set the motor direction inversion.
This configures the MOTOR_DIRECTION parameter which inverts the meaning of "forward" direction for the motor.
- Parameters
-
direction | MotorDirection (FORWARD or REVERSE). |
- Returns
- true if successfully set.
◆ setIdleMotorPWMBehavior()
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
-
pwmOffWhenIdle | True → 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
- Do you need the shaft locked at idle? → Yes: PWM on → No: Continue
- Is battery life, idle power, or heat a concern? → Yes: PWM off
- 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
-
milliamps | Maximum 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
-
milliamps | Maximum 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
-
limit | Output 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
-
frequencyHz | PWM frequency in Hertz (allowed range 10kHz to 100kHz). |
- Returns
- true if set successfully, false if an error occurred.
◆ setPWMSwitchingScheme()
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
-
scheme | PWM 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()
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
-
type | MotorType (DC, BLDC/PMSM, STEPPER). |
polePairs | For 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.
◆ TMC9660
◆ driver
TMC9660& TMC9660::MotorConfig::driver |
|
private |
The documentation for this struct was generated from the following files: