Table of Contents

MP STUDIO 2 Phase 4 · Functions

한국어 | English

Functions are ladder instructions that take up several cells, such as comparisons, math, timers and counters. You can pick them from the Functions panel or type the instruction in the Insert Function window.

Figure 1. How a function runs

A function runs while the condition to the left of the function block is ON, and power continues to the right of the block according to the result. Comparison functions are placed in the row like contacts and pass power when the comparison is true.

Functions Panel

Click the Functions button on the symbol rail or press Alt+2 to open the Functions panel.

Figure 2. The Functions panel (with the Timer category expanded)

Figure 3. The Functions panel filtered by TON

Insert Function Window

Press Ctrl+E, Ctrl+Enter or [, or select Edit → Insert Function, to open the Insert Function window.

  1. In ① Instruction, type the function name followed by its arguments, separated by spaces. Examples: MOVE D0 D1, ADD D0 20 D1, TON T0 1s
  2. As you type the name, ② the argument order and a description are shown (for example [TON] [IN] [SV], TON: On Delay Timer, the operating condition and an input example). If no function matches, No matching instruction. is shown.
  3. Click OK or press Enter to insert the function at the cursor cell.

Figure 4. The Insert Function window with the argument description

Editing Arguments

Figure 5. The Edit Function window for editing the whole instruction

If an address in an argument does not match the data type the function expects (bit, byte, word, double word or real), the cell turns red. Hover over the cell to see the reason.

Timers

The timer set value (SET VALUE) is in units of 10 ms. TON T0 100 and TON T0 1s are the same 1-second setting, and the block shows it as 1S.

Figure 6. A TON that turns P33 on after P0 has been held for 1 second

Function Action
TON On Delay Timer — turns ON when the condition has stayed ON for the set time or longer. When the condition turns OFF, the current value becomes 0.
TOFF Off Delay Timer — stays ON for the set time after the condition turns OFF.
TPL Pulse Timer — turns ON when the condition turns ON, for up to the set time. If the condition turns OFF first, it turns OFF too.
TMON Pulse Extended Timer — turns ON for the set time when the condition turns ON. It stays ON for the full set time even if the condition turns OFF in the meantime.
TMR Accumulative Timer — accumulates the time the condition is ON. The current value remains when the condition turns OFF, so clear it from another rung to reset it.

Counters

The arguments of CTU are COUNT (counter address), SET VALUE (set value) and RESET (reset bit), in that order. Example: CTU C0 5 P2

Figure 7. A CTU that turns C0 on after P1 is pressed five times, switching P34 on

The arguments of CTD (DOWN Counter) are COUNT, SET VALUE and SET, and it turns ON when the current value reaches 0.

Comparison and Move

Comparison functions (==, >, U< and so on) compare two values and pass power when the result is true. For example, >= D0 100 is true when D0 is 100 or more (signed comparison). MOVE (block name MOV) copies the value of IN to OUT.

Figure 8. A rung that copies D0 to D1 when D0 is 100 or more

Function List

The 16 categories of the Functions panel and their functions are listed below. The argument order is shown in parentheses.

Category Functions
Comparison == (equal) · != (not equal) · > · < · >= · ⇐ — signed comparison, U> · U< · U>= · U⇐ — unsigned comparison (IN1, IN2)
Conversion H2D (hex → decimal) · D2H (decimal → hex) · INV (ones' complement) · NEG (two's complement) (IN, OUT)
Math ADD · SUB · MUL (IN1, IN2, OUT) · DIV (IN1, IN2, OUT, REM) · INC · DEC (IN) · SCALE (IN, IN_MAX, IN_MIN, OUT, OUT_MAX, OUT_MIN) · FLOOR · SQRT (IN, OUT)
Counter CTU (COUNT, SET VALUE, RESET) · CTD (COUNT, SET VALUE, SET) · CTUD (COUNT, CU, CD, SET VALUE, RESET) · HCNT (CHANNEL, OUT) · HRST (CH) · ENCODER (CHANNEL, OUT) · ENMOV (CHANNEL, IN)
Timer TON · TOFF · TPL · TMON · TMR (TIMER, SET VALUE)
Logic Control JMP · JMPN · LABEL (LABEL) · END
Word Logic WAND · WOR · WXOR (IN1, IN2, OUT) · SHL · SHR (IN, N, OUT) · SWAP (IN, OUT)
Analog ADC · ADC2 (4 to 20 mA) · DAC (CHANNEL, MAX VALUE, MIN VALUE, OUT) · AFILTER (IN, WEIGHT, OUT) · NTEMP · PTEMP (CHANNEL, OUT) · PWM (PORT, DUTY, WIDTH) · FPWM (PORT, FREQ) · FDPWM (PORT, FREQ, DUTY) · NPWM (PORT, FREQ, N) · POFF (PORT) · PSR (OUT) · PID (PV, SV, KP, KI, KD, OUT MAX, OUT MIN, MV) · PID_PWM (PORT, PV, SV, KP, KI, KD, MV)
MOVE MOVE (IN, OUT) · GMOVE · FMOVE (IN, OUT, N)
Data Processing MAX · MIN · SUM · AVE · MUX · ENCO · DECO (IN, OUT, N)
Program Control MCS · MCSCLR (NUM)
Serialport PUT (CHANNEL, DATA, LENGTH) · GET (CHANNEL, LENGTH, OUT) · PUT_LEN · GET_LEN (CHANNEL, OUT) · SERID (CHANNEL, ID) · SERRATE (CHANNEL, RATE) · MNET (CH) · MNET_READ (RATE, ADD)
I2C ISTA (ADDRESS, READ) · ISTP · IWR (DATA) · IRD (OUT, ACK) · ISR (OUT) · IBR (IN)
CLCD (Character LCD) CINI (ADR, TYPE) · CLOC (ADR, X, Y) · CSTR (ADR, STRING) · CINT · CREAL (ADR, IN, DIGIT, ZERO, SIGN) · CHEX (ADR, IN, DIGIT, ZERO) · CCLS · CCON · CCOF (ADR) · CLON · CLOF · CPUT (ADR, ID, DEFINE) · CGET (ADR, ID)
7Segment FINI (CLK, DIO) · FINT (IN, POSITION, LENGTH, DOT, ZERO, SIGN) · FDATA (DATA, POSITION)
DS3231 (RTC) DS3231_WR · DS3231_RD (YEAR, MONTH, DATE, DAY, HOUR, MINUTE, SECOND)

Analog, pulse and temperature functions can be used only on models or expansion modules that have that feature. The range of channel numbers depends on the selected model.

← Back to the MP STUDIO 2 User Manual