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 high-impedance when commutation is disabled.
- Parameters
-
| pwmOffWhenIdle | True: high-Z/disconnected phases, False: all phases driven equally |
- Returns
- true if the parameter was set successfully.
- Note
- Selection guide by motor type: | Motor type | Typical goal when idle | Best-fit setting | Why it's usually preferred | | ---------— | ---------------------------— | -----------------— | -----------------------------------------— | | Stepper | Hold a fixed shaft position | PWM on | • Energizing both windings gives full static | | | (avoid back-driving) | (all coils | torque | | | | energized) | • Prevents the load or gravity from shifting | | | | | the rotor | | | | | • Draws continuous current, heating the | | | | | motor and wasting power—turn it off if you | | | | | don't need holding torque | | ---------— | ---------------------------— | -----------------— | -----------------------------------------— | | BLDC | Usually want the rotor to | PWM off | • With the bridge inactive the stator | | **(3-phase)**| coast freely or be gently | (high-Z) | doesn't pull current, avoiding battery | | | braked by external friction | | drain and heating | | | | | • If you need static holding/braking torque | | | | | (rare for sensorless BLDC), keep PWM on | | | | | or switch to active braking instead | | ---------— | ---------------------------— | -----------------— | -----------------------------------------— | | Brushed | Let the armature coast; no | PWM off | • Disconnecting the H-bridge removes any | | DC | holding torque exists anyway | (high-Z) | quiescent current | | | | | • Keeping PWM on shorts the terminals | | | | | (dynamic braking) and stops the shaft | | | | | quickly but wastes energy and can cause | | | | | regen currents—use only if you need that | | | | | fast passive brake |
There isn't a single "best" choice that fits every motor type or application—you're really deciding between:
- High-Z (PWM off →
PWM_OFF_WHEN_MOTOR_IDLE) All phases are tri-stated, so the motor is electrically disconnected.
- All-phases driven (PWM on →
PWM_ON_WHEN_MOTOR_IDLE) Every phase is held at the same potential, keeping the bridge active.
Quick decision tree
- Do you need the shaft locked in place at idle? Yes → PWM on. No → continue.
- Is extra heat, quiescent current, or battery life a concern? Yes → PWM off is safer.
- Do you actually want "freewheel" coasting? Yes → PWM off (high-Z). No, I want dynamic braking → leave PWM on or enable a dedicated brake parameter/mode.
Rule of thumb
- Steppers: keep coils powered only if you genuinely need holding torque; otherwise cut them to save power and heat.
- BLDC & brushed DC: default to PWM off; only energize at idle if you're deliberately braking or holding.
So, "most ideal" depends entirely on your idle behavior requirements: holding torque = ON, low power coast = 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: