User manual

TMCM-1140 TMCL Firmware V1.19 Manual (Rev. 1.01 / 2012-JUL-27) 82
www.trinamic.com
Just have a look at the file TMCLParam.tmc provided with the TMCL-IDE. It contains symbolic constants
that define all important parameter numbers.
Using constants for other values makes it easier to change them when they are used more than once in a
program. You can change the definition of the constant and do not have to change all occurrences of it in
your program.
7.4 Using Variables
The User Variables can be used if variables are needed in your program. They can store temporary values.
The commands SGP, GGP and AGP are used to work with user variables:
SGP is used to set a variable to a constant value (e.g. during initialization phase).
GGP is used to read the contents of a user variable and to copy it to the accumulator register for further
usage.
AGP can be used to copy the contents of the accumulator register to a user variable, e.g. to store the
result of a calculation.
Example:
MyVariable = 42
//Use a symbolic name for the user variable
//(This makes the program better readable and understandable.)
SGP MyVariable, 2, 1234 //Initialize the variable with the value 1234
...
...
GGP MyVariable, 2 //Copy the contents of the variable to the
accumulator register
CALC MUL, 2 //Multiply accumulator register with two
AAP MyVariable, 2 //Store contents of the accumulator register to the
variable
...
...
Furthermore, these variables can provide a powerful way of communication between a TMCL program
running on a module and a host. The host can change a variable by issuing a direct mode SGP command
(remember that while a TMCL program is running direct mode commands can still be executed, without
interfering with the running program). If the TMCL program polls this variable regularly it can react on
such changes of its contents.
The host can also poll a variable using GGP in direct mode and see if it has been changed by the TMCL
program.
7.5 Using Subroutines
The CSUB and RSUB commands provide a mechanism for using subroutines. The CSUB command branches
to the given label. When an RSUB command is executed the control goes back to the command that
follows the CSUB command that called the subroutine.
This mechanism can also be nested. From a subroutine called by a CSUB command other subroutines can
be called. In the current version of TMCL eight levels of nested subroutine calls are allowed.