Figure 1。7 An Example of a Sequential Function Chart
Structured Text programming has been developed as a more modern programming language。 It is quite similar to languages such as BASIC。 A simple example is shown in Figure 1。8。 This example uses a PLC memory location i。 This memory location is for an integer, as will be explained later in the book。 The first line of the program sets the value to 0。 The next line begins a loop, and will be where the loop returns to。 The next line recalls the value in location i, adds 1 to it and returns it to the same location。 The next line checks to see if the loop should quit。 If i is greater than or equal to 10, then the loop will quit, otherwise the computer will go back up to the REPEAT statement continue from there。 Each time the program goes through this loop i will increase by 1 until the value reaches 10。
Figure 1。8 An Example of a Structured Text Program
2。1 PLC Connections
When a process is controlled by a PLC it uses inputs from sensors to make decisions and update outputs to drive actuators, as shown in Figure 2。1。 The process is a real process that will change over time。 Actuators will drive the system to new states (or modes of operation)。 This means that the controller is limited by the sensors available, if an input
is not available, the controller will have no way to detect a condition。
Figure 2。1 The Separation of Controller and Process
The control loop is a continuous cycle of the PLC reading inputs, solving the ladder logic, and then changing the outputs。 Like any computer this does not happen instantly。 Figure 2。2 shows the basic operation cycle of a PLC。 When power is turned on initially the PLC does a quick sanity check to ensure that the hardware is working properly。If there is a problem the PLC will halt and indicate there is an error。 For example, if the PLC power is dropping and about to go off this will result in one type of fault。 If the PLC passes the sanity check it will then scan (read) all the inputs。 After the inputs values are stored in memory the ladder logic will be scanned (solved) using the stored values not the current values。 This is done to prevent logic problems when inputs change during the ladder logic scan。 When the ladder logic scan is complete the outputs will be scanned (the output values will be changed)。 After this the system goes back to do a sanity check, and the loop continues indefinitely。 Unlike normal computers, the entire program will be run every scan。 Typical times for each of the stages is in the order of milliseconds。
Figure 2。2 The Scan Cycle of a PLC
2。2 Ladder Logic Inputs
PLC inputs are easily represented in ladder logic。 In Figure 2。3 there are three types of inputs shown。 The first two are normally open and normally closed inputs, discussed previously。 The IIT (Immediate InpuT) function allows inputs to be read after the input scan, while the ladder logic is being scanned。 This allows ladder logic to examine input values more often than once every cycle。 (Note: This instruction is not available on the ControlLogix processors, but is still available on older models。)
Figure 2。3 Ladder Logic Inputs
2。3 Ladder Logic Outputs
In ladder logic there are multiple types of outputs, but these are not consistently available on all PLCs。 Some of the outputs will be externally connected to devices outside the PLC, but it is also possible to use internal memory locations in the PLC。 Six types of outputs are shown in Figure 2。4。 The first is a normal output, when energized the output will turn on, and energize an output。 The circle with a diagonal line through is a normally on output。 When energized the output will turn off。 This type of output is not available on all PLC types。 When initially energized the OSR (One Shot Relay) instruction will turn on for one scan, but then be off for all scans after, until it is turned off。 The L (latch) and U (unlatch) instructions can be used to lock outputs on。 When an L output is energized the output will turn on indefinitely, even when the output coil is deenergized。 The output can only be turned off using a U output。 The last instruction is the IOT (Immediate OutpuT) The last instruction is the IOT (Immediate OutpuT)that will allow outputs to be updated without having to wait for the ladder logic scan to be completed。