Hello,
Has anyone experience issues writing a for loop in TMCL? I have used the script example from Github without success.
The rest of the script is working fine.
From what I can see, the global parameter at index 0 and bank 2 does not update when the CALC ADD function is run.
Or at least I don't see it increment in the local variable viewer.
Any ideas are most welcomed?
Code:
// select module
#module 1 COM6/USB/id1/LandungsbrueckeV3/TMC5160-EVAL
// *** Set variables *** //
vtarget = 2000
oscAngle = 12800 // oscAngle = angle(deg)/360 x 51200
loops = 5 // Number of oscilations
// set defaults
//SAP 1, 0, 0, 1 // set ref position to 0
SAP 6, 0, 1, 1 // max. current
SAP 7, 0, 3, 1 // max. standby current
//WMC SW_MODE, 0, $0000000F, 1 //0x34: R&L Ref inverted (active low)
SAP 4, 0, 20000, 1 // Maximum speed
SAP 5, 0, 2000, 1 // Maximum acceleration
SAP 15, 0, 1000, 1 // Acceleration A1
SAP 16, 0, 0, 1 // Velocity V1
SAP 17, 0, 2000, 1 // Maximum Deceleration
SAP 18, 0, 2000, 1 // Deceleration D1
SAP 19, 0, 0, 1 // Velocity VSTART
SAP 20, 0, 10, 1 // Velocity VSTOP
SAP 21, 0, 0, 1 // Waiting time after ramp down
// *** Reference search initialization *** //
SAP 12, 0, 0, 1 //don't set 'right limit switch disable'
SAP 13, 0, 0, 1 //don't set 'left limit switch disable'
SAP 149, 0, 0, 1 //set soft stop flag: 0 = hard stop, 1 = soft stop
SAP 193, 0, 2, 1 //set reference search mode
SAP 194, 0, vtarget, 1 //set reference search speed
SAP 195, 0, 10000, 1 //set reference switch speed
SGP 0, 2, 0, 1
// *** Find the flag by rotating left and then stop motor *** //
forLoop:
GAP 11, 0, 1 //get Left endstop
COMP 1 //compare with 1
JC EQ, positionOsc //if not equal stop motor
ROL 0, vtarget, 1 //if not equal turn left at vmax
JA forLoop
positionOsc:
MVP REL, 0, oscAngle/2, 1
WAIT POS, 0, 0, 1
MVP REL, 0, -oscAngle/2, 1
WAIT POS, 0, 0, 1
GGP 0, 2, 1 //get user variable #0 to accu
CALC ADD, 1 //add 1 to accu
AGP 0, 2, 1 //accu to user variable #0
COMP loops //amount of loops
JC GE, end //jump to label forLoop
JA positionOsc
end:
STOP
travisfcollins - Moved from Software Interface Tools to Other Products (EN). Post date updated from Wednesday, July 17, 2024 4:52 AM UTC to Wednesday, September 11, 2024 6:25 PM UTC to reflect the move.