HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
stallguard_tuning.cpp File Reference

Automatic StallGuard2 Tuning Tool with Current Reduction. More...

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "../../../inc/tmc51x0.hpp"
#include "test_config/esp32_tmc51x0_bus.hpp"
#include "test_config/esp32_tmc51x0_test_config.hpp"
#include "esp_log.h"
Include dependency graph for stallguard_tuning.cpp:

Typedefs

using TestConfig = tmc51x0_test_config::GetTestConfigForTestRig<SELECTED_TEST_RIG>
 

Functions

void app_main (void)
 

Variables

static const char * TAG = "SGT_Tuning"
 
static constexpr tmc51x0_test_config::TestRigType SELECTED_TEST_RIG
 
static constexpr float TUNING_VELOCITY_RPM = TestConfig::StallGuard::SGT_TUNED_AT_VELOCITY_RPM
 
static constexpr float TUNING_ACCELERATION_REV_S2 = TestConfig::Motion::BOUNDS_SEARCH_ACCEL_REV_S2
 
static constexpr tmc51x0::Unit VELOCITY_UNIT = tmc51x0::Unit::RPM
 
static constexpr tmc51x0::Unit ACCELERATION_UNIT = tmc51x0::Unit::RevPerSec
 

Detailed Description

Automatic StallGuard2 Tuning Tool with Current Reduction.

This tool automatically tunes the StallGuard2 Threshold (SGT) for a specific motor and velocity configuration using the comprehensive AutoTuneStallGuard function. It implements the tuning algorithm following Trinamic application note AN-002 guidelines:

  1. Saves current motor settings (current, CoolStep, etc.)
  2. Applies current reduction for safer tuning and improved sensitivity
  3. Disables interfering features (CoolStep, filter, stop-on-stall)
  4. Moves the motor at a constant velocity
  5. Monitors the SG_RESULT (StallGuard value) across SGT range
  6. Adjusts SGT until a stable non-zero SG_RESULT in ideal range (100-500) is obtained
  7. Validates at min/max velocities
  8. Restores all saved settings (except optimal SGT)

USAGE:

  1. Ensure the motor is free to move (no load or minimal load).
  2. Run this tool.
  3. The tool will output the found optimal SGT value and velocity range analysis.
  4. Use this SGT value in your application.
Author
Nebiyu Tadesse
Date
2025

Typedef Documentation

◆ TestConfig

Function Documentation

◆ app_main()

void app_main ( void )
Here is the call graph for this function:

Variable Documentation

◆ ACCELERATION_UNIT

constexpr tmc51x0::Unit ACCELERATION_UNIT = tmc51x0::Unit::RevPerSec
staticconstexpr

◆ SELECTED_TEST_RIG

constexpr tmc51x0_test_config::TestRigType SELECTED_TEST_RIG
staticconstexpr
Initial value:
=
@ TEST_RIG_FATIGUE
Fatigue test rig (Applied Motion 5034-369 motor, TMC51x0 EVAL board, reference switches,...

◆ TAG

const char* TAG = "SGT_Tuning"
static

◆ TUNING_ACCELERATION_REV_S2

constexpr float TUNING_ACCELERATION_REV_S2 = TestConfig::Motion::BOUNDS_SEARCH_ACCEL_REV_S2
staticconstexpr

◆ TUNING_VELOCITY_RPM

constexpr float TUNING_VELOCITY_RPM = TestConfig::StallGuard::SGT_TUNED_AT_VELOCITY_RPM
staticconstexpr

◆ VELOCITY_UNIT

constexpr tmc51x0::Unit VELOCITY_UNIT = tmc51x0::Unit::RPM
staticconstexpr