Skip to content

Motor movement

Christian edited this page Nov 21, 2023 · 6 revisions

The TMC2209 stepper driver has to possibilites to drive the motor. Either trough the STEP/DIR pins or the UART Interface and the VACTUAL register. For both methods, the EN pins needs to be used to enable the motor current output.

STEP/DIR

The normal way to drive a stepper with a stepper driver, which all stepper driver boards support, is the STEP/DIR interface. After enabling the motor current output with the EN pin. The STEP pin can be used to move the motor. Each time a pulse is send to the driver on the STEP pin, the motor moves one step (one µstep). With the DIR pin the direction of this movement can be inverted.

In order to get to high velocities, an acceleration is needed. The code for getting a speed profile for stepper motor is from the AccelStepper.

Which is based on the theory "Generate stepper-motor speed profiles in real time" by David Austin.

Basicly the time for each step is calulacted new after each step.

According to the TMC2209 datasheet from trinamic the miniumum pulse time for the STEP signal is 100ns. Therefore the STEP pins is beeing pulsed fo 1000ns in the makeAStep function. This image shows the STEP pin signal. each pulse is 1µs long and the distance between the signals is antiproportional to the motor speed. The image shows an deccerlation of a stepper motor.

TMC2209_osci_deccel

With these function the maximum speed and the acceleration of the speed profile can be set:

tmc.set_acceleration(2000)
tmc.set_maxspeed(500)

after that run_to_position_steps or run_to_position_revolutions can be used to move the motor

tmc.run_to_position_steps(400)

UART/VACTUAL

The other option to drive the motor is to use the VACTUAL register via UART. The TMC2209 driver has an integrated step pulse generator, which is controlled the VACTUAL register. But the TMC2209 has no velocity ramping, like the TMC5160, which is required in order to get high speeds. For that a software generated velocity ramping is required. According to the TMC2209 datasheet the value of VACTUAL is dependent on the clock frequency of the TMC. If no external oscillator is used the conversion factor is 0.715 to get steps per seconds.

tmc.set_vactual(1000)

will move the motor with a VACTUAL value of 1000 until a different value is beeing set. With the function set_vactual_rpm and set_vactual_rps the value is automatically converted to the correct VACTUAL value. The parameter duration or revolutions can be used to automatically stop the motor after the given time. In the case of revolutions as parameter the duration is calculated and applied based on the speed.

tmc.set_vactual_rpm(30, revolutions=2)

This will move the motor with 30 rpm (0,5 rps) 2 revolutions, so 4 seconds and is therefore exactly the same as:

tmc.set_vactual_rpm(30, duration=4)

To get high velocities the software velocity ramping can be used with:

tmc.set_vactual_rpm(-120, duration=10, acceleration=500)

This will start at a very low speed and will increase the speed in a loop until the desired speed is reached. This can be a bit choppy.

Clone this wiki locally