PMAC Product Guide Calculation Statements Much of the action taken by a PLC is done through variable value assignment statements: {variable}={expression} . The variables can be I, P, Q, or M types and the action thus taken can affect many things inside and outside the card. Perhaps the simplest PLC program consists of one line: P1=P1+1 Every time the PLC executes, usually hundreds of times per second, P1 will increment by one. Of course, these statements can get a lot more involved. The statement: P2=M162/(I108*32*10000)*COS (M262/(I208*32*100)) can be converting radial (M162) and angular (M262) positions into horizontal position data, scaling at the same time.
Because it updates this frequently, whoever needs access to this information (e.g. host computer, operator, motion program) can be assured of having current data. Conditional Statements Most action in a PLC program is conditional, dependent on the state of PMAC variables, such as inputs, outputs, positions, counters, etc. Action can be level-triggered or edge-triggered; both can be done, but the techniques are different. Level-Triggered Conditions A branch controlled by a level- triggered condition is easier to implement. Taking the incrementing variable example and making the counting dependent on an input assigned to variable M11, we have:
IF (M11=1) P1=P1+1 ENDIF As long as the input is true, P1 will increment several hundred times per second. When the input goes false, P1 will stop incrementing. Edge-Triggered Conditions To increment P1 once for each time M11 goes true (triggering on the rising edge of M11 sometimes called a one-shot or latched). A compound condition is needed to trigger the action, then as part of the action, set one of the conditions false, so the action will not occur on the next PLC scan. The easiest way to do this is through the use of a shadow variable which will follow the input variable value. Action is taken only when the shadow variable does not match the input variable. The code could become:
IF (M11=1) IF (P11=0) P1=P1+1 P11=1 ENDIF ELSE P11=0 ENDIF Make sure that P11 can follow M11 both up and down. Set P11 to 0 in a level-triggered mode. PLC Programs 87