Beruflich Dokumente
Kultur Dokumente
Counter Delay
You will often want a small delay after a PLC commands an action or sets an I/O. A simple
counter can be used for this but you should be aware of the risks. Counters work at the speed
of the PMAC CPU and therefore are not of a fixed time. If the delay time needs to be a fixed
time or portable to different PMAC CPU speeds or firmware versions a Timer Delay is a
better option.
Here is the logical structure of a counter delay and some sample PMAC code.
To write this in PMAC code we
could do the following:
START
V AR IAB L E = INITIA L V A LU E
P100 = 0
WHILE(P100 < 1000)
P100 = P100 + 1
M10 = 1
ENDW
M10=0
WHILE
VARIABLE < LIMIT
True
V A RIAB L E = V A RIA BL E + 1
P erform de sired a ctio ns
False
P erfo rm de sired action s
END
Timer Delay
You will often want a small delay after a PLC commands an action or sets an I/O. A Timer
Delay is a good option when the delay is always at least X msec. Timers work independent of
the speed of the PMAC CPU and are therefore portable to different PMAC CPU speeds or
firmware versions. A Timer Delay is a better option than a Counter Delay. If the time for the
commanded I/O or action to actually take place can vary greatly then a Conditional Delay
could be a better option.
To write this in PMAC code we could do the following setup. First point an M-variable to a
timer register. These are found in the memory map in the PMAC Manual.
M10->X:$0700,0,24,S
Here is the logical structure of a timer delay and some sample PMAC code.
START
M10=1000*8388607/I10
WHILE(M10 > 0)
ENDW
WHILE
TIMER REGISTER > 0
True
False
P erfo rm de sire d actio ns
END
Conditional Delay
You will often want a small delay after a PLC commands an action or sets an I/O. A
Conditional Delay is a good option when the delay time varies due to external factors.
Conditional Delays work independent of the speed of the PMAC CPU and are therefore
portable to different PMAC CPU speeds or firmware versions. A Conditional Delay works
using a feedback principle. When action or I/O is commanded the PLC waits for another
event which means the action actually happened.
Page 2 of 19
To use a Conditional Delay you must therefore have an event that can be used as the
feedback. This event is usually either an I/O or an internal PMAC Status bit. When a
Conditional Delay is used you must also consider what happens if the condition never
happens. Do you timeout of the condition or do you stay locked in it forever?
To write this we will need to setup 2 M-variables, one for a timer and another for the
condition. Let us choose the DESIRED VELOCITY ZERO motor status bit for the condition.
Then the setup is done like this.
M10->X:$0700,0,24,S
M133->X:$003D,13,1
Now the code and logical structure are as follows:
We will consider the action to
do was JOG a motor. The
PMAC code would be like
this. And if the motion does
not happen in 3 seconds we
wish all motors to be killed.
CMD#1J+
M10=3000*8388607/I10
WHILE(M133=1)
AND(M10>0)
ENDW
IF(M10<0)
CMD^K
ENDIF
START
W HIL E
TIMER RE GISTE R > 0
A ND
CONDITION = FAL SE
True
False
Perform desired actions
END
Page 3 of 19
START
IF
CONDITION = TRUE
AND
LATCH = FALSE
IF
False
CONDITION = FALSE
AND
LATCH != FALSE
True
LATCH = TRUE
False
True
LATCH = FALSE
END
Combining Structures
Now that the building blocks are in place how should they be combined? To decide ask
yourself about the purpose of this program. Will it start and stop several actions that are
basically independent of each other or should it execute sequentially to control some sort of
process? We will refer to independent operations as an I/O Read/Write. Examples of I/O
Read/Write are an operator control panel. This panel will have switches that control jogging,
coolant, etc. For a sequential process think of homing a milling machine. First you pull the
cutting heads up, then you home the axes, and then you move to your offsets.
Page 5 of 19
Page 6 of 19
START
IN_MIRROR = INPUTS
M1->Y:$FFC2,0,1
M11->Y:$FFC2,8,1
And the PMAC code is:
IN_MIRROR != OLD_IN_MIRROR
False
True
OLD_IN_MIRROR = IN_MIRROR
IF(P11!=M11)
P11=M11
IF(P11=1)
P1=1
ENDIF
IF(P11=0)
P1=0
ENDIF
M1=P1
ENDIF
Process inputs
Build output word
Perform desired actions
OUTPUTS = OUT_MIRROR
END
IN_MIRROR = INPUTS
Now the state of P11 will be constant for the
IF(IN_MIRROR != OLD_IN_MIRROR)
entire scan of this PLC.
OLD_IN_MIRROR = IN_MIRROR
{process inputs using IN_MIRROR}
{build output word OUT_MIRROR}
{actions}
OUTPUTS = OUT_MIRROR
ENDIF
Process Control
Another way to think of Process Control is to think of a State Machine. A machine in which
you always start at state 1 and you can not advance to the next state until some condition is
satisfied. It is a combination of Conditional Delays.
To combine Conditional Delays into a state machine you should reserve a variable to store
the value of the current state. This is not required but is very useful for debugging and
monitoring the process. And the power of state machine programming is the ease of
debugging it affords. The logical flow of a 3state system follows
IF(START_CONDITION = TRUE)
STATE = 1
Page 7 of 19
;
;
;
;
;
;
;
;
;
;
;
;
;
MACHINE INPUT 1
#1 HMFL STATUS
#1 +LIM STATUS
#1 DESIRED VELOCITY ZERO
#1 HOME COMPLETE
#2 HMFL STATUS
#2 +LIM STATUS
#1 DESIRED VELOCITY ZERO
#2 HOME COMPLETE
#3 HMFL STATUS
#3 +LIM STATUS
#1 DESIRED VELOCITY ZERO
#1 HOME COMPLETE
Page 8 of 19
M120 = 1)
;state finished
;clear flag
;do home move
;wait for motion stopped
;state finished
1)
;past mark?
;move off sensor
;wait for start
0)
M220 = 1)
1)
;past mark?
;move off sensor
;wait for start
0)
M145 = 0
M245 = 0
CMD#1HM #2HM
WHILE(P1 = 4)
IF(M145 = 1 AND M133 = 1)
AND(M245 = 1 AND M233 = 1)
P1 = 5
ENDIF
ENDW
;state finished
;clear flag
;clear flag
;do home move
;wait for motion stopped
;state finished
Page 9 of 19
;state finished
WHILE(P1 = 6)
IF(M133 = 1 AND M233 = 1 AND M333 = 1) ;motion stopped?
P1 = 7
;state finished
ENDIF
ENDW
ENDIF
INP_01_M
INP_01_ADR
INP_02_M
INP_02_ADR
M20
Y:$FFC0,8,1
M21
Y:$FFC0,9,1
Page 10 of 19
INP_03_M
INP_03_ADR
INP_04_M
INP_04_ADR
INP_05_M
INP_05_ADR
INP_06_M
INP_06_ADR
INP_07_M
INP_07_ADR
INP_08_M
INP_08_ADR
INP_09_M
INP_09_ADR
INP_10_M
INP_10_ADR
INP_11_M
INP_11_ADR
INP_12_M
INP_12_ADR
#define INP_WORD_P
#define INP_CHANGE_P
#define INP_LATCH_P
M22
Y:$FFC0,10,1
M23
Y:$FFC0,11,1
M24
Y:$FFC0,12,1
M25
Y:$FFC0,13,1
M26
Y:$FFC0,14,1
M27
Y:$FFC0,15,1
M28
Y:$FFC0,16,1
M29
Y:$FFC0,17,1
M30
Y:$FFC0,18,1
M31
Y:$FFC0,19,1
P1
P2
P3
; Prejog Input
; Start (Run) Input
; Step/Quit Input
; Stop (Abort) Input
; Home Command Input
; Feed Hold Input
; Motor/C.S. Select Bit 0
; Motor/C.S. Select Bit 1
; Motor/C.S. Select Bit 2
; Motor/C.S. Select Bit 3
Page 11 of 19
INP_LATCH_P & 1 != 1)
| 1
AND INP_LATCH_P & 1 = 1)
& (INP_LATCH_P^1)
INP_LATCH_P & 2 != 2)
| 2
AND INP_LATCH_P & 2 = 2)
& (INP_LATCH_P^2)
INP_LATCH_P & 4 != 4)
| 4
AND INP_LATCH_P & 4 = 4)
& (INP_LATCH_P^4)
INP_LATCH_P & 8 != 8)
| 8
AND INP_LATCH_P & 8 = 8)
& (INP_LATCH_P^8)
Page 12 of 19
ENDIF
CLOSE
The rest of the programming techniques in this program have been covered earlier. So here is
the PLC.
CLOSE
ENDG
DEL GAT
#DEFINE
#DEFINE
#DEFINE
#DEFINE
#DEFINE
#DEFINE
INP_ALL_M
INP_ALL_ADR
MEM_INP_ALL_M
MEM_INP_ALL_ADR
INP_LATCH_M
INP_LATCH_ADR
M50
M51
D:$770
M52
D:$771
Page 13 of 19
MEM_MASK_01
MEM_MASK_02
MEM_MASK_03
MEM_MASK_04
MEM_MASK_05
MEM_MASK_06
MEM_MASK_07
MEM_MASK_08
MEM_MASK_09
MEM_MASK_10
MEM_MASK_11
MEM_MASK_12
MEM_MASK_13
MEM_MASK_14
MEM_MASK_15
MEM_MASK_16
MEM_MASK_17
MEM_MASK_18
MEM_MASK_19
MEM_MASK_20
MEM_MASK_21
MEM_MASK_22
MEM_MASK_23
MEM_MASK_24
MEM_MASK_25
MEM_MASK_26
MEM_MASK_27
MEM_MASK_28
MEM_MASK_29
MEM_MASK_30
MEM_MASK_31
MEM_MASK_32
MEM_MASK_33
MEM_MASK_34
MEM_MASK_35
MEM_MASK_36
MEM_MASK_37
MEM_MASK_38
MEM_MASK_39
MEM_MASK_40
MEM_MASK_41
MEM_MASK_42
MEM_MASK_43
MEM_MASK_44
MEM_MASK_45
MEM_MASK_46
MEM_MASK_47
MEM_MASK_48
$1
$2
$4
$8
$10
$20
$40
$80
$100
$200
$400
$800
$1000
$2000
$4000
$8000
$10000
$20000
$40000
$80000
$100000
$200000
$400000
$800000
$1000000
$2000000
$4000000
$8000000
$10000000
$20000000
$40000000
$80000000
$100000000
$200000000
$400000000
$800000000
$1000000000
$2000000000
$4000000000
$8000000000
$10000000000
$20000000000
$40000000000
$80000000000
$100000000000
$200000000000
$400000000000
$800000000000
Page 14 of 19
Page 15 of 19
Page 16 of 19
Page 17 of 19
Page 18 of 19
ENDIF
CLOSE
Page 19 of 19