eNotes: Mechatronics and Controls

   



TOC PREV NEXT

24.2 INSTRUCTION TYPES


There are basic categories of instructions,

Basic (discussed before)
- relay instructions
- timer instructions
- counter instructions
Program Control
- branching/looping
- immediate inputs/outputs
- fault/interrupt detection
Basic Data Handling
- moves
- computation instructions
- boolean instructions
- conversion
Logical
- comparisons
Advanced Data Handling
- file instructions
- shift registers/stacks
Complex
- PID
- communications
- high speed counters
- ASCII string functions

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,

Edge Triggered
CTU, CTD
Non-edge triggered
TON, TRO, TOF, ADD, MUL, etc.

24.2.1 Basic Data Handling

Some handy functions found in PLC-5's (similar functions are available in other PLC's)

24.2.1.1 - Move Functions

There are two types of move functions,

MOV(value,destination) - moves a value to a memory location
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,



24.2.1.2 - Mathematical Functions

These functions use values in memory, and store the results back in memory (Note: these functions do not use variables like normal programming languages.)

Math functions are quite similar. The following example adds the integer and floating point number and puts the results in `F8:36'.



Basic PLC-5 math functions include,

ADD(value,value,destination) - add two values
SUB(value,value,destination) - subtract
MUL(value,value,destination) - multiply
DIV(value,value,destination) - divide
NEG(value,destination) - reverse sign from positive/negative
CLR(value) - clear the memory location

Consider the example below,



As an exercise, try the calculation below with ladder logic,



Some intermediate math functions include,

CPT(destination,expression) - does a calculation
ACS(value,destination) - inverse cosine
COS(value,destination) - cosine
ASN(value,destination) - inverse sine
SIN(value,destination) - sine
ATN(value,destination) - inverse tangent
TAN(value,destination) - tangent
XPY(value,value,destination) - X to the power of Y
LN(value,destination) - natural log
LOG(value,destination) - base 10 log
SQR(value,destination) - square root

Examples of some of these functions are given below.





For practice implement the following function,



Some functions are well suited to statistics.

AVE(start value,destination,control,length) - average of values
STD(start value,destination,control,length) - standard deviation of values
SRT(start value,control,length) - sort a list of values

Examples of these functions are given below.



There are also functions for basic data conversion.

TOD(value,destination) - convert from BCD to binary
FRD(value,destination) - convert from binary to BCD
DEG(value,destination) - convert from radians to degrees
RAD(value,destination) - convert from degrees to radians

Examples of these functions are given below.



24.2.2 Logical Functions

24.2.2.1 - Comparison of Values

These functions act like input contacts. The equivalent to these functions are if-then statements in traditional programming languages.

Basic comparison functions in a PLC-5 include,

CMP(expression) - compares two values for equality
EQU(value,value) - equal
NEQ(value,value) - not equal
LES(value,value) - less than
LEQ(value,value) - less than or equal
GRT(value,value) - greater than
GEQ(value,value) - greater than or equal

The comparison function below compares values at locations A and B. If they are not equal, the output is true. The use of the other comparison functions is identical.



More advanced comparison functions in a PLC-5 include,

MEQ(value,mask,threshold) - compare for equality using a mask
LIM(low limit,value,high limit) - check for a value between limits

Examples of these functions are shown below.



24.2.2.2 - Binary Functions

These functions allow Boolean operations on numbers and values in the PLC memory.

Binary functions are also available for,

AND(value,value,destination) - Binary and function
OR(value,value,destination) - Binary or function
NOT(value,value,destination) - Binary not function
XOR(value,value,destination) - Binary exclusive or function

Examples of the functions are,



24.2.3 Boolean Operations

In most discrete systems the inputs and outputs (I/O) are either on or off. This is a binary state that will be represented with,

1 = on

0 = off

Because there are many inputs and outputs, these can be grouped (for convenience) into binary numbers.

Consider an application of binary numbers. There are three motors M1, M2 and M3

100 = Motor 1 is the only one on
111 = All three motors are on
in total there are 2n or 23 possible combinations of motors on.

The most common Binary operations are,



24.2.4 Binary Mathematics

These include standard logic forms such as,

- and/or/add, etc.
- compliments

Negative numbers are a particular problem with binary numbers. As a result there are two common numbering systems use,

- signed binary - the most significant bit (MSB) of the binary number is used to indicate positive/negative
- 2s compliment - negative numbers are represented by complimenting the binary number and then adding 1.

Signed binary numbers are easy to understand, but much harder to work with when doing calculations.

An example of 2s compliments are given below,



When adding 2s compliment numbers, additional operations are not needed to deal with negative numbers. Consider the examples below,



24.2.5 BCD (Binary Coded Decimal)

Each digit is encoded in 4 bits



This numbering system makes poor use of the digits, but is easier to convert to/from base 10 numbers. For the two bytes above the maximum numbers possible are from 0-9999 in BCD, but 0-64285 in binary.

Convert the BCD number below to a decimal number,



Convert the following binary number to a BCD number,



24.2.6 Advanced Data Handling

24.2.6.1 - Multiple Data Value Functions

We can also deal with large `chunks' of memory at once. These will not be covered, but are available in texts. Some functions include,

- move/copy memory blocks
- add/subtract/multiply/divide/and/or/eor/not/etc blocks of memory

These functions are similar to single value functions, but they also include some matrix operations. For a PLC-5 a matrix, or block of memory is also known as an array.

The basic functions are,

FAL(control,length,mode,destination,expression) - will perform basic math operations to multiple values.
FSC(control,length,mode,expression) - will do a comparison to multiple values
COP(start value,destination,length) - copies a block of values
FLL(value,destination,length) - copies a single value to a block of memory

These functions are done on a PLC-5 using file commands. Typical operations include

file to file - copy an array of memory from one location to another.
element to file - one value is copied to a block of memory
file to element - can convert between data types
file add - add arrays
file subtract - subtract arrays
file multiply - multiply arrays
file divide - divide an array by a value
convert to/from BCD
AND/OR/XOR/NOT - perform binary functions.

Examples of these functions are shown below.



a useful function not implemented on PLC-5 processors is a memory exchange.

24.2.7 Complex Functions

24.2.7.1 - Shift Registers

The values can be shifted left or right with the following functions.

BSL - shifts left from the LSB to the MSB. The LSB must be supplied
BSR - similar to the BSL, except the bit is input to the MSB and shifted to the LSB

These use bit memory blocks of variable length.

An example of a shift register is given below. In this case it is taking the value of bit B3:1/0 and putting it in the control word bit R6:2/UL. It then shifts the bits once to the right, B3:1/0 = B3:1/1 then B3:1/1 = B3:1/2 then B3:1/2 = B3:1/3 then B3:1/3 = B3:1/4. Then the input bit is put into the most significant bit B3:1/4 = I:000/00.



There are other types of shift registers not implemented in PLC-5s.



24.2.7.2 - Stacks

We can also use stack type commands. These allow values to be stored in a `pile'. This allows us to write programs that will accumulate values that can be used later, or in sequence.

The basic concept of a FIFO stack is that the first element in is the first element out.

The PLC-5 commands are FFL to load the stack, and FFU to unload it.

The example below shows two instructions to load and unload the stack. The first time FFL is activated it will grab all of the bits from the input card I:001 and store them on the stack, at N7:0. The next value would be at N7:1, and so on until the stack length is met. When FFU is used the value at N7:0 will be moved to set all of the bits on the output card O:003 and the values on the stack will be shifted up so that the value previously in N7:1 is now in N7:0, etc. (note: the source and destination do not need to be inputs and outputs)



A Last-In-First-Out stack can also be used with the LFL/LFU functions.

24.2.7.3 - Sequencers

Basically, sequencers are a method for using predetermined patterns to drive a process

These were originally based on motor driven rotating cams that made and broke switches. When a number of these cams were put together, they would be equivalent to a binary number, and could control multiple system variables.



A sequencer can keep a set of values in memory and move these to memory locations (such as an output card) when directed.

These are well suited to state diagrams/processes with a single flow of execution (like traffic lights)

The commands are,

SQO(start,mask,source,destination,control,length) - sequencer output from table to memory address
SQI(start,mask,source,control,length) - sequencer input from memory address to table
SQL(start,source,control,length) - sequencer load to set up the sequencer parameters

An example of a sequencer is given below for traffic light control. The light patterns are stored in memory (entered manually by the programmer). These are then moved out to the output card as the function is activated. The mask (003F = 0000000000111111) is used so that only the 6 LSB are changed.



24.2.8 Program Control Structures

These change the flow of execution of the ladder logic.

24.2.8.1 - Branching and Looping

These functions allow control found in languages like Fortran

IF-THEN is like MCR (Master Control Reset)
GOTO is like JMP (Jump)
SUBROUTINES is like Program Files

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.



24.2.8.2 - 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.



24.2.8.3 - Fault Detection and Interrupts

The PLC can be set up to run programs automatically. This is normally done for a few reasons,

- to deal with errors that occur (eg. divide by zero)
- to run a program at a regular timed interval (eg. SPC calculations)
- to respond when a long instruction is complete (eg. analog input)
- when a certain input changed (eg. panic button)

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.

S:29 - program file number to run when a fault occurs

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.

S:30 - timed delay between program execution - an integer number of ms
S:31 - the program number to be run

To cause an interrupt when a bit changes the following bits can be set.

S:46 - the program file to run when the input bit changes
S:47 - the rack and group number (eg. if in the main rack it is 000)
S:48 - mask for the input address (eg. 0000000000000100 watches 02)
S:49 - for positive edge triggered =1 for negative edge triggered = 0
S:50 - the number of counts before the interrupt occurs 1 = always up to 32767

24.2.9 Block Transfer Functions

Certain PLC cards only have a single address (eg. O:001 or I:001) but multiple data values need to be read or written to it. To do this the block transfer functions are used.

These will be used in the labs for analog input/output cards.

These functions will take more than a single scan, and so once activated they will require a delay until they finish.

To use the write functions we set up a block of memory, the function shows this starting at N9:0, and it is 10 words long (this is determined by the special purpose card). The block transfer function also needs a control block of memory, this is BT10:1



To read values we use a similar method. In the example below 9 values will be read from the card and be placed in memory locations from N9:4 to N9:11.



TOC PREV NEXT

Search for More:

Custom Search