There are two items to configure when setting your motor current:
The resulting rms_current
is calculated according to the following:
rms_current = (MOTOR_CURRENT_RATING * OPERATING_CURRENT_SETTING/100) / SQRT(2)
When a current value is set via UART control, a value from 0-31 is sent to a register on the TMC2209. This value represents a scaling value (CS, or Current Scale) to output the correct RMS current relative to the maximum current the driver can output.
The TMCStepper library takes the desired input rms_current
, calculates CS, then outputs it to the TMC2209.
To properly determine the current settings to use, this calculator is available.
Enter your Motor Current Rating (MOTOR_CURRENT_RATING
) and the percentage operating load you intend to use (OPERATING_CURRENT_SETTING
). The "Actual Output" RMS will be given, along with the corresponding CS value.
The CS value ideally should be >=16 if possible. According to the TMC2209 datasheet, a value between 16 to 31 will result in better microstepping performance.
There are two ways CS can be increased without changing the actual RMS current output:
If you are not able or comfortable measuring your Vref value, the system will still function if CS<16.
If USE_VREF
is enabled, the TMC2209 will utilize BOTH the Vref voltage and the UART current command to determine the current to output.
If you are using an operating current (Motor Current Rating * Operating Current Setting/100) > 740mA, there is no reason to enable this function.
When USE_VREF = 1
the TMC2209 outputs current relative to the Vref voltage of the potentiometer as well as the UART current given.
However, when the TMCStepper library determines the CS value based on an input current it does not know what the Vref voltage of the TMC2209 potentiometer is set to.
Therefore in order to have an accurate RMS output, you need to measure/adjust Vref and revise your UART RMS value to produce the correct actual output.
There are two scenarios to achieve a target RMS current.
The following is from the TMCStepper library for how it calculated CS from an input RMS current value. If the initial CS value is too low, Vsense is enabled resulting in a higher CS value with the same current output.
void TMCStepper::rms_current(uint16_t mA) {
uint8_t CS = 32.0*1.41421*mA/1000.0*(Rsense+0.02)/0.325 - 1;
// If Current Scale is too low, turn on high sensitivity R_sense and calculate again
if (CS < 16) {
vsense(true);
CS = 32.0*1.41421*mA/1000.0*(Rsense+0.02)/0.180 - 1;
} else { // If CS >= 16, turn off high_sense_r
vsense(false);
}
if (CS > 31)
CS = 31;
irun(CS);
ihold(CS*holdMultiplier);
//val_mA = mA;
}