|
HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
|
Comprehensive internal ramp test suite for TMC51x0 (single motor) More...
#include "tmc51x0.hpp"#include "features/tmc51x0_units.hpp"#include "test_config/esp32_tmc51x0_bus.hpp"#include "test_config/esp32_tmc51x0_test_config.hpp"#include "test_config/TestFramework.h"#include "driver/gpio.h"#include <memory>Classes | |
| struct | TestDriverHandle |
| Test driver handle containing SPI interface and driver instance. More... | |
Typedefs | |
| using | Motor = tmc51x0_test_config::MotorConfig_17HS4401S |
| using | Test = tmc51x0_test_config::TestConfig_17HS4401S |
Functions | |
| bool | test_driver_initialization () noexcept |
| Test driver initialization and basic setup verification. | |
| bool | test_register_read_write () noexcept |
| Test register read/write operations. | |
| bool | test_motor_parameter_settings () noexcept |
| Test motor parameter configuration and settings. | |
| bool | test_ramp_parameter_settings () noexcept |
| Test ramp parameter configuration (speed, acceleration, etc.). | |
| bool | test_global_configuration () noexcept |
| Test global configuration settings (GCONF register). | |
| bool | test_enable_disable () noexcept |
| Test motor enable/disable functionality. | |
| bool | test_current_control () noexcept |
| Test motor current control (IRUN/IHOLD settings). | |
| bool | test_chopper_configuration () noexcept |
| Test chopper configuration (SpreadCycle mode). | |
| bool | test_stealthchop_configuration () noexcept |
| Test StealthChop configuration and automatic tuning. | |
| bool | test_mode_change_speeds () noexcept |
| Test mode change speed thresholds (PWM_THRS, COOL_THRS, HIGH_THRS). | |
| bool | test_global_scaler () noexcept |
| Test global scaler configuration. | |
| bool | test_freewheeling_mode () noexcept |
| Test freewheeling mode configuration. | |
| bool | test_coolstep_configuration () noexcept |
| Test CoolStep configuration and operation. | |
| bool | test_dcstep_configuration () noexcept |
| Test DCStep configuration and operation. | |
| bool | test_microstep_lookup_table () noexcept |
| Test microstep lookup table configuration. | |
| bool | test_motor_setup_from_spec () noexcept |
| Test motor setup from specifications (automatic configuration). | |
| bool | test_ramp_modes () noexcept |
| Test ramp mode switching (POSITIONING, VELOCITY_POS, VELOCITY_NEG, HOLD). | |
| bool | test_position_control () noexcept |
| Test position control (target position, current position). | |
| bool | test_speed_control () noexcept |
| Test speed control (max speed, acceleration, deceleration). | |
| bool | test_ramp_parameters () noexcept |
| Test ramp parameters (VSTART, VSTOP, first acceleration, etc.). | |
| bool | test_reference_switch_configuration () noexcept |
| Test reference switch configuration and homing. | |
| bool | test_unit_conversions () noexcept |
| Test unit conversion functions (RPM, degrees, millimeters, etc.). | |
| bool | test_driver_status () noexcept |
| Test driver status reading (GSTAT, DRV_STATUS). | |
| bool | test_stallguard () noexcept |
| Test StallGuard2 configuration and reading. | |
| bool | test_lost_steps () noexcept |
| Test lost steps detection and reading. | |
| bool | test_phase_currents () noexcept |
| Test phase current reading (microstep current diagnostics). | |
| bool | test_pwm_scale () noexcept |
| Test PWM scale reading (PWM_AUTO, PWM_SCALE_SUM). | |
| bool | test_microstep_diagnostics () noexcept |
| Test microstep diagnostics (counter, time between microsteps). | |
| bool | test_gpio_pins () noexcept |
| Test GPIO pin reading functionality. | |
| bool | test_factory_otp_config () noexcept |
| Test factory and OTP configuration reading. | |
| bool | test_uart_transmission_count () noexcept |
| Test UART transmission count reading. | |
| bool | test_offset_calibration () noexcept |
| Test offset calibration reading. | |
| bool | test_sensorless_homing () noexcept |
| Test sensorless homing configuration (StallGuard2-based). | |
| bool | test_open_load () noexcept |
| Test open load detection functionality. | |
| bool | test_short_circuit_protection () noexcept |
| Test short circuit protection configuration. | |
| bool | test_overtemperature_protection () noexcept |
| Test overtemperature protection status reading. | |
| bool | test_encoder_configuration () noexcept |
| Test encoder configuration and setup. | |
| bool | test_encoder_resolution () noexcept |
| Test encoder resolution setting. | |
| bool | test_encoder_position_reading () noexcept |
| Test encoder position reading. | |
| bool | test_deviation_detection () noexcept |
| Test encoder deviation detection and warnings. | |
| bool | test_latched_position () noexcept |
| Test latched position reading (index pulse). | |
| uint8_t | CalculateCurrentRegister (uint16_t current_ma, uint16_t global_scaler=0, uint32_t sense_resistor_mohm=0) |
| Helper to calculate current register value (0-31) from mA. | |
| bool | verify_mode_pins (const Esp32SPI &spi, const tmc51x0::TMC51x0< Esp32SPI > &driver, tmc51x0::CommMode expected_comm_mode) noexcept |
| Verify mode pins match expected communication mode. | |
| std::unique_ptr< TestDriverHandle > | create_test_driver (bool enable_ref_switch_stop=false) noexcept |
| Create and initialize a test driver instance. | |
| void | app_main (void) |
Variables | |
| static const char * | TAG = "InternalRamp_Test" |
| static TestResults | g_test_results |
| static constexpr tmc51x0_test_config::TestRigType | SELECTED_TEST_RIG |
| static constexpr uint8_t | TEST_TOFF = Motor::TOFF |
| static constexpr tmc51x0::MicrostepResolution | TEST_MRES = Motor::MRES |
| static constexpr float | MICROSTEPS = 256.0f |
| static constexpr float | STEPS_PER_REV = static_cast<float>(Motor::OUTPUT_FULL_STEPS) * MICROSTEPS |
| static constexpr float | LEAD_SCREW_PITCH_MM = 2.0F |
| static constexpr float | TEST_MAX_SPEED_RPM = 60.0f |
| static constexpr float | TEST_ACCELERATION_REV_S2 = 120.0f |
| static constexpr float | TEST_DECELERATION_REV_S2 = 120.0f |
| static constexpr bool | ENABLE_INITIALIZATION_TESTS = true |
| static constexpr bool | ENABLE_REGISTER_ACCESS_TESTS = true |
| static constexpr bool | ENABLE_MOTOR_PARAMETER_TESTS = true |
| static constexpr bool | ENABLE_RAMP_PARAMETER_TESTS = true |
| static constexpr bool | ENABLE_GLOBAL_CONFIG_TESTS = true |
| static constexpr bool | ENABLE_ENABLE_DISABLE_TESTS = true |
| static constexpr bool | ENABLE_CURRENT_CONTROL_TESTS = true |
| static constexpr bool | ENABLE_CHOPPER_TESTS = true |
| static constexpr bool | ENABLE_STEALTHCHOP_TESTS = true |
| static constexpr bool | ENABLE_MODE_CHANGE_SPEED_TESTS = true |
| static constexpr bool | ENABLE_GLOBAL_SCALER_TESTS = true |
| static constexpr bool | ENABLE_FREEWHEELING_TESTS = true |
| static constexpr bool | ENABLE_COOLSTEP_TESTS = true |
| static constexpr bool | ENABLE_DCSTEP_TESTS = true |
| static constexpr bool | ENABLE_LUT_TESTS = true |
| static constexpr bool | ENABLE_MOTOR_SETUP_TESTS = true |
| static constexpr bool | ENABLE_RAMP_MODE_TESTS = true |
| static constexpr bool | ENABLE_POSITION_CONTROL_TESTS = true |
| static constexpr bool | ENABLE_SPEED_CONTROL_TESTS = true |
| static constexpr bool | ENABLE_RAMP_PARAMETER_TESTS_RAMP = true |
| static constexpr bool | ENABLE_REFERENCE_SWITCH_TESTS = true |
| static constexpr bool | ENABLE_UNIT_CONVERSION_TESTS = true |
| static constexpr bool | ENABLE_DRIVER_STATUS_TESTS = true |
| static constexpr bool | ENABLE_STALLGUARD_TESTS = true |
| static constexpr bool | ENABLE_LOST_STEPS_TESTS = true |
| static constexpr bool | ENABLE_PHASE_CURRENT_TESTS = true |
| static constexpr bool | ENABLE_PWM_SCALE_TESTS = true |
| static constexpr bool | ENABLE_MICROSTEP_DIAGNOSTICS_TESTS = true |
| static constexpr bool | ENABLE_GPIO_TESTS = true |
| static constexpr bool | ENABLE_FACTORY_OTP_TESTS = true |
| static constexpr bool | ENABLE_UART_COUNT_TESTS = true |
| static constexpr bool | ENABLE_OFFSET_CALIBRATION_TESTS = true |
| static constexpr bool | ENABLE_SENSORLESS_HOMING_TESTS = true |
| static constexpr bool | ENABLE_OPEN_LOAD_TESTS = true |
| static constexpr bool | ENABLE_SHORT_CIRCUIT_TESTS = true |
| static constexpr bool | ENABLE_OVERTEMPERATURE_TESTS = true |
| static constexpr bool | ENABLE_ENCODER_CONFIG_TESTS = true |
| static constexpr bool | ENABLE_ENCODER_RESOLUTION_TESTS = true |
| static constexpr bool | ENABLE_ENCODER_POSITION_TESTS = true |
| static constexpr bool | ENABLE_DEVIATION_DETECTION_TESTS = true |
| static constexpr bool | ENABLE_LATCHED_POSITION_TESTS = true |
Comprehensive internal ramp test suite for TMC51x0 (single motor)
This file contains comprehensive testing for TMC51x0 driver covering:
Hardware Requirements:
Configuration:
| void app_main | ( | void | ) |
| uint8_t CalculateCurrentRegister | ( | uint16_t | current_ma, |
| uint16_t | global_scaler = 0, | ||
| uint32_t | sense_resistor_mohm = 0 ) |
Helper to calculate current register value (0-31) from mA.
Converts target current in mA to IRUN/IHOLD register value (0-31) using the TMC51x0 current calculation formula: I_RMS = (GLOBAL_SCALER/256) * ((CS+1)/32) * (VFS/RSENSE) * (1/√2)
Reversed: CS = (I_RMS * 256 * 32) / (GLOBAL_SCALER * (VFS/RSENSE) * (1/√2)) - 1
NOTE: This is a TEST HELPER function, not part of the TMC51x0 driver API. The driver's SetCurrent() method takes register values (0-31) directly. The driver's SetupMotorFromSpec() handles mA-to-register conversion automatically during initialization, but tests need fine-grained control over specific mA values, hence this helper function.
| current_ma | Target current in mA |
| global_scaler | Global scaler value (32-256). If 0, uses 256 (full scale) |
| sense_resistor_mohm | Sense resistor value in mOhm. If 0, uses board config default |
|
noexcept |
Create and initialize a test driver instance.
This helper function creates a fully configured TMC51x0 driver instance with the selected motor, board, and platform configuration.
|
noexcept |
Test chopper configuration (SpreadCycle mode).
|
noexcept |
Test CoolStep configuration and operation.
|
noexcept |
Test motor current control (IRUN/IHOLD settings).
|
noexcept |
Test DCStep configuration and operation.
|
noexcept |
Test encoder deviation detection and warnings.
|
noexcept |
Test driver initialization and basic setup verification.
|
noexcept |
Test driver status reading (GSTAT, DRV_STATUS).
|
noexcept |
Test motor enable/disable functionality.
|
noexcept |
Test encoder configuration and setup.
|
noexcept |
Test encoder position reading.
|
noexcept |
Test encoder resolution setting.
|
noexcept |
Test factory and OTP configuration reading.
|
noexcept |
Test freewheeling mode configuration.
|
noexcept |
Test global configuration settings (GCONF register).
|
noexcept |
Test global scaler configuration.
|
noexcept |
Test GPIO pin reading functionality.
|
noexcept |
Test latched position reading (index pulse).
|
noexcept |
Test lost steps detection and reading.
|
noexcept |
Test microstep diagnostics (counter, time between microsteps).
|
noexcept |
Test microstep lookup table configuration.
|
noexcept |
Test mode change speed thresholds (PWM_THRS, COOL_THRS, HIGH_THRS).
|
noexcept |
Test motor parameter configuration and settings.
|
noexcept |
Test motor setup from specifications (automatic configuration).
|
noexcept |
Test offset calibration reading.
|
noexcept |
Test open load detection functionality.
|
noexcept |
Test overtemperature protection status reading.
|
noexcept |
Test phase current reading (microstep current diagnostics).
|
noexcept |
Test position control (target position, current position).
|
noexcept |
Test PWM scale reading (PWM_AUTO, PWM_SCALE_SUM).
|
noexcept |
Test ramp mode switching (POSITIONING, VELOCITY_POS, VELOCITY_NEG, HOLD).
|
noexcept |
Test ramp parameter configuration (speed, acceleration, etc.).
|
noexcept |
Test ramp parameters (VSTART, VSTOP, first acceleration, etc.).
|
noexcept |
Test reference switch configuration and homing.
|
noexcept |
Test register read/write operations.
|
noexcept |
Test sensorless homing configuration (StallGuard2-based).
|
noexcept |
Test short circuit protection configuration.
|
noexcept |
Test speed control (max speed, acceleration, deceleration).
|
noexcept |
Test StallGuard2 configuration and reading.
|
noexcept |
Test StealthChop configuration and automatic tuning.
|
noexcept |
Test UART transmission count reading.
|
noexcept |
Test unit conversion functions (RPM, degrees, millimeters, etc.).
|
noexcept |
Verify mode pins match expected communication mode.
| spi | SPI communication interface |
| driver | TMC51x0 driver instance |
| expected_comm_mode | Expected communication mode (SPI or UART) |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
static |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
static |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |