User manual

PDx-113-57/60-SE / TMCM-113-57/60-SE Firmware Manual (V1.10 / 2009-OCT-28) 58
Copyright © 2009, TRINAMIC Motion Control GmbH & Co. KG
6.7.20 CSUB (call subroutine)
This function calls a subroutine in the TMCL
TM
program memory. It is intended for stand-alone operation
only.
Note that the host address and the reply is only used to transfer this instruction to the TMCL
TM
program
memory. This command cannot be used in direct mode.
Internal function: The actual TMCL
TM
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
8
Function
Target-
address
Instruction
Number
Type
Motor/
Bank
Operand
Byte3
Operand
Byte2
Operand
Byte1
Operand
Byte0
Checksum
Value (hex)
$01
$17
$00
$00
$00
$00
$00
$64
$7c