Delta Tau GEO BRICK LV User Manual

Page of 440
Turbo PMAC User Manual 
Writing and Executing PLC Programs
 
373
 
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.  It updates this frequently, so 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 Turbo PMAC variables such as 
inputs, outputs, positions, counters, etc.  The action should 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 
Suppose instead that you want to increment P1 only once for each time M11 goes true (triggering on the 
rising edge of M11 sometimes called a one-shot or latched).  We need a compound condition to trigger 
the action, then as part of the action, we 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 could become: 
IF (M11=1) 
  IF (P11=0) 
    P1=P1+1 
    P11=1 
  ENDIF 
ELSE 
  P11=0 
ENDIF