Trinamic TMCM-351 Use and care manual

MODULE FOR STEPPER MOTORS MODULE
Firmware Version V4.45
TMCL™ FIRMWARE MANUAL
++TMCM-351
+ +
3-Axis Stepper
Controller / Driver
2.8 A/ 24 V
SPI, RS232, RS485, CAN, and USB
Encoder Interface

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 2
www.trinamic.com
Table of Contents
1Features........................................................................................................................................................................... 4
2Putting the TMCM-351 into Operation.................................................................................................................... 5
2.1 Starting up............................................................................................................................................................. 5
2.2 Testing with a Simple TMCL Program ........................................................................................................... 8
2.2.1 Testing without Encoder ............................................................................................................................. 8
2.2.2 Testing with Encoder ................................................................................................................................... 9
2.3 Operating the Module in Direct Mode.........................................................................................................10
3Overview .......................................................................................................................................................................11
4TMCL and TMCL-IDE....................................................................................................................................................11
4.1 Binary command format..................................................................................................................................11
4.1.1 Checksum Calculation.................................................................................................................................12
4.2 Reply Format.......................................................................................................................................................12
4.2.1 Status Codes .................................................................................................................................................13
4.3 Standalone Applications ..................................................................................................................................13
4.4 TMCL Command Overview ..............................................................................................................................14
4.4.1 TMCL Commands .........................................................................................................................................14
4.4.2 Commands Listed According to Subject Area.....................................................................................15
4.5 The ASCII Interface...........................................................................................................................................20
4.5.1 Command Line Format ..............................................................................................................................20
4.5.2 Format of a Reply........................................................................................................................................20
4.5.3 Commands Used in ASCII Mode.............................................................................................................20
4.5.4 Configuring the ASCII Interface..............................................................................................................21
4.6 Commands...........................................................................................................................................................22
4.6.1 ROR (rotate right).......................................................................................................................................22
4.6.2 ROL (rotate left)............................................................................................................................................23
4.6.3 MST (motor stop) .......................................................................................................................................24
4.6.4 MVP (move to position).............................................................................................................................25
4.6.5 SAP (set axis parameter) ...........................................................................................................................27
4.6.6 GAP (get axis parameter)...........................................................................................................................28
4.6.7 STAP (store axis parameter) .....................................................................................................................29
4.6.8 RSAP (restore axis parameter) .................................................................................................................30
4.6.9 SGP (set global parameter).......................................................................................................................31
4.6.10 GGP (get global parameter)......................................................................................................................32
4.6.11 STGP (store global parameter).................................................................................................................33
4.6.12 RSGP (restore global parameter).............................................................................................................34
4.6.13 RFS (reference search)................................................................................................................................35
4.6.14 SIO (set output) ...........................................................................................................................................36
4.6.15 GIO (get input/output) ...............................................................................................................................38
4.6.16 CALC (calculate) ............................................................................................................................................41
4.6.17 COMP (compare)...........................................................................................................................................42
4.6.18 JC (jump conditional)..................................................................................................................................43
4.6.19 JA (jump always)..........................................................................................................................................44
4.6.20 CSUB (call subroutine)................................................................................................................................45
4.6.21 RSUB (return from subroutine)................................................................................................................46
4.6.22 WAIT (wait for an event to occur) .........................................................................................................47
4.6.23 STOP (stop TMCL program execution) ...................................................................................................48
4.6.24 SAC (SPI bus access)...................................................................................................................................49
4.6.25 SCO (set coordinate) ...................................................................................................................................50
4.6.26 GCO (get coordinate) ..................................................................................................................................51
4.6.27 CCO (capture coordinate)...........................................................................................................................52
4.6.28 ACO (accu to coordinate)...........................................................................................................................53
4.6.29 CALCX (calculate using the X register) ..................................................................................................54
4.6.30 AAP (accumulator to axis parameter) ....................................................................................................55
4.6.31 AGP (accumulator to global parameter) ...............................................................................................56
4.6.32 CLE (clear error flags) .................................................................................................................................57
4.6.33 VECT (set interrupt vector)........................................................................................................................58

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 3
www.trinamic.com
4.6.34 EI (enable interrupt) ...................................................................................................................................59
4.6.35 DI (disable interrupt)..................................................................................................................................61
4.6.36 RETI (return from interrupt) .....................................................................................................................63
4.6.37 Customer Specific TMCL Command Extension (user function).......................................................64
4.6.38 Request Target Position Reached Event ...............................................................................................65
4.6.39 BIN (return to binary mode) ....................................................................................................................65
4.6.40 TMCL Control Functions .............................................................................................................................66
5Axis Parameters...........................................................................................................................................................67
6Global Parameters ......................................................................................................................................................71
6.1 Bank 0 ...................................................................................................................................................................71
6.2 Bank 1 ...................................................................................................................................................................74
6.3 Bank 2 ...................................................................................................................................................................74
6.4 Bank 3 ...................................................................................................................................................................75
7Hints and Tips .............................................................................................................................................................76
7.1 Reference Search................................................................................................................................................76
7.2 Changing the Prescaler Value of an Encoder............................................................................................77
7.3 Stall Detection ....................................................................................................................................................78
7.4 Fixing Microstep Errors.....................................................................................................................................78
7.5 Using the RS485 Interface...............................................................................................................................78
8Life Support Policy .....................................................................................................................................................79
9Revision History ..........................................................................................................................................................80
9.1 Firmware Revision.............................................................................................................................................80
9.2 Document Revision ...........................................................................................................................................80
10 References.....................................................................................................................................................................80

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 4
www.trinamic.com
1Features
The TMCM-351 is a powerful three axes bipolar stepper motor controller/driver board with optional encoder
interface for all three axes and a large number of general purpose digital and analogue input/outputs.
Several different serial communication interfaces are available.
MAIN CHARACTERISTICS
Electrical data
-Supply voltage: +24V DC nominal (28.5V DC max.)
-Motor current: up to 2.8A RMS per axis (programmable)
Stepper motor data
-two phase bipolar stepper motors with up to 2.8A RMS coil current
-optional incremental encoder interface (a/b/n), accepts differential or single ended input signals
Interfaces
-2 reference switch inputs per motor axis (6 altogether, internal pull-up resistors, +24V compatible)
-8 general purpose inputs (+24V compatible)
-8 general purpose outputs incl. two power outputs (all open-collector)
-1 shutdown input (enable/disable driver stage in hardware)
-4 dedicated analogue inputs (programmable 3.3V/10V input range)
-SPI™1connector with three chip select signals for I/O extension
-RS232, RS485, CAN and USB serial communication interfaces
Features
-High-efficient operation, low power-dissipation (TMC249 stepper driver with external MOSFETs)
-Dynamic current control
-Integrated Protection
-On the fly alteration of motor parameters (e.g. position, velocity, acceleration)
-Motion profile calculation in real-time (TMC429 motion controller)
-Each axis individually and independently programmable
-Supports up to 64 microsteps per fullstep
-Integrated stallGuard™for motor stall detection (e.g. elimination of end switches)
-Closed-loop operation with TMCL possible (when using the optional incremental encoder interface)
Software
-TMCL™remote (direct mode) or stand-alone operation (memory for 2048 TMCL commands)
-Fully supported by TMCL-IDE (PC based integrated development environment)
-Optional CANopen firmware
1SPI™ is a trademark of Motorola

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 5
www.trinamic.com
2Putting the TMCM-351 into Operation
Here you can find basic information for putting your module into operation. The text contains two simple
examples (with and without encoder) for a TMCL program and a short description of operating the module
in direct mode.
THE THINGS YOU NEED
-TMCM-351
-Interface (RS232, RS485, USB or CAN) suitable to your TMCM-351 version with cables
-Nominal supply voltage +24V DC (+7…+28.5V DC) for your module
-Up to three stepper motors which fit to your module, for example QSH-5718 or QSH-6018.
-TMCL-IDE program and PC
-Encoder optional
PRECAUTIONS
-Do not connect or disconnect the motor while powered!
-Do not mix up connections or short-circuit pins.
-Avoid bounding I/O wires with motor power wires as this may cause noise picked up from the motor
supply.
-Do not exceed the maximum power supply of 28.5V DC.
-Start with power supply OFF!
2.1 Starting up
1. Connect the motors
For the three motors there are two connector options:
-one detachable screw connector (for prototyping, smaller series)
-three separate crimp connectors (for higher volume series)
For this example we choose the screw connector. You will find further information about the crimp
connectors in the hardware manual.
Please connect the motors with the screw connector as follows:
112
Pin
Label
Description
1
Motor_0_B-
Motor 0, coil B
2
Motor_0_B+
Motor 0, coil B
3
Motor_0_A-
Motor 0, coil A
4
Motor_0_A+
Motor 0, coil A
5
Motor_1_B-
Motor 1, coil B
6
Motor_1_B+
Motor 1, coil B
7
Motor_1_A-
Motor 1, coil A
8
Motor_1_A+
Motor 1, coil A
9
Motor_2_B-
Motor 2, coil B
10
Motor_2_B+
Motor 2, coil B
11
Motor_2_A-
Motor 2, coil A
12
Motor_2_A+
Motor 2, coil A

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 6
www.trinamic.com
2. Connect the encoder
For boards with assembled encoder option three connectors (one encoder interface connector per axis)
will be available. A standard 2.54mm pitch two row header is used for connecting an encoder.
Differential and single ended incremental encoders with/without zero/index channel are supported.
Please connect the encoders as follows:
-Single ended encoder: GND to pin 1 and/or 2
+5V to pin 7 and/or 8
A to pin 5
N to pin 3
B to pin 9
-Differential encoder: GND to pin 1 and/or 2
+5V to pin 7 and/or 8
A+ to pin 5, A- to pin 6
N+ to pin 3, N- to pin 4
B+ to pin 9, B- to pin 10
1
2
9
10
Pin
Label
Pin
Label
1
GND
2
GND
3
Encoder_0/1/2_N+
4
Encoder_0/1/2_N-
5
Encoder_0/1/2_A+
6
Encoder_0/1/2_A-
7
+5V output
8
+5V output
9
Encoder_0/1/2_B+
10
Encoder_0/1/2_B-
GND
B
A
N
+5V
Example for single ended encoder
3. Connect the interface
In this case we choose the USB interface for serial communication. A standard USB type B connector
is used for this purpose. USB is one out of four different interfaces available for communication with
the board. You can refer to the hardware manual for further information about the pinning of the
other interfaces.
Please connect the USB interface with the enclosed cable as follows:
1
2
4
3
Pin
Label
Description
1
+5V
Board is self-powered –just use to detect availability of
attached host system (e.g. PC)
2
USB-
Differential USB bus
3
USB+
Differential USB bus
4
GND
System / module ground

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 7
www.trinamic.com
4. Connect the power supply:
Attention: Do not exceed the maximum power supply of 28.5 V DC!
Please connect the power supply as follows:
12
Pin
Label
Description
1
GND
Module ground (power supply and signal ground)
2
VDD
Power supply input, nom. +24V DC (+7 .. +28.5V DC)
5. Switch on the power supply
The green LED for power should glow now. This indicates that the on-board +5V supply is available.
If this does not occur, switch power OFF and check your connections as well as the power
supply.
6. Start the TMCL-IDE software development environment
The TMCL-IDE is on hand on the TechLibCD and on www.trinamic.com.
Installing the TMCL-IDE:
-Make sure the COM port you intend to use is not blocked by another program.
-Open TMCL-IDE by clicking TMCL.exe.
-Choose Setup and Options and thereafter the Connection tab.
-Choose COM port and type with the parameters shown below (baud rate 9600). Click OK.

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 8
www.trinamic.com
2.2 Testing with a Simple TMCL Program
2.2.1 Testing without Encoder
Assemble
Download Run
Stop
1. Click on Icon Assemble to convert the TMCL into machine code.
2. Then download the program to the TMCM-351 module via the icon Download.
3. Press icon Run. The desired program will be executed.
4. Click Stop button to stop the program.
//A simple example for using TMCL™ and TMCL-IDE
ROL 0, 500 //Rotate motor 0 with speed 500
WAIT TICKS, 0, 500
MST 0
ROR 1, 250 //Rotate motor 1 with 250
WAIT TICKS, 0, 500
MST 1
SAP 4, 2, 500 //Set max. Velocity
SAP 5, 2, 50 //Set max. Acceleration
Loop: MVP ABS, 2, 10000 //Move to Position 10000
WAIT POS, 2, 0 //Wait until position reached
MVP ABS, 2, -10000 //Move to Position -10000
WAIT POS, 2, 0 //Wait until position reached
JA Loop //Infinite Loop

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

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 10
www.trinamic.com
2.3 Operating the Module in Direct Mode
1. Start TMCL Direct Mode.
Direct Mode
2. If the communication is established the TMCM-351 is automatically detected. If the module is not
detected, please check all points above (cables, interface, power supply, COM port, baud rate).
3. Issue a command by choosing instruction, type (if necessary), motor, and value and click Execute
to send it to the module.
Examples:
-ROR rotate right, motor 0, value 500 -> Click Execute. The first motor is rotating now.
-MST motor stop, motor 0 -> Click Execute. The first motor stops now.
You will find a description of all TMCL commands in the following chapters.

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 11
www.trinamic.com
3Overview
As with most TRINAMIC modules the software running on the microprocessor of the TMCM-351 consists of
two parts, a boot loader and the firmware itself. Whereas the boot loader is installed during production and
testing at TRINAMIC and remains –normally –untouched throughout the whole lifetime, the firmware can
be updated by the user. New versions can be downloaded free of charge from the TRINAMIC website
(http://www.trinamic.com).
The firmware shipped with this module is related to the standard TMCL firmware [TMCL] shipped with most
of TRINAMIC modules with regard to protocol and commands. Corresponding, the module is based on the
TMC428/429 stepper motor controller and the TMC249 power driver and supports the standard TMCL with a
special range of values. Further you can order the module with encoder option, realized with the TMC423.
4TMCL and TMCL-IDE
The TMCM-351module supports TMCL direct mode (binary commands or ASCII interface) and standalone
TMCL program execution. You can store up to 2048 TMCL instructions on it. In direct mode and most cases
the TMCL communication over RS485, RS232, USB and CAN follows a strict master/slave relationship. That is,
a host computer (e.g. PC/PLC) acting as the interface bus master will send a command to the module. The
TMCL interpreter on it will then interpret this command, do the initialization of the motion controller, read
inputs and write outputs or whatever is necessary according to the specified command. As soon as this step
has been done, the module will send a reply back over RS485/RS232/USB/CAN to the bus master. Only then
should the master transfer the next command. Normally, the module will just switch to transmission and
occupy the bus for a reply, otherwise it will stay in receive mode. It will not send any data over the
interface without receiving a command first. This way, any collision on the bus will be avoided when there
are more than two nodes connected to a single bus.
The Trinamic Motion Control Language (TMCL) provides a set of structured motion control commands. Every
motion control command can be given by a host computer or can be stored in an EEPROM on the TMCM-351
to form programs that run stand-alone on the module. For this purpose there are not only motion control
commands but also commands to control the program structure (like conditional jumps, compare and
calculating).
Every command has a binary representation and a mnemonic. The binary format is used to send commands
from the host to a module in direct mode, whereas the mnemonic format is used for easy usage of the
commands when developing standalone TMCL applications using the TMCL-IDE (IDE means Integrated
Development Environment).
There is also a set of configuration variables for the axis and for global parameters which allow individual
configuration of nearly every function of a module. This manual gives a detailed description of all TMCL
commands and their usage.
4.1 Binary command format
Every command has a mnemonic and a binary representation. When commands are sent from a host to a
module, the binary format has to be used. Every command consists of a one-byte command field, a one-byte
type field, a one-byte motor/bank field and a four-byte value field. So the binary representation of a
command always has seven bytes.
When a command is to be sent via RS232, RS485 or USB interface, it has to be enclosed by an address byte
at the beginning and a checksum byte at the end. In this case it consists of nine bytes.
This is different when communicating takes place via the CAN bus. Address and checksum are included in
the CAN standard and do not have to be supplied by the user.
The binary command format for RS232, RS485, and USB is as follows:

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 12
www.trinamic.com
Bytes
Meaning
1
Module address
1
Command number
1
Type number
1
Motor or Bank number
4
Value (MSB first!)
1
Checksum
-The checksum is calculated by adding up all the other bytes using an 8-bit addition.
-When using the CAN bus, just leave out the first byte (module address) and the last byte (checksum).
4.1.1 Checksum Calculation
As mentioned above, the checksum is calculated by adding up all bytes (including the module address byte)
using 8-bit addition. Here are two examples to show how to do this:
in C:
unsigned char i, Checksum;
unsigned char Command[9];
//Set the “Command” array to the desired command
Checksum = Command[0];
for(i=1; i<8; i++)
Checksum+=Command[i];
Command[8]=Checksum; //insert checksum as last byte of the command
//Now, send it to the module
in Delphi:
var
i, Checksum: byte;
Command: array[0..8] of byte;
//Set the “Command” array to the desired command
//Calculate the Checksum:
Checksum:=Command[0];
for i:=1 to 7 do Checksum:=Checksum+Command[i];
Command[8]:=Checksum;
//Now, send the “Command” array (9 bytes) to the module
4.2 Reply Format
Every time a command has been sent to a module, the module sends a reply.
The reply format for RS485, RS232, and USB is as follows:
Bytes
Meaning
1
Reply address
1
Module address
1
Status (e.g. 100 means no error)
1
Command number
4
Value (MSB first!)
1
Checksum
-The checksum is also calculated by adding up all the other bytes using an 8-bit addition.
-When using CAN bus, the first byte (reply address) and the last byte (checksum) are left out.
-Do not send the next command before you have received the reply!

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 13
www.trinamic.com
4.2.1 Status Codes
The reply contains a status code. The status code can have one of the following values:
Code
Meaning
100
Successfully executed, no error
101
Command loaded into TMCL
program EEPROM
1
Wrong checksum
2
Invalid command
3
Wrong type
4
Invalid value
5
Configuration EEPROM locked
6
Command not available
4.3 Standalone Applications
The module is equipped with a TMCL memory for storing TMCL applications. You can use TMCL-IDE for
developing standalone TMCL applications. You can download a program into the EEPROM and afterwards it
will run on the module. The TMCL-IDE contains an editor and the TMCL assembler where the commands can
be entered using their mnemonic format. They will be assembled automatically into their binary
representations. Afterwards this code can be downloaded into the module to be executed there.

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 14
www.trinamic.com
4.4 TMCL Command Overview
In this section a short overview of the TMCL commands is given.
4.4.1 TMCL Commands
The following TMCL commands are currently supported:
Command
Number
Parameter
Description
ROR
1
<motor number>, <velocity>
Rotate right with specified velocity
ROL
2
<motor number>, <velocity>
Rotate left with specified velocity
MST
3
<motor number>
Stop motor movement
MVP
4
ABS|REL|COORD, <motor number>,
<position|offset>
Move to position (absolute or relative)
SAP
5
<parameter>, <motor number>, <value>
Set axis parameter (motion control
specific settings)
GAP
6
<parameter>, <motor number>
Get axis parameter (read out motion
control specific settings)
STAP
7
<parameter>, <motor number>
Store axis parameter permanently (non
volatile)
RSAP
8
<parameter>, <motor number>
Restore axis parameter
SGP
9
<parameter>, <bank number>, value
Set global parameter (module specific
settings e.g. communication settings
or TMCL user variables)
GGP
10
<parameter>, <bank number>
Get global parameter (read out module
specific settings e.g. communication
settings or TMCL user variables)
STGP
11
<parameter>, <bank number>
Store global parameter (TMCL user
variables only)
RSGP
12
<parameter>, <bank number>
Restore global parameter (TMCL user
variable only)
RFS
13
START|STOP|STATUS, <motor number>
Reference search
SIO
14
<port number>, <bank number>, <value>
Set digital output to specified value
GIO
15
<port number>, <bank number>
Get value of analogue/digital input
CALC
19
<operation>, <value>
Process accumulator & value
COMP
20
<value>
Compare accumulator <-> value
JC
21
<condition>, <jump address>
Jump conditional
JA
22
<jump address>
Jump absolute
CSUB
23
<subroutine address>
Call subroutine
RSUB
24
Return from subroutine
EI
25
<interrupt number>
Enable interrupt
DI
26
<interrupt number>
Disable interrupt
WAIT
27
<condition>, <motor number>, <ticks>
Wait with further program execution
STOP
28
Stop program execution
SAC
29
<bus number>, <number of bites>,
<send data>
SPI bus access
SCO
30
<coordinate number>, <motor number>,
<position>
Set coordinate
GCO
31
<coordinate number>, <motor number>
Get coordinate
CCO
32
<coordinate number>, <motor number>
Capture coordinate
CALCX
33
<operation>
Process accumulator & X-register
AAP
34
<parameter>, <motor number>
Accumulator to axis parameter
AGP
35
<parameter>, <bank number>
Accumulator to global parameter
VECT
37
<interrupt number>, <label>
Set interrupt vector
RETI
38
Return from interrupt
ACO
39
<coordinate number>, <motor number>
Accu to coordinate

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 15
www.trinamic.com
4.4.2 Commands Listed According to Subject Area
4.4.2.1 Motion Commands
These commands control the motion of the motor. They are the most important commands and can be used
in direct mode or in standalone mode.
Mnemonic
Command
number
Meaning
ROL
2
Rotate left
ROR
1
Rotate right
MVP
4
Move to position
MST
3
Motor stop
RFS
13
Reference search
SCO
30
Store coordinate
CCO
32
Capture coordinate
GCO
31
Get coordinate
4.4.2.2 Parameter Commands
These commands are used to set, read and store axis parameters or global parameters. Axis parameters can
be set independently for the axis, whereas global parameters control the behavior of the module itself.
These commands can also be used in direct mode and in standalone mode.
Mnemonic
Command
number
Meaning
SAP
5
Set axis parameter
GAP
6
Get axis parameter
STAP
7
Store axis parameter into EEPROM
RSAP
8
Restore axis parameter from EEPROM
SGP
9
Set global parameter
GGP
10
Get global parameter
STGP
11
Store global parameter into EEPROM
RSGP
12
Restore global parameter from EEPROM
4.4.2.3 I/O Port Commands
These commands control the external I/O ports and can be used in direct mode and in standalone mode.
Mnemonic
Command
number
Meaning
SIO
14
Set output
GIO
15
Get input
SAC
29
Access to external SPI device
4.4.2.4 SPI Bus Access Command
Mnemonic
Command
number
Meaning
SAC
29
SPI bus access

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 16
www.trinamic.com
4.4.2.5 Control Commands
These commands are used to control the program flow (loops, conditions, jumps etc.). It does not make
sense to use them in direct mode. They are intended for standalone mode only.
Mnemonic
Command
number
Meaning
JA
22
Jump always
JC
21
Jump conditional
COMP
20
Compare accumulator with constant value
CLE
36
Clear error flags
CSUB
23
Call subroutine
RSUB
24
Return from subroutine
WAIT
27
Wait for a specified event
STOP
28
End of a TMCL program
4.4.2.6 Calculation Commands
These commands are intended to be used for calculations within TMCL applications. Although they could
also be used in direct mode it does not make much sense to do so.
Mnemonic
Command
number
Meaning
CALC
19
Calculate using the accumulator and a constant
value
CALCX
33
Calculate using the accumulator and the X register
AAP
34
Copy accumulator to an axis parameter
AGP
35
Copy accumulator to a global parameter
ACO
39
Copy accu to coordinate
For calculating purposes there is an accumulator (or accu or A register) and an X register. When executed in
a TMCL program (in stand-alone mode), all TMCL commands that read a value store the result in the
accumulator. The X register can be used as an additional memory when doing calculations. It can be loaded
from the accumulator.
When a command that reads a value is executed in direct mode the accumulator will not be affected. This
means that while a TMCL program is running on the module (stand-alone mode), a host can still send
commands like GAP, GGP or GIO to the module (e.g. to query the actual position of the motor) without
affecting the flow of the TMCL program running on the module.
4.4.2.7 Interrupt Commands
Due to some customer requests, interrupt processing has been introduced in the TMCL firmware for ARM
based modules.
Mnemonic
Command number
Meaning
EI
25
Enable interrupt
DI
26
Disable interrupt
VECT
37
Set interrupt vector
RETI
38
Return from interrupt
4.4.2.7.1 Interrupt Types:
There are many different interrupts in TMCL, like timer interrupts, stop switch interrupts, position reached
interrupts, and input pin change interrupts. Each of these interrupts has its own interrupt vector. Each
interrupt vector is identified by its interrupt number. Please use the TMCL included file Interrupts.inc for
symbolic constants of the interrupt numbers.

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 17
www.trinamic.com
4.4.2.7.2 Interrupt Processing:
When an interrupt occurs and this interrupt is enabled and a valid interrupt vector has been defined for that
interrupt, the normal TMCL program flow will be interrupted and the interrupt handling routine will be
called. Before an interrupt handling routine gets called, the context of the normal program will be saved
automatically (i.e. accumulator register, X register, TMCL flags).
There is no interrupt nesting, i.e. all other interrupts are disabled while an interrupt handling routine is
being executed.
On return from an interrupt handling routine, the context of the normal program will automatically be
restored and the execution of the normal program will be continued.
4.4.2.7.3 Interrupt Vectors:
The following table shows all interrupt vectors for the three motors that can be used.
Interrupt number
Interrupt type
0
Timer 0
1
Timer 1
2
Timer 2
3
Target position reached 0
4
Target position reached 1
5
Target position reached 2
15
stallGuard 0
16
stallGuard 1
17
stallGuard 2
21
Deviation 0
22
Deviation 1
23
Deviation 2
27
Left stop switch 0
28
Right stop switch 0
29
Left stop switch 1
30
Right stop switch 1
31
Left stop switch 2
32
Right stop switch 2
39
Input change 0
40
Input change 1
41
Input change 2
42
Input change 3
43
Input change 4
44
Input change 5
45
Input change 6
46
Input change 7
255
Global interrupts
4.4.2.7.4 Further Configuration of Interrupts
Some interrupts need further configuration (e.g. the timer interval of a timer interrupt). This can be done
using SGP commands with parameter bank 3 (SGP <type>, 3, <value>). Please refer to the SGP command for
further information about that.

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 18
www.trinamic.com
4.4.2.7.5 Using Interrupts in TMCL
To use an interrupt the following things have to be done:
-Define an interrupt handling routine using the VECT command.
-If necessary, configure the interrupt using an SGP <type>, 3, <value> command.
-Enable the interrupt using an EI <interrupt> command.
-Globally enable interrupts using an EI 255 command.
-An interrupt handling routine must always end with a RETI command
The following example shows the use of a timer interrupt:
VECT 0, Timer0Irq //define the interrupt vector
SGP 0, 3, 1000 //configure the interrupt: set its period to 1000ms
EI 0 //enable this interrupt
EI 255 //globally switch on interrupt processing
//Main program: toggles output 3, using a WAIT command for the delay
Loop:
SIO 3, 2, 1
WAIT TICKS, 0, 50
SIO 3, 2, 0
WAIT TICKS, 0, 50
JA Loop
//Here is the interrupt handling routine
Timer0Irq:
GIO 0, 2 //check if OUT0 is high
JC NZ, Out0Off //jump if not
SIO 0, 2, 1 //switch OUT0 high
RETI //end of interrupt
Out0Off:
SIO 0, 2, 0 //switch OUT0 low
RETI //end of interrupt
In the example above, the interrupt numbers are used directly. To make the program better readable use the
provided include file Interrupts.inc. This file defines symbolic constants for all interrupt numbers which can
be used in all interrupt commands. The beginning of the program above then looks like the following:
#include Interrupts.inc
VECT TI_TIMER0, Timer0Irq
SGP TI_TIMER0, 3, 1000
EI TI_TIMER0
EI TI_GLOBAL
Please also take a look at the other example programs.
4.4.2.8 ASCII Commands
Mnemonic
Command number
Meaning
-
139
Enter ASCII mode
BIN
-
Quit ASCII mode and return to binary mode. This command can
only be used in ASCII mode.

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 19
www.trinamic.com
4.4.2.9 TMCL Control Commands
Instruction
Description
Type
Mot/Bank
Value
128 –stop application
a running TMCL standalone
application is stopped
(don't care)
(don't care)
(don't care)
129 –run application
TMCL execution is started (or
continued)
0 - run from
current address
1 - run from
specified address
(don't care)
(don't care)
starting address
130 –step application
only the next command of a
TMCL application is executed
(don't care)
(don't care)
(don't care)
131 –reset application
the program counter is set to
zero, and the standalone
application is stopped (when
running or stepped)
(don't care)
(don't care)
(don't care)
132 –start download
mode
target command execution is
stopped and all following
commands are transferred to
the TMCL memory
(don't care)
(don't care)
starting address
of the application
133 –quit download
mode
target command execution is
resumed
(don't care)
(don't care)
(don't care)
134 –read TMCL
memory
the specified program memory
location is read
(don't care)
(don't care)
<memory
address>
135 –get application
status
one of these values is
returned:
0 –stop
1 –run
2 –step
3 –reset
(don't care)
(don't care)
(don't care)
136 –get firmware
version
return the module type and
firmware revision either as a
string or in binary format
0 –string
1 –binary
(don’t care)
(don’t care)
137 –restore factory
settings
reset all settings stored in the
EEPROM to their factory
defaults
This command does not send
back a reply.
(don’t care)
(don’t care)
must be 1234
139 –enter ASCII
mode
Enter ASCII command line
(don’t care)
(don’t care)
(don’t care)

TMCM-351 TMCL Firmware V4.45 Manual (Rev. 1.06 / 2014-MAY-16) 20
www.trinamic.com
4.5 The ASCII Interface
There is also an ASCII interface that can be used to communicate with the module and to send some
commands as text strings.
PROCEED AS FOLLOWS
-The ASCII command line interface is entered by sending the binary command 139 (enter ASCII mode).
-Afterwards the commands are entered as in the TMCL-IDE. Please note that only those commands,
which can be used in direct mode, also can be entered in ASCII mode.
-For leaving the ASCII mode and re-enter the binary mode enter the command BIN.
4.5.1 Command Line Format
As the first character, the address character has to be sent. The address character is Awhen the module
address is 1, Bfor modules with address 2 and so on. After the address character there may be spaces (but
this is not necessary). Then, send the command with its parameters. At the end of a command line a <CR>
character has to be sent.
EXAMPLES FOR VALID COMMAND LINES
AMVP ABS, 1, 50000
A MVP ABS, 1, 50000
AROL 2, 500
A MST 1
ABIN
These command lines would address the module with address 1. To address e.g. module 3, use address
character Cinstead of A. The last command line shown above will make the module return to binary mode.
4.5.2 Format of a Reply
After executing the command the module sends back a reply in ASCII format. The reply consists of:
-the address character of the host (host address that can be set in the module)
-the address character of the module
-the status code as a decimal number
-the return value of the command as a decimal number
-a <CR> character
So, after sending AGAP 0, 1 the reply would be BA 100 –5000 if the actual position of axis 1 is –5000,
the host address is set to 2 and the module address is 1. The value 100 is the status code 100 that means
command successfully executed.
4.5.3 Commands Used in ASCII Mode
The following commands can be used in ASCII mode: ROL, ROR, MST, MVP, SAP, GAP, STAP, RSAP, SGP, GGP,
STGP, RSGP, RFS, SIO, GIO, SCO, GCO, CCO, UF0, UF1, UF2, UF3, UF4, UF5, UF6, and UF7.
SPECIAL COMMANDS WHICH ARE ONLY AVAILABLE IN ASCII MODE
-BIN: This command quits ASCII mode and returns to binary TMCL mode.
-RUN: This command can be used to start a TMCL program in memory.
-STOP: Stops a running TMCL application.
Other manuals for TMCM-351
4
Table of contents
Other Trinamic Computer Hardware manuals

Trinamic
Trinamic BB-100 User manual

Trinamic
Trinamic PD 108-28-SE-485 Series User manual

Trinamic
Trinamic TMCM-351 User manual

Trinamic
Trinamic TMCM-310 User manual

Trinamic
Trinamic PANdrive PD42-1- 1243-IOLINK Safety guide

Trinamic
Trinamic PD-109 User manual

Trinamic
Trinamic CANopen User manual

Trinamic
Trinamic TMCM-1161 User manual

Trinamic
Trinamic TMCL TMCM-142 Use and care manual

Trinamic
Trinamic TMCM-160 User manual