PMAC Quick Reference Guide To erase an uncompiled PLC program, open the buffer, clear the contents, then close the buffer again. This can be done with three commands on one line, as in: OPEN PLC 5 CLEAR CLOSE PLC Program Structure The important thing to remember in writing a PLC program is that each PLC program is effectively in an infinite loop; it will execute over and over again until told to stop.
(These are called PLC because of the similarity in how they operate to hardware Programmable Logic Controllers – the repeated scanning through a sequence of operations and potential operations.) 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)) could 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 our 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 to trigger the action is needed. 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. Our code would 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 63