@@ -911,7 +911,7 @@ void tmc2130_get_wave(uint8_t axis, uint8_t* data)
911911// - Analog Devices AN-026: "Stepper Motor Control Using TMC2130"
912912// https://www.analog.com/en/resources/app-notes/an-026.html
913913uint8_t tmc2130_calc_constant_torque_value (uint8_t i, uint8_t va, float fac, float tcorr,
914- float & carry, float & prev_theoretical_value) {
914+ float & prev_theoretical_value) {
915915 constexpr uint8_t SIN0 = 0 ;
916916 constexpr uint8_t AMP = 248 ; // Amplitude limit as per AN-026 recommendation
917917 constexpr float TARGET_MAGNITUDE_SQUARED = (float )AMP * AMP + (float )SIN0 * SIN0;
@@ -940,10 +940,8 @@ uint8_t tmc2130_calc_constant_torque_value(uint8_t i, uint8_t va, float fac, flo
940940 theoretical_value = sqrt (TARGET_MAGNITUDE_SQUARED - mirror_theoretical * mirror_theoretical);
941941 }
942942
943- // Step 1: Apply carry mechanism and initial quantization
944- // Carry compensates for accumulated rounding errors from previous steps
945- float adjusted_theoretical = theoretical_value - carry;
946- uint8_t candidate_value = (uint8_t )(adjusted_theoretical + 0.5 );
943+ // Step 1: Initial quantization using simple rounding
944+ uint8_t candidate_value = (uint8_t )(theoretical_value + 0.5 );
947945
948946 // Step 2: Slope-based delta limiting for TMC2130 compression
949947 // Calculate slope between current and previous theoretical values
@@ -977,10 +975,6 @@ uint8_t tmc2130_calc_constant_torque_value(uint8_t i, uint8_t va, float fac, flo
977975 candidate_value = AMP;
978976 }
979977
980- // Step 4: Update carry for next iteration
981- // Carry = quantization_error = actual_output - theoretical_target
982- carry = candidate_value - theoretical_value;
983-
984978 // Update previous theoretical value for next slope calculation
985979 prev_theoretical_value = theoretical_value;
986980
@@ -1015,7 +1009,6 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000)
10151009 uint32_t reg = 0 ; // tmc2130 register
10161010
10171011 // Constant torque algorithm parameters (only used if use_constant_torque is true)
1018- float carry = 0.0 ; // Carry value to handle rounding adjustments
10191012 float prev_theoretical_value = 0.0 ; // Cache previous theoretical value for slope calculation (initialized with SIN0)
10201013 float tcorr = 1.0 ; // Pre-calculated correction factor for constant torque algorithm
10211014
@@ -1040,7 +1033,7 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000)
10401033 reg = 0 ;
10411034
10421035 if (use_constant_torque) {
1043- vA = tmc2130_calc_constant_torque_value (i, va, fac, tcorr, carry, prev_theoretical_value);
1036+ vA = tmc2130_calc_constant_torque_value (i, va, fac, tcorr, prev_theoretical_value);
10441037 } else {
10451038 // calculate value
10461039 if (fac == 1 ) // default TMC wave
0 commit comments