User Manual

PD-x-1670 TMCL
Firmware Manual Firmware Version V2.0 | Document Revision V1.0 2018-Oct-29
76 / 82
Please see the following example:
1 M y Variable = 42
// Use a symbolic name for the user variable
3 // ( This makes the program better re adable and un derstandab l e .)
5 SGP MyVariable , 2, 1234 // I n i t ialize the va r iable with the value 1234
...
7 ...
GGP MyVariable , 2 // Copy conte nts of variable to accumulator register
9 CALC MUL , 2 // Multipl y a c c u m u l a t o r r egister with two
AGP MyVariable , 2 // Store contents of accumulator register to variabl e
11 ...
...
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.
7.6 Combining Direct Mode and Standalone Mode
Direct mode and standalone mode can also be combined. When a TMCL program is being executed in
standalone mode, direct mode commands are also processed (and they do not disturb the ow of the
program running in standalone mode). So, it is also possible to query e.g. the actual position of the motor
in direct mode while a TMCL program is running.
Communication between a program running in standalone mode and a host can be done using the TMCL
user variables. The host can then change the value of a user variable (using a direct mode SGP command)
which is regularly polled by the TMCL program (e.g. in its main loop) and so the TMCL program can react
on such changes. Vice versa, a TMCL program can change a user variable that is polled by the host (using a
direct mode GGP command).
A TMCL program can be started by the host using the run command in direct mode. This way, also a set
of TMCL routines can be dened that are called by a host. In this case it is recommended to place JA
commands at the beginning of the TMCL program that jump to the specic routines. This assures that
the entry addresses of the routines will not change even when the TMCL routines are changed (so when
changing the TMCL routines the host program does not have to be changed).
Example:
©2018 TRINAMIC Motion Control GmbH & Co. KG, Hamburg, Germany
Terms of delivery and rights to technical change reserved.
Download newest version at www.trinamic.com