User manual

TMCM-1140 TMCL Firmware V1.19 Manual (Rev. 1.01 / 2012-JUL-27) 44
www.trinamic.com
3.6.20 CSUB (call subroutine)
This function calls a subroutine in the TMCL program memory. It is intended for standalone operation only.
The host address and the reply are only used to take the instruction to the TMCL program memory while
the program loads down. This command cannot be used in direct mode.
Internal function: The actual TMCL program counter value is saved to an internal stack, afterwards
overwritten with the passed value. The number of entries in the internal stack is limited to 8. This also
limits nesting of subroutine calls to 8. The command will be ignored if there is no more stack space left.
Related commands: RSUB, JA
Mnemonic: CSUB <Label>
Binary representation:
INSTRUCTION NO.
TYPE
MOT/BANK
VALUE
23
(don't care)
(don't care)
<subroutine address>
Example: Call a subroutine
Loop: MVP ABS, 0, 10000
CSUB SubW //Save program counter and jump to label SubW
MVP ABS, 0, 0
JA Loop
SubW: WAIT POS, 0, 0
WAIT TICKS, 0, 50
RSUB //Continue with the command following the CSUB command
Binary format of the CSUB SubW command assuming that the label SubW is at address 100:
Byte Index
0
1
2
3
4
5
6
7
Function
Target-
address
Instruction
Number
Type
Motor/
Bank
Operand
Byte3
Operand
Byte2
Operand
Byte1
Operand
Byte0
Value (hex)
$01
$17
$00
$00
$00
$00
$00
$64