10.13 INSTRUCTION TYPES
There are basic categories of instructions,
The reader should be aware that some functions are positive edge triggered (i.e. they only work the scan is active). while most are active any time the input is active. Some examples of edge triggered and non-edge triggered functions are listed below,
10.13.1 Program Control Structures
These change the flow of execution of the ladder logic.
10.13.2 Branching and Looping
These functions allow control found in languages like Fortran
MCR blocks have been used earlier, but they are worth mentioning again.
Block of ladder logic can be bypassed using a jump statment.
Subroutines allow reusable programs to be written and called as needed. They are different from jump statements because they are not part of the main program (they are other program files), and arguments can be passed and returned.
For next loops can also be done to repeat blocks of ladder logic inside a single scan. Care must be used for this instruction so that the ladder logic does not get caught in an infinite, or long loop - if this happens the PLC will experience a fault and halt.
Ladder logic programs always have an end statement, but it is often taken for granted and ignored. Most modern software automatically inserts this. Some PLCs will experience faults if this is not present.
There is also a temporary end (TND) that for a single ladder scan will skip the remaining portion of a program.
A one shot contact can be used to turn on a ladder run for a single scan. When the run has a positive rising edge the oneshot will turn on the run for a single scan. Bit `B3:0' is used here to track to rung status.
10.13.2.1 - Immediate I/O Instructions
This approach avoids problems caused by logic setting and resetting outputs before done.
If we have a problem we may want to update an output immediately, and not wait for the PLC to complete its scan of the ladder logic. To do this we use immediate inputs and outputs.
10.13.2.2 - Fault Detection and Interrupts
The PLC can be set up to run programs automatically. This is normally done for a few reasons,
Two types of errors will occur - terminal (critical) and warnings (non-critical). A critical failure will normally stop the PLC.
In some applications faults and failures must be dealt with in logic if possible, if not the system must be shut down.
There are some memory locations that store indications of warning and fatal errors that have occurred. The routine in program file [S:29] needs to be able to detect and clear the fault.
To set a timed interrupt we will set values in the status memory as indicated below. The program in file [S:31] will be run every [S:30]ms.
To cause an interrupt when a bit changes the following bits can be set.
10.13.3 Basic Data Handling
Some handy functions found in PLC-5's (similar functions are available in other PLC's)
10.13.3.1 - Move Functions
There are two types of move functions,
MVM(value,mask,destination) - moves a value to a memory location, but with a mask to select specific bits.
The following function moves data values between memory locations. The following example moves a floating point number from floating point memory 7 to 23
The following example moves a floating point number from floating point memory F8:7 to integer memory N7:23
The following example puts an integer value 123 in integer memory N7:23
A more complex example of the move functions follows,