dear sir:
here a few codes list below to make motor ( drived by tmcl-140-42-232) turn left when the general input 0 is high level and turn right when the
general input 1 is high level (a left limit switch and a right switch are added,).
SGP 77, 0, 1
SAP 4, 0, 1000 //set maximum positioning speed
SAP 5, 0, 500 //set maximum acceleration speed
SAP 6, 0, 100 //set absolute maximum current
SAP 7, 0, 20 //set standby current
SAP 12, 0, 0 //right limit switch enable
SAP 13, 0, 0 //left limit switch enable
SAP 140, 0, 5 //set microstep resolution ,32 microsteps
SAP 153, 0, 7 //set ramp divisor ,2 exp 7
SAP 154, 0, 3 //set pulse divisor ,2 exp 3
SAP 195, 0, 4 //set home speed
SAP 193, 0, 3 //3,first search right ref switch
ROR 0, 1000 //speed 1000
WAIT LIMSW, 0, 0 //until limit switch is hit
//JC ETO, RefErr
MST 0 // stop motor 0
SAP 1, 0, 0 // set current position(actual position) 0
MVP REL, 0, -1500
WAIT POS, 0, 0
MST 0
SAP 1, 0, 0
//main program
LOOP1://first stop the motor
MST 0
GIO 0, 0 //get status of digital inputs 0 ,port number 0, bank number 0
COMP 1 //compare with 1
JC EQ, LEFTRUN //if status is 1,jump to leftrun,left move
GIO 1, 0 //get status of digital inputs 1
COMP 1 //compare with 1
JC EQ, RIGHTRUN //if status is 1,jump to rightrun,right move
JA LOOP1
LEFTRUN: GIO 0, 0 //leftrun subprogram
COMP 1 //compare with 1
JC NE, LOOP1 // if status is 0,jump to loop1
MVP ABS, 0, 0
WAIT POS, 0, 0
JA LEFTRUN
RIGHTRUN: GIO 1, 0 //right run subprogram
COMP 1 //compare with 1
JC NE, LOOP1
MVP ABS, 0, -10000
WAIT POS, 0, 0
JA RIGHTRUN
STOP
now if the upper pc want to know the current status of motor(send query instruction to general input 0 and 1,and output from general output 0 and
output 1 ),such as currently the motor is stopped right direction or stopped left direction when motor stopped(when the motor is stopped right direction ,sio 0 ,2 ,0;when the motor is stopped left direction ,sio 1,2 ,0).
what the program code like? thanks a lot!