|
HF-TMC9660 Driver 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC9660
|
Motor configuration and control subsystem. More...
#include <tmc9660.hpp>
Classes | |
| struct | MotorProfile |
| Configuration structure for auto-configuring motor parameters. More... | |
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 frequency_hz) 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 | getOutputVoltageLimit (uint16_t &limit) noexcept |
| Read 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). | |
| bool | configureAuto (const MotorProfile &profile) noexcept |
| Auto-configure motor parameters based on high-level motor characteristics. | |
Private Member Functions | |
| MotorConfig (TMC9660 &parent) noexcept | |
Private Attributes | |
| TMC9660 & | driver |
Friends | |
| class | TMC9660 |
Motor configuration and control subsystem.
Provides high-level methods for configuring motor parameters such as motor type, pole pairs, PWM frequency, commutation mode, and control limits. This subsystem abstracts the low-level TMCL parameter access into intuitive, easy-to-use methods.
|
inlineexplicitprivatenoexcept |
|
noexcept |
Auto-configure motor parameters based on high-level motor characteristics.
This method automatically configures motor-specific parameters including:
| profile | Motor configuration profile (see MotorProfile) |
|
noexcept |
Read the output voltage limit for the FOC controller.
| [out] | limit | Current output voltage limit value. |
|
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.
| mode | A CommutationMode value defining the motor control strategy:
|
|
noexcept |
Set the motor direction inversion.
This configures the MOTOR_DIRECTION parameter which inverts the meaning of "forward" direction for the motor.
| direction | MotorDirection (FORWARD or REVERSE). |
|
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.
| pwm_off_when_idle | True → high-Z / disconnected phases False → all phases driven equally (same PWM output) |
| 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 freely (no braking) | PWM off | • With PWM off (high-Z), stator |
| (3-phase) | (high-Z) | phases are floating—not | |
| connected to power or ground | |||
| • No current flows from battery, | |||
| eliminating idle power & heat | |||
| • Rotor coasts with only | |||
| mechanical friction | |||
| • No braking torque (this is | |||
| pure coasting, not braking) | |||
| • For passive braking (eddy- | |||
| current braking), use | |||
| SYSTEM_OFF_LOW_SIDE_FETS_ON | |||
| or SYSTEM_OFF_HIGH_SIDE_FETS_ON | |||
| instead (phases shorted) | |||
| • If holding torque is needed | |||
| (rare for sensorless BLDC), | |||
| enable PWM or use active brake | |||
| ----------— | --------------------------— | -------------— | -------------------------------— |
| Brushed | Coast freely (no braking) | PWM off | • With PWM off (high-Z), H-bridge |
| DC Motor | (high-Z) | terminals float—not connected | |
| • No current flows from battery, | |||
| eliminating idle power & heat | |||
| • Rotor coasts with only | |||
| mechanical friction | |||
| • No braking torque (this is | |||
| pure coasting, not braking) | |||
| • PWM on = short-circuit braking | |||
| (both terminals at same | |||
| voltage) → motor generates | |||
| back-EMF, creating braking | |||
| torque and regenerative | |||
| currents flowing back | |||
| • Regenerative currents can | |||
| charge battery or damage | |||
| system if not handled—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.
• 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
|
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.
| milliamps | Maximum flux current in 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.
| milliamps | Maximum current in milliamps. |
|
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).
| limit | Output voltage limit (0 ... 32767, default 8000). |
|
noexcept |
Set the PWM frequency for the motor driver.
| frequency_hz | PWM frequency in Hertz (allowed range 10kHz to 100kHz). |
|
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.
| 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) |
|
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.
| type | MotorType (DC, BLDC/PMSM, STEPPER). |
| polePairs | For BLDC motors, number of pole pairs. For stepper or DC, this can be set to 1. |
|
private |