User`s manual

6.0 - PLC Programs
Page - 58
6.1 - Entering a PLC Program
- PLCs are programmed in the same way as motion programs are, in a text editor window for later downloading to
PMAC.
- Before start writing the PLC it is good practice to make sure that memory has not been tied up in data gathering or
program trace buffers, by issuing DELETE GATHER and DELETE TRACE commands.
- Open the buffer for entry with the OPEN PLC n statement, where n is the buffer number. Next, if there is anything
currently in the buffer that should not be kept, it should be emptied with the CLEAR statement (PLC buffers may not be
edited on the PMAC itself; they must be cleared and re-entered). If the buffer is not cleared, new statements will be
added onto the end of the buffer.
- When you are finished, you close the buffer with the CLOSE command. Opening a PLC program buffer automatically
disables that program. After it is closed, it remains disabled, but it can be re-enabled again with the ENABLE PLC n
command, where n is the buffer number (0--31). I5 must also be set properly for a PLC program to operate.
- At the closing, PMAC checks to make sure all IF branches and WHILE loops have been terminated properly. If not, it
reports an error, and the buffer is inoperable. You should then correct the PLC program in the host and re-enter it
(clearing the erroneous block in the process, of course). This process is repeated for all of the PLC buffers you wish to
use.
- Because all PLC programs in PMAC's memory are enabled at power-on/reset it is good practice to have I5 saved as 0
in PMAC's memory when developing PLC programs. This will allow you to reset PMAC and have no PLC's running
(an enabled PLC only runs if I5 is set properly) and more easily recover from a PLC programming error.
Structure example:
CLOSE
DELETE GATHER
DELETE TRACE
OPEN PLC n CLEAR
{PLC statements}
CLOSE
ENABLE PLC n
- To erase an uncompiled PLC program, you must open the buffer, clear the contents, then close the buffer again. This
can be done with 3 commands on one line, as in:
OPEN PLC 5 CLEAR CLOSE
6.2 - 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.)
6.3 - 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 very frequently, whoever needs access to this information (e.g. host computer, operator, motion
program) can be assured of having current data.