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.
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.
- ① Search functions: type part of a name to show only the matching functions.
- ② Category header: click to expand or collapse the category. Each category has its own color, and the number on the right is the number of functions in it.
- ③ Function row: double-click to insert the function at the cursor cell.
- ④ Mark list: the bookmarks in the program.
Insert Function Window
Press Ctrl+E, Ctrl+Enter or [, or select Edit → Insert Function, to open the Insert Function window.
- In ① Instruction, type the function name followed by its arguments, separated by spaces. Examples:
MOVE D0 D1,ADD D0 20 D1,TON T0 1s - 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. - Click OK or press
Enterto insert the function at the cursor cell.
Editing Arguments
- Select an argument cell of a function and press
Enter, or simply start typing a value, to change just that argument. - Select the name cell (the head) of a function and press
Enterto open the Edit Function window, where you can edit the whole instruction on one line.
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.
- ①
P0: the timer start condition - ②
TON T0 1s: while the condition is ON, the current value ofT0increases, and when it reaches the set value (1 second),T0turns ON. When the condition turns OFF, the current value returns to 0. - ③
T0contact: passes power to the next rung when the timer is ON. - ④
P33: the timer output
| 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
- Each time the condition on the left goes from OFF to ON, the current value of
C0increases by 1. - When the current value reaches the set value or more,
C0turns ON. - When the bit given as RESET (
P2) is ON, the current value becomes 0.
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.
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.




