You are on page 1of 19

Chapter 5: Applied instructions

• Applied Instructions are the ‘specialist’ instructions of the


FX family of PLC’s.

• They allow the user to perform complex data


manipulations, mathematical operations while still being
very easy to program and monitor.

• Not all instructions and conditions apply to all PLC’s.

 C.B. Pham 5-1


Instruction groups

 C.B. Pham 5-2


5.1. Program flow

CJ Conditional jump FNC 00


CALL Call Subroutine FNC 01
SRET Subroutine Return FNC 02
IRET Interrupt Return FNC 03
EI Enable Interrupt FNC 04
DI Disable Interrupt FNC 05
FEND First End FNC 06
WDT Watchdog Timer FNC 07
FOR Start of a For/Next Loop FNC 08
NEXT End a For/Next Loop FNC 09

 C.B. Pham 5-3


5.1. Program flow

• CJ: Conditional jump.

- When the CJ instruction is active it


forces the program to jump to an
identified program marker. The resulting
effect is to speed up the programs
operational scan time.
- Many CJ statements can reference a single pointer. Each
pointer must have a unique number. Using pointer P63 is
equivalent to jumping to the END instruction.
 C.B. Pham 5-4
5.1. Program flow

• CALL: Call subroutine

- When the CALL instruction is active it


forces the program to run the subroutine
associated with the called pointer. A
CALL instruction must be used in
conjunction with FEND (FNC 06) and
SRET (FNC 02) instructions.

 C.B. Pham 5-5


5.1. Program flow

• FEND: indicate the end of the main program block.

- An FEND instruction indicates the first end of a main program and the
start of the program area to be used for subroutines. Commonly used:
CJ-P-FEND, CALL-P-SRET.
 C.B. Pham 5-6
5.1. Program flow

• FOR, NEXT: Repeat the loop.

- The FOR and NEXT instructions allow the specification of an area of


program, i.e. the program enclosed by the instructions, which is to be
repeated S number of times (from 1 to 32767)
 C.B. Pham 5-7
5.1. Program flow

• Note: bit devices can be grouped into 4 bit units

K1X0: X0 to X3 (4 bit devices with a head address of X0)


K1X6: X6 to X11 (4 bit devices with a head address of X6)
K3X0: X0 to X13 (12 bit devices with a head address of X0)
K8X0: X0 to X37 (32 bit devices with a head address of X0)
 C.B. Pham 5-8
5.2. Move and compare

CMP Compare FNC 10


ZCP Zone Compare FNC 11
MOV Move FNC 12
SMOV Shift Move FNC 13
CML Compliment FNC 14
BMOV Block Move FNC 15
FMOV Fill Move FNC 16
XCH Exchange FNC 17
BCD Binary Coded Decimal FNC 18
BIN Binary FNC 19

 C.B. Pham 5-9


5.2. Move and compare

• CMP: Compares two data values

- The data of S1 is compared to the


data of S2. The result is indicated
by 3 bit devices specified from the
head address entered as D. The bit
devices indicate:
• [S2] < [S1]  [D] = 1
• [S2] = [S1]  [D+1] = 1
• [S2] > [S1]  [D+2] = 1
 C.B. Pham 5-10
5.2. Move and compare

• ZCP: Zone compare

- The operation is the same as the CMP


instruction except a single data value
(S3) is compared against a data range
(S1-S2):
• [S3] < [S1] & [S2]  [D] = 1
• [S3]: from [S1] and [S2]  [D+1] = 1
• [S3] > [S1] & [S2]  [D+2] = 1
 C.B. Pham 5-11
5.2. Move and compare

• MOV: Move data

- The contents of the source device (S) is copied to the destination (D)
device when the control input is active. If the MOV instruction is not
driven, no operation takes place.

 C.B. Pham 5-12


5.2. Move and compare

• BCD: Converts binary numbers to BCD.


• BIN: Converts BCD to binary numbers.

 C.B. Pham 5-13


5.3. Arithmetic and logical operations

ADD Addition FNC 20


SUB Subtraction FNC 21
MUL Multiplication FNC 22
DIV Division FNC 23
INC Increment FNC 24
DEC Decrement FNC 25
WAND Word AND FNC 26
WOR Word OR FNC 27
WXOR Word Exclusive OR FNC 28
NEG Negation FNC 29

 C.B. Pham 5-14


5.3. Arithmetic and logical operations

• ADD: Addition

- The data contained within the source devices (S1,S2) is combined


and the total is stored at the specified destination device (D).
- All calculations are algebraically processed, i.e. 5 + (-8)= -3..
- If the result of a calculation is “0" then a special auxiliary flag, M8020
is set ON

 C.B. Pham 5-15


5.3. Arithmetic and logical operations

• SUB: Subtraction

- [D] = [S1] – [S2]


- The ‘Points to note’ is similar to ADD

 C.B. Pham 5-16


5.3. Arithmetic and logical operations

• MUL: Multiplication.

- When operating the MUL instruction in 16bit mode, two 16 bit data
sources are multiplied together. They produce a 32 bit result.
- The device identified as the destination address is the lower of the
two devices used to store the 32 bit result.
- Example: 5 (D0) × 7 (D2) = 35 - The value 35 is stored in (D4, D5)
 C.B. Pham 5-17
5.3. Arithmetic and logical operations

• DIV: Division

- [S1]  [S2]: When operating the DIV instruction in 16bit mode, two 16
bit data sources are divided into each other. They produce two 16 bit
results. The device identified as the destination address is the lower of
the two devices used to store the these results.
 C.B. Pham 5-18
5.3. Arithmetic and logical operations

• INC: incremented by 1
• DEC: decremented by 1

 C.B. Pham 5-19

You might also like