![Trinamic TMCM-351 Firmware Manual Download Page 9](http://html1.mh-extra.com/html/trinamic/tmcm-351/tmcm-351_firmware-manual_1163054009.webp)
TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16)
9
www.trinamic.com
2.2.2
Testing with Encoder
The motor rotates between two positions and stops if itis obstructed. The position is then corrected so that
the motor always reaches the correct target positions.
The encoder multiplier and the microstep resolution must be set so that the resolution of the encoder
position and the motor position match with each other.
The values here are for an encoder with 2000 steps per rotation and a motor with 200 full steps per
rotation. The setting of 64 microsteps then results in a motor resolution of 12800 microsteps per rotation
and the encoder multiplier of 68672 (=>6.4) also results in an encoder resolution of 12800 steps per rotation.
// Encoder demo program for all modules with encoder interface
MST
0
//Ensure that the motor is not moving
CSUB
WaitUntilStanding
SAP
210, 0, 68672
//Encoder multiplier (6.4)
SAP
209, 0, 0
//reset encoder position
SAP
0, 0, 0
//reset the motor
SAP
1, 0, 0
//position registers
SAP
140, 0, 6
//Microstep resolution (64)
SAP
5, 0, 50
//Acceleration
SAP
212, 0, 250
//use automatic deviation check to stop
motor
//when it is obstructed
Loop:
MVP
ABS
, 0, 128000
//Rotate 10 revolutions
CSUB
WaitUntilRunning
//Wait until the motor is running
CSUB
WaitUntilStanding
//Wait until the motor has stopped
GAP
8, 0
//Check if the end position has been
reached
JC
NZ
, PosReached1
//Jump if yes
GAP
209, 0
//if not: copy encoder position to
...
AAP
0, 0
//
...
target position and...
AAP
1, 0
//...actual position
WAIT
TICKS
, 0, 50
//wait 0.5sec
JA
Loop
//continue the move
PosReached1:
//End position has been reached
WAIT
TICKS
, 0, 200
//Wait 2sec
Rst2:
MVP
ABS
, 0, 0
//Move 10 revolutions back
CSUB
WaitUntilRunning
//Wait until the motor is running
CSUB
WaitUntilStanding
//Wait until the motor has stopped
GAP
8, 0
//Check if the end position has been
reached
JC
NZ
, PosReached2
//Jump if yes
GAP
209, 0
//if not: copy encoder position to...
AAP
0, 0
//...target position and...
AAP
1, 0
//...actual position
WAIT
TICKS
, 0, 50
//wait 0.5sec
JA
Rst2
//continue the move
PosReached2:
//The other end position has been reached
WAIT
TICKS
, 0, 200
//Wait 2sec
JA
Loop
//Start again
WaitUntilRunning:
//Subroutine that waits until the motor is
running
GAP
3, 0
COMP
0
JC
EQ
, WaitUntilRunning
RSUB
WaitUntilStanding:
//Subroutine that waits until the motor
has stooped
GAP
3, 0
COMP
0
JC
NE
, WaitUntilStanding
RSUB