MDrive Example Program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | 'MDRIVE DEMO PROGRAM 'Last modified 08/25/2016 'Sample test program for demonstration purposes only 'Not tested or verified for safety or any function CP 'preclear program memory '*****Turntable Program***** 'Find shortest route to absolute position '***Operation*** 'Enter desired position in .01 deg (180 deg = 18000)into 'V1 variable (V1=18000) 'Execute program at address 1 (EX 1) 'This program sets up a matrix to find distance and Direction 'It compares whether the Current Position is > than 'the Requested Position and Whether the requested move is '>180 deg. 'Move < 180 deg AND CurPos>ReqPos = CCW 'Move < 180 deg AND CurPos<ReqPos = CW 'Move > 180 deg AND CurPos>ReqPos = CW 'Move > 180 deg AND CurPos<ReqPos = CCW '****Variable Declarations**** Ms=180 'Set to 36000 steps/rev (.01 deg) VA V1 'Requested Position Setpoint VA V2 'Move Amount VA V3 'Move Direction VA V4 VA V5 'Final Move Setpoint VA V6 'Current Pos VS Requested Pos Matrix value VA V7 'Move Amount >180 deg Matrix value VA V8 'Matrix Resolution Value '****Program**** PG 1 ' Start program LB L1 V2=P-V1 'Find the Move Distance 'PR "v2="v2 BR L2,V2<0 'Branch if Current Pos<Requested Pos V6=1 'Set Matrix Value if CurPos>ReqPos LB L3 'Move Routine BR L5, V2>18000 'Branch if move is > 180 deg V7=0 'Set Matrix Value if Move < 180 deg LB L10 BR L8 'Branch to Matrix resolution LB L6 V5=V3*V2 'Final Move = Distance*Polarity MR V5 'Mave Move CL L7 'Wait until Move Complete P=V1 'Set Current Position to Absolute BR L4 'Go to finish LB L2 'Current Position>Requested Position V2=V2*-1 'ABS Move distance V6=0 'Set Matrix Value BR L3 'Branch back to Move Routine LB L5 'Shortest Distance Routine V2=36000-V2 'Set Shortest distance if move > 180 deg V7=1 ' Set >180 deg Matrix value BR L10 ' Return to Move Routine LB L8 'Matrix Resolution V8=V6+V7 'Find sum of Matrix Values BR L9,V8=1 'Branch if move should be CCW V3=1 'Set move flag to be CW BR L6 'Return to Move Routine LB L9 'Set CCW Move V3=-1 'Set move flag to be CCW BR L6 'Return to Move Routine LB L7 'Wait for Move Complete H 10 '10ms Hold BR L7, Mv=1 'Loop if still Moving RT 'Return LB L4 'Finish E PG |