250
Programming Examples
Appendix C
General Examples
Example 1: Turning an Output ON and OFF Every 100ms
The following code controls output 10 to go on and off every 100 ms.
loop:
OP(10, ON)
WA(100)
OP(10, OFF)
WA(100)
GOTO loop
Example 2: Flashing MC Unit Outputs
The following code will sequentially step through all available outputs on the MC Unit and flash them for 0.5
seconds each
start:
FOR a = 8 TO 13
OP(a, ON)
WA(500)
OP(a, OFF)
NEXT a
GOTO start
Example 3: Positioning a Rotary Table
A rotary table must stop at one of 8 equally spaced positions according to the value of a thumbwheel input
(inputs 4 to 7). The table will not move until a start button is pressed (input 10).
start:
WAIT UNTIL IN(10) = ON
WAIT UNTIL IN(10) = OFF
GOSUB get_tws
MOVEABS(45 * tw_value)
WAIT IDLE
GOTO start
get_tws:
tw_value = IN(4,7)
RETURN
Example 4: Positioning with Product Detection
A ballscrew is required to move forward at a creep speed until it reaches a product, at which point a
microswitch (IN(2)) is turned ON. The ballscrew is stopped immediately, the position at which the product was
sensed is indicated and the ballscrew is returned at a rapid speed back to the start position.
start:
IF ( IN(1) = ON ) THEN WAIT UNTIL IN(8) = OFF
WAIT UNTIL IN(1) = ON
SPEED = 10
FORWARD
WAIT UNTIL IN(2) = ON
prod_pos = MPOS
CANCEL
WAIT IDLE
PRINT "Product Position : "; prod_pos
SPEED = 100
MOVEABS(0)
WAIT IDLE
GOTO start