MDrive/MForce – Speed Control with analog input
This program demonstrates a typical application using the MDrive analog input. The voltage or current present on Input 5 is converted to a decimal value of 0 to 1023. In this case, the I5 voltage value is manipulated to determine speed, direction and deadband.
'This program allows the user to perform speed control
'using the analog input on the MDI.
'R1 analog input work register
'R2 direction
'R3 slew value
'R4 deadband
S5=9,0 'sets analog input to accept 0-5Vdc.
S1=0,1 'sets I/O point 1 to general purpose input
A=2000000 'accel set to 2000000 microsteps/sec/sec
D=A 'decel set to accel
R4=20 'deadband set to 20
PG 1 'initiate program mode at address 1
LB SU 'SU label. Program executes on power up
R1 = I5 'register 1 set to analog input value
CL AB 'computes new velocity in subroutine at AB
SL R3 'slew at the value of register 3
H 10 'wait 10 milliseconds
BR SU 'branch to the label called SU
E 'end of main routine
LB AB 'label called AB
R1 = R1-508 'routine to determine direction & deadband
R2 = 1 'offset from joystick center plus
BR A1, R1>=0 'get dir of R1
R2 = -1 'negative direction minus
R1 = R1 * R2 'get abs of R1
LB A1 'label called A1
BR A2, R1 < R4 'check that value is greater than DB
R1 = R1 * 2500 'scale value in R1
R3 = R1 * R2 'set slew value with value and sign
LB A3 'label called A3
RT 'return from subroutine use only after CL
LB A2 'label called A2
R3 = 0 'if value is less than DB then Slew is 0
BR A3
PG
S
Download Speed Control with Analog Input
.mxt file
(color-coded in IMS Terminal)