MDrive/MForce – Toggle program

Example program to show how to use one momentary input to toggle between different functions.

'****Declare Variables****
S1=0,0,0 'I/O 1 Input
VA V1=0 'Declare Variable V1
VA V2=0 'Declare Variable V1

'****Program****
PG 1

LB P1
BR L1, I1=1 'Branch to Label L1 if Input 1 is active
H 10 'Hold 10ms
CL L4, I1=0 'Branch to Label L4 if Input 1 is active
BR P1 'Loop back

LB L1 'Set Output Routine
H 10
BR P1, V2=1 'Only run sub on 1st iteration of Input
CL L2,V1=0 'Call L2 if first toggle
CL L3,V1=1 'Call L3 if second toggle
V1=!V1+2 'Toggle Variable
BR P1 'Return to Main Loop

LB L2
SL 50000 'Jog
V2=1 'Set active bit for debounce
RT

LB L3
SL 0 ' Close Position
V2=1 'Set active bit for debounce
RT

LB L4
V2=0
RT

E
PG

 


Download Toggle_Demo.mxt file
(color-coded in IMS Terminal)

 

> Motion Control Code Index