Calibration¶
STEPFOC firmware has autocalibration feature that allows you to automatically detect and tune your motor parameters. It detects the following:
- Motor phase order (checked; if it is wrong you are told to swap the phases)
- Current loop PID parameters
- Motor Kt, KV
- Fine tune electrical angle
Vbus voltage
When calibrating the motor use 24V supply voltage for the best results! Using smaller voltage may result in incorrect Resistance, inductance and kt and other parameters!
Positive rotation¶
In STEPFOC firmware positive rotation is always counter-clockwise. That means that positive current will result in rotation in that direction. Positive speed setpoint will rotate motor in that direction and rotating in that direction will increase motor position!
Calibration settings¶
Note that the values that STEPFOC calculate are only estimations and if you want to get exact values use high precision instruments to measure them.
Resistance, Inductance and pole pair
You will NEED to enter Resistance, Inductance and pole pair manually. STEPFOC will not calculate those for you and will return error if you don't change default values. Use #R, #L and #PP to enter the values listed in the spec sheet of your stepper motor!
For 1.8 deg stepper enter #PP 50
For 1.2 deg stepper enter #PP 75
For 0.9 deg stepper enter #PP 100
For 0.72 deg stepper enter #PP 125
Calling calibration routine¶
Calibration routine can only be called from the UART interface. The command is:
#Cal
Calibration routine output¶
Note
Values that our calibration routine returns here are specific to motor we tested. Your numbers WILL be different!
Tip
In case your motor stays in one step of the calibration routine too long issues a #Reset command and try again. Also do that in case you don't get full log messages from the routine.
After calling calibration routine the following will happen:
----------------
Calibration mode
----------------
Pole pair check
Make sure you enter correct pole pair for your stepper motor. Use this as a guide:
For 1.8 deg stepper enter #PP 50
For 1.2 deg stepper enter #PP 75
For 0.9 deg stepper enter #PP 100
For 0.72 deg stepper enter #PP 125
Magnet and Vbus check
Motor will check Vbus voltage and try to detect Encoder magnet. If both passed you will get:
Magnet test: Passed
Vbus test: Passed
Even if the magnet test "passed" your magnet could still be too far or too close (touching) the encoder IC. You need to make sure that distance between the magnet and the IC is around 1mm.
Resistance and inductance
STEPFOC does not measure resistance and inductance. It checks that you entered them with #R and #L and prints them back, then calculates the current loop gains from them and the current loop bandwidth (#Cbw). With the example motor:
Resistance = 1.100000Ohm
Inductance = 0.002600H
Kp_iq = ...
Ki_iq = ...
If either value is still 0 the step fails:
Resistance test: Failed
Please enter your stepper resistance by using #R command
The calculated Kp_iq and Ki_iq are a starting point for stepper motors; it is best to tune them by hand (see PID tuning).
Open loop dir check
Motor will spin in one direction in open loop mode. If it spins in the positive direction you get Open loop direction: good and calibration continues. Otherwise:
Open loop: Failed
Switch motor phases and try again!
Swap A+ and A- (or B+ and B-), then run #Cal again.
Phase order dir
Motor will start to spin in a single direction with voltage mode.
If it spins our phase connections are good. If it does not spin we need to switch them up and try again.
Theta offset
Motor will spin rapidly in one direction and then switch to another. This can last a few minutes (max 2 minutes, after that it times out). When it finishes you get Angle offset is: <value> and Phase order is good!.
Kt, KV and flux linkage dir
Motor will start to spin fast in one direction for a short time.
Good output will look like this (Your numbers will be different):
KV is: 39.41667
Kt is: 0.20981
Flux linkage is: 0.012716
Errors
Note that in this step we measure motor KV and from that Kt and flux linkage. KV measurement can be wrong due the a lot of factors and for cheap and poor quality motors you can get different results.
Calibration end
In case your calibration was successful you will get message like below. Make sure to #Save the config.
After the successful config is saved you don't need to re run calibration when you start your motor driver.
Calibration success!
Save config with #Save
Going to idle!
Note
You will need to re run the calibration if you change your motors or change motor phases.
False success!
There is a known issue related to the encoder magnet's attachment to the motor rotor. If the magnet is not securely fastened and can slip or rotate freely, the motor may incorrectly report that the calibration process was successful when, in fact, it was not. To avoid this problem, it's crucial to ensure that the magnet is firmly secured to the motor rotor. Proper attachment of the magnet ensures the accuracy of the calibration process and prevents potential errors in motor operation.
Troubleshooting¶
No magnet detected
Magnet test: Failed
Vbus to low or not detected
Vbus test: Failed
Resistance or inductance left at 0 (enter them with #R and #L)
Resistance test: Failed
Please enter your stepper resistance by using #R command
Wrong phase order. Switch motor phases (swap A+ and A-)
Open loop: Failed
Switch motor phases and try again!
or
Phase order is wrong!
Switch motor phases and try again!
Calibration failed!
If calibration is successful but your LED is in error mode and calling #Error reports no error try to call #Info command. If you see -1 somewhere that means that default config was no loaded and eeprom is filled with junk variables. To fix that call the #Default command.
Found a mistake on this page? Edit it on GitHub ยท Report it

