Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeContact

The text of a manual · part 8 of 11

MELSEC FX Family Programmable Logic Controllers Beginners Manual, pages 71 to 80

Pages 71 to 80 of 106

The original document is the PDF (969 KB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

For the Mitsubishi FX2NC-32MT

Page 71

Devices in Detail

Programming Tips for Timers and Counters

Setting setpoints with the integrated potentiometers The controllers of the FX1S and FX1N series have two integrated analog potentiometers with which you can adjust setpoint values for timers and other functions quickly and easily.

100-240 VAC

L

N

The value of the upper potentiometer (VR1) can be read from special data register D8031, the value of the lower potentiometer (VR2) from register D8031. To use one of the potentiometers as the setpoint value source for a timer you just specify the corresponding register in your program instead of a constant.

X15 X7 X11 X13 X5 X3 X1 X14 S/S X6 X10 X12 X4 X2 X0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 IN

POWER RUN ERROR

The value in the register can be adjusted between 0 and 255 by turning the potentiometer.

FX1N-24MR OUT

0 1 2 3 4 5 6 7 10 11 Y6 Y10 Y5 Y3 Y2 Y1 Y11 Y0 0V COM4 Y7 COM2 COM3 Y4 24+ COM0 COM1

24MR -ES/UL

MITSUBISHI

Potentiometer

Ladder Diagram

Instruction List

D8030 T1

X001 0

D8031 T2

T1 4 T1

0 1 4 5 8 8 10

T2 Y000

8

LD OUT LD OUT LD ANI OUT

X001 T1 T1 T2 T1 T2 Y000

D8030 D8031

In the program example above Y0 is switched on after the delay specified for timer T1, for the time specified for timer T2 (delayed pulse generation). Signal sequence ON

X1

OFF 1

[D8030]

T1 0 1

[D8031]

T2 0 ON

Y0

OFF t

FX Beginners Manual

4 – 13

Page 72

Programming Tips for Timers and Counters

4.6.2

Devices in Detail

Switch-off delay By default, all the timers in MELSEC PLCs are delayed make timers, i.e. the output is switched ON after the defined delay period. However, you will often also want to program a delayed break operation (switch OFF after a delay). A typical example of this is a ventilation fan in a bathroom that needs to continue running for several minutes after the lights are switched off. Program version 1 (latching) Ladder Diagram

Instruction List

X001 Y000

0 Y000

0 1 2 3 4 5 6

T0

K300 T0

X001 5

LD LD ANI ORB OUT LDI OUT

X001 Y000 T0 Y000 X001 T0

K300

As long as input X1 (e.g. a light switch) is on output Y0 (fan) is also on. However, the latching function ensures that Y0 also remains on after X1 has been switched off, because timer T0 is still running. T0 is started when X1 is switched off. At the end of the delay period (300 x 0.1s = 30s in the example) T0 interrupts the Y0 latch and switches the output off. Signal sequence X1 30 s T0

Y0 t

Program version 2 (set/reset) Ladder Diagram

Instruction List

X001 SET

0 X001 2

Y000

K300 T0

T0 6

RST

0 1 2 3 6 7

LD SET LDI OUT LD RST

X001 Y000 X001 T0

K300 T0

Y000

Y000

When X1 is switched on output Y0 is set (switched on). When X1 is switched off timer T0 is started. After the delay period T0 then resets output Y0. The resulting signal sequence is identical with that produced by program version 1.

4 – 14

MITSUBISHI ELECTRIC

Page 73

Devices in Detail

4.6.3

Programming Tips for Timers and Counters

Delayed make and break Sometimes you will want to switch an output on after a delay and then switch it off again after another delay. This is very easy to implement with the controller’s basic logical instructions. Ladder Diagram

Instruction List

0

K25 T1

4

K50 T2

X000

X000

T1

0 1 4 5 8 9 10 11

T2

8

Y000

LD OUT LDI OUT LD OR ANI OUT

X000 T1 X000 T2 T1 Y000 T2 Y000

K25 K50

Y000

Signal sequence ON

X0

OFF 1

T1 0 1

T2 0 ON

Y0

OFF t1 t2 t

Output Y000 is latched with the help of T1, keeping the output switched on until the end of the break delay period.

FX Beginners Manual

4 – 15

Page 74

Programming Tips for Timers and Counters

4.6.4

Devices in Detail

Clock signal generators The controllers have special relays that make it very easy to program tasks requiring a regular clock signal (for example for controlling a blinking error indicator light). Relay M8013 switches on and off at 1-second intervals, for example. For full details on all special relays see the Programming Manual for the FX family. If you need a different clock frequency or different on and off times you can program your own clock signal generator with two timers, like this: Ladder Diagram

X001

Instruction List

K10 T1

T2

0 T1

0 1 2 5 6 9

K20 T2

5

LD ANI OUT LD OUT OUT

X001 T2 T1 T1 T2 Y000

K10 K20

Y000

Input X1 starts the clock generator. If you want, you can omit this input – then the clock generator is always on. In the program you could use the output of T1 to control a blinking warning light. The on period is determined by T2, the off period by T1. The output of timer T2 is only switched on for a single program cycle. This time is shown much longer than it really is in the signal sequence illustration below. T2 switches T1 off and immediately after this T2 itself is also switched off. In effect this means that the duration of the on period is increased by the time that it takes to execute a program cycle. However, since the cycle is only a few milliseconds long it can usually be ignored. Signal sequence ON

X0

OFF 1

T1 0 t1

1

T2 t2 0 ON

Y1

OFF t

4 – 16

MITSUBISHI ELECTRIC

Page 75

More Advanced Programming

5

Applied Instructions Reference

More Advanced Programming The basic logic instructions listed in Chapter 3 can be used to emulate the functions of a hard-wired contactor controller with a programmable logic controller. However, this only scratches the surface of the capabilities of modern PLCs. Since every PLC is built around a microprocessor they can also easily perform operations like mathematical calculations, comparing numbers, converting from one number system to another or processing analog values. Functions like these that go beyond the capabilities of logic operations are performed with special instructions, which are referred to as applied or application instructions.

5.1

Applied Instructions Reference Applied instructions have short names that are based on the English names of their functions. For example, the instruction for comparing two 16-bit or 32-bit numbers is called CMP, which is short for compare. When you program an applied instruction you enter the instruction name followed by the device name. The following table shows all the applied instructions currently supported by the MELSEC FX family of controllers. This list may look a little overwhelming at first, but don’t worry – you don’t have to memorise them all! When you are programming you can use the powerful Help functions of GX Developer and GX IEC Developer to find the instructions you need. In this chapter we will only cover the more frequently-used instructions, which are shown with a grey shaded background in the reference table. For full documentation of all the instructions with examples please refer to the Programming Manual for the FX family. Category

Program flow functions

Move and compare functions

FX Beginners Manual

Instruction

Function

CJ

Conditional Jump to a program position

CALL

Calls (executes) a subroutine

SRET

Subroutine Return, marks the end of a subroutine

IRET

Interrupt Return, marks the end of an interrupt routine

EI

Enable Interrupt, enables processing of interrupt routines

DI

Disable Interrupt, disables processing of interrupt routines

Controller FX1S

FX1N

FX2N FX2NC FX3U

쏹

쏹

쏹

쏹

쏹

FEND

First End, marks end of main program block

WDT

WatchDog Timer refresh

FOR

Marks beginning of a program loop

NEXT

Marks end of a program loop

CMP

Compare numerical values

쏹

쏹

쏹

쏹

쏹 쏹

ZCP

Zone Compare, compares numerical ranges

쏹

쏹

쏹

쏹

MOV

Move data from one storage area to another

쏹

쏹

쏹

쏹

쏹

SMOV

Shift Move

쏹

쏹

쏹

CML

Compliment, copies and inverts

쏹

쏹

쏹

BMOV

Block Move

쏹

쏹

쏹

FMOV

Fill Move, copy to a range of devices

쏹

쏹

쏹

쏹

쏹

XCH

Exchange data in specified devices

쏹

쏹

쏹

BCD

BCD conversion

쏹

쏹

쏹

쏹

쏹

BIN

Binary conversion

쏹

쏹

쏹

쏹

쏹

5–1

Page 76

Applied Instructions Reference

Category

More Advanced Programming

Instruction ADD

Math and logic instructions

Rotate and shift functions

Data operation functions

Application instructions

5–2

Controller FX1S

FX1N

FX2N FX2NC FX3U

Add numerical values

쏹

쏹

쏹

쏹

쏹

SUB

Subtract numerical values

쏹

쏹

쏹

쏹

쏹

MUL

Multiply numerical values

쏹

쏹

쏹

쏹

쏹

DIV

Divide numerical values

쏹

쏹

쏹

쏹

쏹

INC

Increment

쏹

쏹

쏹

쏹

쏹

DEC

Decrement

쏹

쏹

쏹

쏹

쏹

AND

Logical AND

쏹

쏹

쏹

쏹

쏹

OR

Logical OR

쏹

쏹

쏹

쏹

쏹

XOR

Logical exclusive OR

쏹

쏹

쏹

쏹

쏹

NEG

Negation, logical inversion of device contents

쏹

쏹

쏹

ROR

Rotate right

쏹

쏹

쏹

ROL

Rotate left

쏹

쏹

쏹

RCR

Rotate carry right, rotate right with carry

쏹

쏹

쏹

RCL

Rotate carry left, rotate left with carry

쏹

쏹

쏹

SFTR

Shift right, bitwise shift to the right

쏹

쏹

쏹

쏹

쏹

SFTL

Shift left, bitwise shift to the left

쏹

쏹

쏹

쏹

쏹

WSFR

Word shift right, shift word values to the right

쏹

쏹

쏹

WSFL

Word shift left, shift word values to the left

쏹

쏹

쏹

SFWR

Shift register write, writes to a FIFO stack

쏹

쏹

쏹

쏹

쏹

SFRD

Shift register read, reads from a FIFO stack

쏹

쏹

쏹

쏹

쏹

ZRST

Zone Reset, resets ranges of like devices

쏹

쏹

쏹

쏹

쏹

DECO

Decode data

쏹

쏹

쏹

쏹

쏹

ENCO

Encode data

쏹

쏹

쏹

쏹

쏹

SUM

Sum (number) of active bits

쏹

쏹

쏹

BON

Bit on, checks status of a bit

쏹

쏹

쏹

MEAN

Calculates mean values

쏹

쏹

쏹

ANS

Timed annunciator set, starts a timer interval

쏹

쏹

쏹

Annunciator reset

쏹

쏹

쏹

SQR

Square root

쏹

쏹

쏹

FLT

Floating point, converts data

쏹

쏹

쏹

REF

Refresh inputs and outputs

쏹

쏹

쏹

ANR

High-speed instructions

Function

쏹

쏹

REFF

Refresh inputs and filter adjust

쏹

쏹

쏹

MTR

Input matrix, read a matrix (MTR)

쏹

쏹

쏹

DHSCS

High-speed counter set

쏹

쏹

쏹

쏹

쏹

DHSCR

High-speed counter reset

쏹

쏹

쏹

쏹

쏹

DHSZ

High speed zone compare

쏹

쏹

쏹

SPD

Speed detection

쏹

쏹

쏹

쏹

쏹

PLSY

Pulse Y output (frequency)

쏹

쏹

쏹

쏹

쏹

PWM

Pulse output with pulse width modulation

쏹

쏹

쏹

쏹

쏹

PLSR

Pulse ramp (accelleration/deceleration setup)

쏹

쏹

쏹

쏹

쏹

IST

Initial state, set up multi-mode STL system

쏹

쏹

쏹

쏹

쏹

SER

Search data stack

쏹

쏹

쏹

ABSD

Absolute counter comparison

쏹

쏹

쏹

쏹

쏹

INCD

Incremental counter comparison

쏹

쏹

쏹

쏹

쏹

TTMR

Teaching timer

쏹

쏹

쏹

STMR

Special timer

쏹

쏹

쏹

ALT

Alternate state, flip-flop function

쏹

쏹

쏹

쏹

쏹

RAMP

Ramp function

쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

ROTC

Rotary table control

쏹

SORT

Sort table data on selected fields

쏹

MITSUBISHI ELECTRIC

Page 77

More Advanced Programming

Category

Instructions for external I/O devices

Instructions for external serial devices

Applied Instructions Reference

Instruction TKY

Ten key input

HKY

Hexadecimal key input

DSW

Digital switch

SEGD

7-segment display decoder

SEGL

7-segment display with latch

Floating point operations

Trigonometry instructions for floating point numbers

FX Beginners Manual

Controller FX1S

쏹 쏹

FX1N

쏹 쏹

FX2N FX2NC FX3U 쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

ARWS

Arrow switch

쏹

쏹

쏹

ASC

ASCII conversion

쏹

쏹

쏹

PR

Print, data output via the outputs

쏹

쏹

쏹

쏹

쏹

쏹

쏹

FROM

Read data from a special function module

TO

Write data to a special function module

쏹

쏹

쏹

쏹

RS

RS serial communications

쏹

쏹

쏹

쏹

쏹

PRUN

Parallel run (octal mode)

쏹

쏹

쏹

쏹

쏹

ASCI

Convert to an ASCII character

쏹

쏹

쏹

쏹

쏹

HEX

Convert to a hexadecimal character

쏹

쏹

쏹

쏹

쏹

CCD

Check Code, sum and parity check

쏹

쏹

쏹

쏹

쏹

VRRD

Read setpoint values from FX1N-8AV-BD and FX2N-8AV-BD

쏹

쏹

쏹

쏹

쏹

VRSC

Read switch settings from FX1N-8AV-BD and FX2N-8AV-BD

쏹

쏹

쏹

쏹

쏹

RS2

RS serial communications (2) 쏹

쏹

쏹

쏹

PID Store/restore index registers

Function

Program a PID control loop

쏹

ZPUSH

Zone push, store contents of index registers

ZPOP

Zone pop, restore contents of index registers

DECMP

Compare floating point values

쏹

쏹

쏹

쏹

쏹 쏹 쏹 쏹

DEZCP

Compare floating point values (range)

DEMOV

Move floating point values

쏹

DESTR

Convert floating point value to a string

쏹

DEVAL

Convert string to floating point value

쏹

DEBCD

Convert floating point value to scientific notation

쏹

쏹

쏹

DEBIN

Convert scientific notation to floating point

쏹

쏹

쏹

DEADD

Add floating point numbers

쏹

쏹

쏹

DESUB

Subtract floating point numbers

쏹

쏹

쏹

DEMUL

Multiply floating point numbers

쏹

쏹

쏹

DEDIV

Divide floating point numbers

쏹

쏹

DEXP

Floating point exponent

쏹

DLOGE

Calculate natural logarithm

쏹

DLOG10

Calculate decadic logarithm

DESQR

Square root of floating point numbers

DENEG

Reverse sign of floating point numbers

쏹

쏹 쏹

쏹

쏹 쏹

INT

Convert floating-point numbers to integers

쏹

쏹

쏹

SIN

Calculate the sine

쏹

쏹

쏹

COS

Calculate the cosine

쏹

쏹

쏹

TAN

Calculate the tangent

쏹

쏹

쏹

ASIN

Calculate the arc sine

쏹

ACOS

Calculate the arc cosine

쏹

ATAN

Calculate the arc tangent

쏹

RAD

Convert degrees to radians

쏹

DEG

Convert radians to degrees

쏹

5–3

Page 78

Applied Instructions Reference

Category

Data operations

Positioning instructions

Operations with the PLC’s integrated clock

Gray code conversion Data exchange with analog modules Instructions in external memory

Miscellaneous instructions

More Advanced Programming

Function

WSUM

Sum of the contents of word devices

쏹

WTOB

Word to byte, divide words into bytes

쏹

BTOW

Byte To Word, form words from individual bytes

쏹

UNI

Combine groups of 4 bits to form words

쏹

FX1S

FX1N

FX2N FX2NC FX3U

쏹

DIS

Divide words into groups of 4 bits

SWAP

Swap least and most significant bits

SORT

Sort the data in a table

쏹

DSZR

Return to zero home point (with proximity switch)

쏹

DVIT

Positioning with interrupt

쏹

TBL

Positioning with data table

DABS

Read absolute current position

쏹

쏹

쏹

쏹

쏹

쏹 쏹

쏹

쏹

ZRN

Return to zero home point

쏹

쏹

쏹

PLSV

Output pulses with variable frequency

쏹

쏹

쏹

DRVI

Position to an incremental value

쏹

쏹

쏹

DRVA

Position to an absolute value

쏹

쏹

쏹

TCMP

Compare clock data

쏹

쏹

쏹

쏹

쏹

TZCP

Compare clock data with a zone (range)

쏹

쏹

쏹

쏹

쏹

TADD

Add clock data

쏹

쏹

쏹

쏹

쏹

TSUB

Subtract clock data

쏹

쏹

쏹

쏹

쏹

HTOS

Convert hours / minutes / seconds time value to seconds

쏹

STOH

Convert seconds time value to hours / minutes / seconds

쏹

TRD

Read clock time and date

쏹

쏹

쏹

쏹

쏹

TWR

Write time and date to PLC clock

쏹

쏹

쏹

쏹

쏹

HOUR

Operating hours counter

쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

쏹

GRY

Convert Gray code to decimal

GBIN

Convert decimal number to Gray code

RD3A

Read analog input values

WR3A

Write analog output values

EXTR

Execute command stored in an external ROM

COMRD

Read device comment

RND

Generate a random number

DUTY

Generate a pulse with a defined length

CRC

Check data (CRC check)

HCMOV

Instructions for data stored in consecutive devices (data blocks)

Controller

Instruction

쏹

쏹

Move the current value of a high-speed counter

BK+

Add data in a data block

BK-

Subtract data in a data block

BKCMP= BKCMP> BKCMP< BKCMP<>

쏹

Compare data in data blocks

BKCMP<= BKCMP>=

5–4

MITSUBISHI ELECTRIC

Page 79

More Advanced Programming

Category

String operations

Data table operations

Applied Instructions Reference

Instruction

Function

STR

Convert binary data to a string

VAL

Convert a string to binary data

$+

Concatenate strings

LEN

Returns the length of a string

RIGHT

Extract substring from right

LEFT

Extract substring from left

MIDR

Select a character string

MIDW

Replace a character strings

INSTR

Search for a character string

$MOV

Move a character string

FDEL

Delete data from a table

FINS

Insert data in a table

POP

Read last data inserted in a table

SFR

Shift a 16-bit data word right

SFL

Shift a 16-bit data word left

Controller FX1S

FX1N

FX2N FX2NC FX3U

쏹

쏹

LD= LD> LD< LD<> LD<= LD>= AND= Comparison operations

AND> AND<

Compare data within operations

쏹

쏹

쏹

쏹

쏹

AND>= OR= OR> OR< OR<> OR<= OR>=

Data control instructions

Instructions for communication with frequency inverters

Data exchange with special function modules High-speed counter instruction

FX Beginners Manual

LIMIT

Limits the output range of values

BAND

Define input offset

ZONE

Define output offset

SCL

Scale values

DABIN

Convert an ASCII number to a binary value

BINDA

Convert a binary value to ASCII code

SCL2

Scale values (different value table structure to SCL)

IVCK

Check status of frequency inverter

IVDR

Control frequency inverter

IVRD

Read frequency inverter parameter

IVWR

Write parameter to frequency inverter

IVBWR

Write parameters to frequency inverter in blocks

RBFM

Read from module buffer memory

WBFM

Write to module buffer memory

HSCT

Compare current value of a high-speed counter with data in data tables

쏹

쏹

쏹 쏹

5–5

Page 80

Applied Instructions Reference

Category

Instructions for extension file registers

5.1.1

More Advanced Programming

Controller

Instruction

Function

LOADR

Read data from extension file registers

SAVER

Write data to extension file registers

INITR

Initialise extension registers and extension file registers

LOGR

Read values from devices in extension registers and extension file registers

RWER

Write data from extension registers to extension file registers

INITER

Initialise extension file registers

FX1S

FX1N

FX2N FX2NC FX3U

쏹

Entering applied instructions Programming applied instructions in GX Developer FX is simple. Just position the cursor in the place in the program line where you want to insert the instruction and type the abbreviations for the instruction and its operand(s). GX Developer will automatically register that you are entering an instruction and will open the input dialog (see below). Alternatively, you can also position the cursor and then click on the insert instruction tool in the toolbar .

You can also select the instruction from the drop-down list, which you can display by clicking on the „쑽“ icon.

Then enter the abbreviations for the instruction and its operand(s) in the input field, separating them by spaces. All numbers must be preceded by a letter character, which either identifies the device type or – in the case of constants – specifies the number format. The letter “K” identifies decimal constants and “H” identifies hexadecimal constants. In the example on the left a MOV instruction is used to write the value 5 to data register D12. The Help button opens a dialog in which you can search for a suitable instruction for the function you want to perform. The help also contains information on how the functions work and the type and number of devices that they take as operands. Then you just click on OK to insert the applied instruction into the program.

M457 MOV K5 D12

If you are programming in Instruction List format enter the instruction and its operand(s) in a single line, separated by spaces.

5–6

MITSUBISHI ELECTRIC