You are on page 1of 5

FX-SAD411A

DATE: NOVEMBER 1993


TM PAGE: 1 OF 5
© MITSUBISHI ELECTRIC

AN INTRODUCTION TO THE
DECODE INSTRUCTION (DECO, FNC41)
Introduction Parameter a) - DECO Statement
The DECO instruction has one variable which gives a
There are many ways to save time when program-
possibility of two different instruction forms. The avail-
ming. The quickest and most reliable method is to use
able forms are:-
special instructions found in the PC. The FX family of
PCs has such a set of special instructions. These are I) DECO - a standard DECO statement can
called ’Applied Instructions’. The DECO or DECOde access data up to a maximum of 16 bits.
instruction is a member of these applied instructions. The instruction will act continuously
DECO has a special function number of 41. while the control signal is ON. In the
sample program this occurs when X010
The DECO Instruction
is switched on. This instruction accounts
The DECO instruction is a method of retrieving the for seven (7) steps in the program.
address of an encoded active bit, which forms part of
II) DECOP - a modified DECO statement
a range of specified bits. The retrieval method is by now acting once on the rising edge of the
decoding the stored offset of the active bit. This offset control signal. In the sample program this
is applied to the head address of the destination data. occurs when X010 switches from OFF to
The basic components of a DECO instruction are; ON. The ’P’ suffix stands for pulse. This
a) The DECO statement instruction accounts for seven (7) steps
in a program.
b) The head address of the encoded source FX0 users should note that this variation
data of the DECO instruction is not available
on the FX0.
c) The head address of the destination for
the decoded data Parameter b) - The Head Address Of The Source
Data
d) The number of bits that has been used
This identifies what form the encoded source data has,
as the storage device where it is located in the PC and how much there is of
it. This can be regarded as the head address of the
PARAMETER
source data. The data can be in any of the following
forms;
a) b) c) d) Constant Numeric Values: Decimal values (K),
X010 Hexadecimal values (H)
DECO X000 Y000 K 3 Numeric Data Values: Data Registers (D),
Counters (C), Timers (T), Index Registers (V ,Z)
Bit Devices: Inputs (X), Outputs (Y),
The same line of ladder logic written in instruction Auxiliary Coils (M), State Coils (S)
format would look like;
Parameter c) -
Each of the parameters required for the DECO instruc- The Head Address Of The Destination Data
tion will now be described in detail.
This identifies the head bit address for the storage of
PROGRAM the decoded data. This address can be supplied in
INSTRUCTION PROGRAM many formats;
STEP No.
Numeric Data Values: Data Registers (D),
0 LD X 010 Counters (C), Timers (T)
1 DECO 41 Bit Devices: Outputs (Y), Auxiliary Coils (M), State
Coils (S)
X 000
Y 000
K 3
FX-SAD411A
DATE: NOVEMBER 1993
TM PAGE: 2 OF 5
© MITSUBISHI ELECTRIC

AN INTRODUCTION TO THE
DECODE INSTRUCTION (DECO, FNC41)
Parameter d) - The Number Of Bits To Be Used I) Decoding Bit Devices to Bit Devices
As The Source Device
X017
The number of bits to be used can be specified in
DECO X000 M100 K 5
hexadecimal (H) or decimal (K). This parameter can-
not be indexed. When the destination device is a bit,
i.e. an output/auxiliary coil or a state relay parameter
d) may have a value in the range of 1 to 8. If the One of the most important points to identify is the
destination device is designated as a data device, i.e. number of bits that have been used to form the source
a data register, counter or timer, then parameter d) data. This has great significance as it can be used to
must have a value in the range of 1 to 4. When determine how many devices will be required as a
parameter d) is specified it identifies the quantity of destination. In the example K5 is identified as the
source data which will be decoded. This is an impor- number of source bits. This means devices X000 to
tant factor when bit devices are used as the destina- X004 have been used, i.e. 5 devices. Any data stored
tion data. The following table identifies how many outside of these devices will NOT be part of this
destination bit devices will be required for each of the example DECO instruction.
available settings of parameter d); To identify how many destination devices are re-
quired, the maximum encoded number must be found.
PARAMETER d) This is carried out by assuming all of the source bits
NUMBER OF
NUMBER OF BITS equal 1. The source bit pattern is then decoded to
DESTINATION BITS
THE ENCODED DATA
REQUIRED reveal the maximum decodable number.
IS STORED IN
K1 2 SOURCE DATA FOR DECODING

K2 4 X X X X X X7 X6 X5 X4 X3 X2 X1 X0
14 13 12 11 10
K3 8 THESE BIT DEVICES ARE 1 1 1 1 1
IGNORED BY THIS DECODE
K4 16 EXAMPLE AS THEY FALL OUTSIDE on on on on on
THE
K5 32 DESIGNATED SOURCE AREA MAXIMUM VALUE
K6 64
X7 X6 X5 X4 X3 X2 X1 X0
K7 128
K8 256 ----- 1 1 1 1 1
Decodes to;
If parameter d) is set to 0 then the DECO instruction
acts as if it has been disabled. 1 x X4 = 1 x 16
1 x X3 = 1 x 8
How Does It Work? 1 x X2 = 1 x 4
1 x X1 = 1 x 2
The DECO instruction can be split into four proce- 1 x X0 = 1 x 1
dures;

• Decoding bit devices to bit devices = 31


Once the maximum number of destination bits is
• Decoding bit devices to data devices known, it is important to be very careful with the use
• Decoding data devices to bit devices of these devices for other functions. Errors could be
caused from confusion over which bit is actually the
• Decoding data devices to data devices
decoded bit. In the example, 5 source bits will decode
There is a slight difference between these four func- to a maximum of 31 destination bits.To save working
tions which should be noted to ensure complete un- this out, please reference the table under parameter
derstanding of this command. The four variations d).
mentioned are explained in the two following exam- The decoded data provides the offset address from
ples; the destination head address. At this identified ad-
dress the related bit device will be turned on.
FX-SAD411A
DATE: NOVEMBER 1993
TM PAGE: 3 OF 5
© MITSUBISHI ELECTRIC

AN INTRODUCTION TO THE
DECODE INSTRUCTION (DECO, FNC41)
Worked example II) Decoding Data Devices To Data Devices

M 40
S 20
DECO X000 Y000 K 7
DECO D 10 D 4 K 4

Step 1 : K7 means 128 possible output bits


When data devices are used as the destination device
Step 2 : X000 is the source head address, hence with the number of valid source bits is reduced too, 1 to 4.
7 possible inputs the operating range is X000 to X006 This limits the size of the numbers present as the
source data. It also means that the maximum number
Step 3 : X006 and X001 are on, hence identifying the of destination devices is 16, as a word device only has
source data as being; 16 bits. If a source data device was configured with a
IDENTIFICATION OF SOURCE DATA bit device destination, there would be the usual 1 to 8
bit restriction. When data devices are used as the
X007 X006 X005 X004 X003 X002 X001 X000
source data, the stored number relates directly to the
off on off off off off on off offset address.
0 1 0 0 0 0 1 0
Important:
⇑ ⇑
As already mentioned, if the destination is specified
Step 4 : The decoded offset allows the related desti- as a data device, care must be taken when entering
nation bit device to be identified and turned on, i.e. the the source data. For example, if a data value which
66th output from Y000, which is Y102 in octal. activates 7 bits is used then it will not be decoded as
expected because the number of source bits is limited
X7 X6 X5 X4 X3 X2 X1 X0 to a maximum of 4. For example;
----- 1 0 0 0 0 1 0
X7 X6 X5 X4 X3 X2 X1 X0
Decodes to;
----- 1 0 0 0 0 1 0
1 x X6 = 1 x 64
0 x X5 = 0 x 32 Decodes to;
0 x X4 = 0 x 16
0 x X3 = 0 x 8 1 x X6 = 1 x 64
DATA IS IGNORED
0 x X2 = 0 x 4 0 x X5 = 0 x 32
1 x X1 = 1 x 2 AS ONLY 4 BITS 0 x X4 = 0 x 16
0 x X0 = 0 x 1 ARE VALID 0 x X3 = 0 x 8
0 x X2 = 0 x 4
= 66 1 x X1 = 1 x 2
0 x X0 = 0 x 1
IDENTIFICATION OF THE DESTINATION DEVICE
Y105 Y104 Y103 Y102 Y100 Y77 Y76 Y75 Hence incorrect value of =2
off off off on off off off off
is read.
0 0 0 1 0 0 0 0

Important:
Please remember ALL of these steps are automat-
ically carried out by the DECO instruction. They are
shown here to help explain how the instruction works.
All that is required is that correct and valid data is
entered into the DECO instruction.
FX-SAD411A
DATE: NOVEMBER 1993
TM PAGE: 4 OF 5
© MITSUBISHI ELECTRIC

AN INTRODUCTION TO THE
DECODE INSTRUCTION (DECO, FNC41)
When monitoring a destination data device, please Worked Example
remember that although the DECO instruction is set-
ting only one destination bit, the actual value moni-
tored will be the decimal conversion of that decoded
bit, i.e. If bit 7 is set then the monitored value is 128 S 50
decimal. The following table lists the expected data DECO D 0 D6 K 3
value, against which bit has been decoded/set.

CORRELATION OF ACTIVE DESTINATION BIT


Vs NUMERICAL VALUE OF DESTINATION
DATA
Step 1 : K3 means 8 possible outputs
ACTIVE DESTINATION DATA VALUE
DESTINATION Step 2 : D0 is the source head address, hence with 3
BIT DECIMAL HEXADECIMAL possible inputs the operating range is b0 to b07
b0 1 Step 3 : D0 contains the value 6 decimal. This means
the destination offset will be 6.
b1 2
b2 4 IDENTIFICATION OF SOURCE DATA IN REGISTER D0
b b b b b b b b b b b b b b b b
b3 8 8 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
b4 16 10 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
b5 32 20 THIS DATA IS NOT DECODED AS IT FALLS
⇑ ⇑
OUTSIDE THE SOURCE RANGE
b6 64 40
b7 128 80 Step 4 : The destination bit has its offset calculated
from the source head address. A value of 64 decimal
b8 256 100 will be observed when D6 is monitored.
b9 512 200
OFFSET OF ACTIVE BIT FROM THE DESTINATION
b10 1024 400 HEAD ADDRESS - D6

b11 2048 800 b b b b b b b b b b b b b b b b


15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
b12 4096 1000 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
b13 8192 2000 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
b14 16384 4000 off off off off off off off off off on off off off off off off

b15 -32768 8000 ⇑


FX-SAD411A
DATE: NOVEMBER 1993
TM PAGE: 5 OF 5
© MITSUBISHI ELECTRIC

AN INTRODUCTION TO THE
DECODE INSTRUCTION (DECO, FNC41)
Special Feature
The bit device which was turned on by the DECO
instruction remains set according to the last value
decoded even when DECO is turned off.

The ENCO Instruction


This text has been dedicated to the encoding of data.
The antonym of the DECO instruction is the ENCO
instruction (FNC 42). The ENCO instruction can be
used to encode data for the DECO to decode.

Further Reference
For more detailed information an the ENCO (FNC 42) instruction please reference datasheet FX-SAD421.
Information on bit and data devices can be found on the following sheets

• SDB001 - A Basic Introduction To The Term ’Bit’


• SDB006 - Grouping Bit Devices
• SDD001 - A Basic Introduction To The Term ’Word’
• SDD003 - Data Device ’D’ The Data Register
• SDD005 - A Look Behind The Data Register
Note 1: Sometimes data devices are called word devices or data registers. The FX family of PCs have 16 bits
to every data device.

You might also like