User manual

TMCM-1160 TMCL Firmware V1.19 Manual (Rev. 1.01 / 2012-JUL-27) 83
www.trinamic.com
7 TMCL Programming Techniques and Structure
7.1 Initialization
The first task in a TMCL program (like in other programs also) is to initialize all parameters where different
values than the default values are necessary. For this purpose, SAP and SGP commands are used.
7.2 Main Loop
Embedded systems normally use a main loop that runs infinitely. This is also the case in a TMCL
application that is running stand alone. Normally the auto start mode of the module should be turned on.
After power up, the module then starts the TMCL program, which first does all necessary initializations and
then enters the main loop, which does all necessary tasks end never ends (only when the module is
powered off or reset).
There are exceptions to this, e.g. when TMCL™ routines are called from a host in direct mode.
So most (but not all) stand alone TMCL programs look like this:
//Initialization
SAP 4, 0, 500 //define max. positioning speed
SAP 5, 0, 100 //define max. acceleration
MainLoop:
//do something, in this example just running between two positions
MVP ABS, 0, 5000
WAIT POS, 0, 0
MVP ABS, 0, 0
WAIT POS, 0, 0
JA MainLoop //end of the main loop => run infinitely
7.3 Using Symbolic Constants
To make your program better readable and understandable, symbolic constants should be taken for all
important numerical values that are used in the program. The TMCL-IDE provides an include file with
symbolic names for all important axis parameters and global parameters.
Example:
//Define some constants
#include TMCLParam.tmc
MaxSpeed = 500
MaxAcc = 100
Position0 = 0
Position1 = 5000
//Initialization
SAP APMaxPositioningSpeed, Motor0, MaxSpeed
SAP APMaxAcceleration, Motor0, MaxAcc
MainLoop:
MVP ABS, Motor0, Position1
WAIT POS, Motor0, 0
MVP ABS, Motor0, Position0
WAIT POS, Motor0, 0
JA MainLoop