|
| bool | setShuntType (tmc9660::tmcl::AdcShuntType shuntType) noexcept |
| | Set the ADC shunt type (Parameter 12: ADC_SHUNT_TYPE).
|
| |
| bool | getShuntType (tmc9660::tmcl::AdcShuntType &shuntType) noexcept |
| | Get the ADC shunt type (Parameter 12: ADC_SHUNT_TYPE).
|
| |
| bool | readRaw (int16_t &adc0, int16_t &adc1, int16_t &adc2, int16_t &adc3) noexcept |
| | Read raw ADC values (Parameters 13-16: ADC_I0_RAW ... ADC_I3_RAW).
|
| |
| bool | setCSAGain (tmc9660::tmcl::CsaGain gain012, tmc9660::tmcl::CsaGain gain3) noexcept |
| | Set current sense amplifier gain (Parameters 17/18: CSA_GAIN_ADC_I0_TO_ADC_I2, CSA_GAIN_ADC_I3).
|
| |
| bool | getCSAGain (tmc9660::tmcl::CsaGain &gain012, tmc9660::tmcl::CsaGain &gain3) noexcept |
| | Get current sense amplifier gain (Parameters 17/18: CSA_GAIN_ADC_I0_TO_ADC_I2, CSA_GAIN_ADC_I3).
|
| |
| bool | setCSAFilter (tmc9660::tmcl::CsaFilter filter012, tmc9660::tmcl::CsaFilter filter3) noexcept |
| | Set current sense amplifier filter (Parameters 19/20: CSA_FILTER_ADC_I0_TO_ADC_I2, CSA_FILTER_ADC_I3).
|
| |
| bool | getCSAFilter (tmc9660::tmcl::CsaFilter &filter012, tmc9660::tmcl::CsaFilter &filter3) noexcept |
| | Get current sense amplifier filter (Parameters 19/20: CSA_FILTER_ADC_I0_TO_ADC_I2, CSA_FILTER_ADC_I3).
|
| |
| bool | setScalingFactor (uint16_t scaling_factor) noexcept |
| | Set current scaling factor (Parameter 21: CURRENT_SCALING_FACTOR).
|
| |
| bool | getScalingFactor (uint16_t &scaling_factor) noexcept |
| | Get current scaling factor (Parameter 21: CURRENT_SCALING_FACTOR).
|
| |
| bool | setPhaseAdcMapping (tmc9660::tmcl::AdcMapping ux1, tmc9660::tmcl::AdcMapping vx2, tmc9660::tmcl::AdcMapping wy1, tmc9660::tmcl::AdcMapping y2) noexcept |
| | Set ADC mapping for each phase (Parameters 22-25: PHASE_UX1_ADC_MAPPING ... PHASE_Y2_ADC_MAPPING).
|
| |
| bool | getPhaseAdcMapping (tmc9660::tmcl::AdcMapping &ux1, tmc9660::tmcl::AdcMapping &vx2, tmc9660::tmcl::AdcMapping &wy1, tmc9660::tmcl::AdcMapping &y2) noexcept |
| | Get ADC mapping for each phase (Parameters 22-25: PHASE_UX1_ADC_MAPPING ... PHASE_Y2_ADC_MAPPING).
|
| |
| bool | setScalingFactors (uint16_t scale0, uint16_t scale1, uint16_t scale2, uint16_t scale3) noexcept |
| | Set individual ADC scaling factors (Parameters 26-29: ADC_I0_SCALE ... ADC_I3_SCALE).
|
| |
| bool | getScalingFactors (uint16_t &scale0, uint16_t &scale1, uint16_t &scale2, uint16_t &scale3) noexcept |
| | Get individual ADC scaling factors (Parameters 26-29: ADC_I0_SCALE ... ADC_I3_SCALE).
|
| |
| bool | setInversion (tmc9660::tmcl::AdcInversion inv0, tmc9660::tmcl::AdcInversion inv1, tmc9660::tmcl::AdcInversion inv2, tmc9660::tmcl::AdcInversion inv3) noexcept |
| | Set ADC inversion (Parameters 30-33: ADC_I0_INVERTED ... ADC_I3_INVERTED).
|
| |
| bool | getInversion (tmc9660::tmcl::AdcInversion &inv0, tmc9660::tmcl::AdcInversion &inv1, tmc9660::tmcl::AdcInversion &inv2, tmc9660::tmcl::AdcInversion &inv3) noexcept |
| | Get ADC inversion (Parameters 30-33: ADC_I0_INVERTED ... ADC_I3_INVERTED).
|
| |
| bool | setOffsets (int16_t offset0, int16_t offset1, int16_t offset2, int16_t offset3) noexcept |
| | Set ADC offset (Parameters 34-37: ADC_I0_OFFSET ... ADC_I3_OFFSET).
|
| |
| bool | getOffsets (int16_t &offset0, int16_t &offset1, int16_t &offset2, int16_t &offset3) noexcept |
| | Get ADC offset (Parameters 34-37: ADC_I0_OFFSET ... ADC_I3_OFFSET).
|
| |
| bool | readScaledAndOffset (int16_t &adc0, int16_t &adc1, int16_t &adc2, int16_t &adc3) noexcept |
| | Read scaled and offset-compensated ADC values (Parameters 38-41: ADC_I0 ... ADC_I3).
|
| |
| bool | calibrateOffsets (bool waitForCompletion=false, uint32_t timeoutMs=1000) noexcept |
| | Calibrate the ADC offsets for current measurement.
|
| |
| bool | getCalibrationStatus (bool &is_calibrated) noexcept |
| | Check if ADC offset calibration has been completed.
|
| |
| bool | configureAuto (const AutoConfig &config) noexcept |
| | Auto-configure current sensing based on shunt resistance and expected current.
|
| |
Subsystem for configuring ADC-based current measurement.
Auto-configure current sensing based on shunt resistance and expected current.
This method automatically selects the optimal CSA gain and calculates the current scaling factor to enable direct m_a units for torque/flux commands.
The function:
- Selects the smallest CSA gain that provides ≥1.5x headroom above expected peak current
- Calculates CURRENT_SCALING_FACTOR using the formula from the datasheet:
- Peak: Factor = 39.06 / (G_CSA * R_shunt_Ohm)
- RMS: Factor = 27.62 / (G_CSA * R_shunt_Ohm)
- Configures shunt type, CSA gain, filter, scaling factor, and ADC inversion
- Optionally calculates per-ADC scaling factors if actual shunt resistances are provided
After calling this, torque/flux commands (MAX_TORQUE, TARGET_TORQUE, etc.) can be specified directly in m_a. For example, MAX_TORQUE = 3000 means 3.0 A.
Two-Level Scaling System
The TMC9660 uses a two-level scaling system:
- ADC_Ix_SCALE (per-phase trim): Compensates for physical mismatch in shunt resistors and CSA amplifier tolerances. Default: 1024 (1.000×). If actual shunt resistances are provided, this is automatically calculated to equalize all phases.
- CURRENT_SCALING_FACTOR (global unit conversion): Converts normalized ADC currents to m_a units for the torque/flux control system. This is automatically calculated based on nominal shunt resistance and CSA gain.
Signal flow:
SPI status codes as per TMC9660 Parameter Mode.
Definition tmc9660_comm_interface.hpp:514
Per-ADC Shunt Resistance Compensation
If you have measured the actual shunt resistance for each ADC channel, you can provide them to automatically calculate ADC_Ix_SCALE. The formula used is:
This ensures all phases report the same current for the same real current, compensating for shunt resistor tolerances.
- Parameters
-
| config | Configuration structure containing all current sensing parameters. See AutoConfig for details on all available options. |
- Returns
- true if configuration was successful (and calibration succeeded if autoCalibrate=true)
- Note
- ADC inversion defaults are set according to Table 24 for the specified motor type, but can be overridden via config.adc0_inverted, etc. Verify in open-loop voltage mode and adjust if phases are 180° out of phase.
-
ADC offset calibration is required before using current sensing. If config.autoCalibrate is false, you must call calibrateOffsets() manually. The motor must be stationary and commutation must be off (SYSTEM_OFF) during calibration.
config.shuntResistance_mOhm = 3.0;
config.expectedPeakCurrent_A = 3.0;
config.motorType = tmc9660::tmcl::MotorType::BLDC_MOTOR;
config.actualShuntR_adc0_mOhm = 2.97;
config.actualShuntR_adc1_mOhm = 3.01;
config.actualShuntR_adc2_mOhm = 3.02;
config.phaseU_adcMapping = tmc9660::tmcl::AdcMapping::ADC_I0;
config.phaseV_adcMapping = tmc9660::tmcl::AdcMapping::ADC_I1;
config.phaseW_adcMapping = tmc9660::tmcl::AdcMapping::ADC_I2;
config.adc0_inverted = tmc9660::tmcl::AdcInversion::INVERTED;
config.adc1_inverted = tmc9660::tmcl::AdcInversion::INVERTED;
config.adc2_inverted = tmc9660::tmcl::AdcInversion::INVERTED;
driver.motorConfig.setMaxTorqueCurrent(3000);
driver.focControl.setTargetTorque(2500);
Configuration structure for auto-configuring current sensing.
Definition tmc9660.hpp:888
TMC9660 & driver
Definition tmc9660.hpp:1038