PLC Simulator
GX Works reference

Mitsubishi GX Works instruction list reference

GX Works is the programming software for Mitsubishi Electric MELSEC controllers, from the compact FX family to the iQ-R platform. Its ladder editor and its instruction list share one small vocabulary: LD, AND, OR and their inverse forms to read bits, OUT, SET and RST to write them, and a few application instructions such as MOV and CMP. This page explains nine of them in Mitsubishi terms, with the IEC equivalent and a runnable exercise for each.

The other habit to learn is device addressing. Mitsubishi does not use free-form tag names in the core instruction list. Inputs are X devices, outputs are Y devices, internal relays are M, timers are T, counters are C and data registers are D. GX Works can attach labels to devices, but the instruction list you read in a manual or on a customer site is written with the device letters.

What the browser editor does and does not simulate

The exercises run in our browser Mitsubishi dialect, a tested subset of the FX and iQ mnemonic: LD, LDI, AND, ANI, OR, ORI, OUT, SET, RST, ANB, ORB, timers and counters as OUT T and OUT C, and MOV, ADD, SUB, MUL and DIV as standalone instructions. X and Y numbers are decimal here (real FX controllers number them in octal and Q and iQ-R in hexadecimal), timers are fixed at 100 ms, and there is no MPS, PLS, PLF, CMP or edge contact. The PLS and CMP units explain the real instruction and run an equivalent.

The MELSEC scan and where to read scan time

A MELSEC CPU repeats the same sequence: refresh the inputs, run the program from step 0 to the END instruction, then refresh the outputs. Within the program, rungs run top to bottom and an OUT writes its device straight away, so a later rung in the same scan sees the new value, while the physical outputs update once at the end of the scan.

Scan time is the time one such cycle takes. Each MELSEC series keeps the current, minimum and maximum scan time in special registers, and the numbers and units differ between series, so read the special-register list in the manual for your CPU rather than copying an address from another series. A scan-time monitor in GX Works shows the same figures while online.

Because the physical inputs are refreshed once per scan, an input pulse shorter than the scan can be missed, and a very long scan delays every output. Application instructions with a P suffix, such as MOVP, run for one scan on the rising edge of their condition instead of on every scan, which is the standard way to make a data transfer happen once.

To estimate a scan time from your own program size, use the PLC scan time calculator.

Mitsubishi instructions explained

LD / LDI · 6 min · Free exercise

LD and LDI: start a rung open or closed

Load and Load Inverse

Every rung needs a first contact. In Mitsubishi instruction list that first contact is written LD when the rung should pass while the device is on, and LDI when it should pass while the device is off.

What it does exactly

LD, short for Load, starts a rung with a normally open contact on the named device: the rung is true while the device is on. LDI, Load Inverse, starts the rung with a normally closed contact: the rung is true while the device is off. The device can be an input X, an output Y, an internal relay M, a timer or counter contact, or another bit device.

LD and LDI only begin a rung and read a device. The contacts that follow on the same rung are written with AND, ANI, OR and ORI, and the rung ends with an output instruction. A new LD or LDI starts the next rung, which is how a program with many rungs is written one after another.

The IEC and editor equivalent

LD X0 is the IEC normally open contact | GATE_OPEN |, and LDI X0 is the normally closed contact | NOT GATE_OPEN |. IEC Instruction List also uses LD, with LDN for the inverse.

What the scan does with it

The device value read by LD or LDI is the value at that moment of the scan, which for an input X is the image captured at the start of the scan. For an output Y written by a rung above, it is the new value.

LD  X0
OUT Y0

LDI X0
OUT Y1
One limit switch drives an open lamp with LD and a closed lamp with LDI.

Common mistakes

  • Starting a rung with AND or OR. The first contact of a rung is always a load instruction.
  • Thinking LDI is "pressed". It means the device is off, so a normally closed limit switch wired to X0 reads on at rest.

What you can now do: You can start a rung with LD or LDI and pick the right one for the state you want to detect.

AND / ANI / OR / ORI · 8 min · Pro exercise

AND, ANI, OR, ORI: series and parallel contacts

Series and parallel contacts

Once a rung has a first contact you add more. Contacts in series all have to be on; contacts in parallel need only one to be on. Mitsubishi has an instruction for each of the four cases.

What it does exactly

AND adds a normally open contact in series and ANI adds a normally closed contact in series. OR adds a normally open contact in parallel with the contact or block before it, and ORI adds a normally closed contact in parallel. Together with LD and LDI they cover every simple rung.

A motor seal-in is the standard example: LD X0 for the start button, OR Y0 to put the motor output itself in parallel as a holding contact, ANI X1 for the stop button, then OUT Y0. Branches that need whole groups combined use ANB and ORB, which join two blocks in series or in parallel.

The IEC and editor equivalent

The same rung in IEC is | (START OR MOTOR) AND NOT STOP | := MOTOR ;. IEC Instruction List writes it with LD, OR and ANDN.

What the scan does with it

The seal-in works because the OR Y0 contact reads the motor output as written by the previous scan. The first scan after START is pressed sets Y0, and from then on Y0 itself keeps the rung true.

LD  X0
OR  Y0
ANI X1
OUT Y0
Start/stop with a holding contact.

Common mistakes

  • Wiring the stop button so that pressing it cannot drop the seal-in. The ANI must be in series with the whole OR block, not inside the parallel branch.
  • Using a normally closed stop button and an ANI at once. The wiring and the instruction must agree on which state means stopped.

What you can now do: You can build series and parallel contact logic and write a seal-in from LD, OR and ANI.

OUT · 7 min · Pro exercise

OUT: the coil and the double-coil mistake

Output coil

The OUT instruction is the coil: it writes the result of the rung to a device. If the rung is on the device is on, and if the rung is off the device is off.

What it does exactly

OUT drives an output Y, an internal relay M, and with extra operands a timer or counter. It copies the rung result to the device on every scan, so the device is not held: it follows the rung.

Writing the same device with OUT in two rungs is the double coil mistake. Both rungs run each scan, and the later rung overwrites the earlier one, so the earlier condition appears to do nothing. The fix is to join the conditions with OR in one rung ahead of a single OUT.

The IEC and editor equivalent

OUT is the IEC output coil, written := HORN ; in ladder text, or HORN := ALARM_1 OR ALARM_2; in structured text. IEC Instruction List calls it ST.

What the scan does with it

The OUT updates the device image immediately, so a rung further down the same scan can read it. The physical output terminal changes when the CPU refreshes outputs at the end of the scan.

LD  X0
OR  X1
OUT Y0
One OUT with the two alarm conditions in parallel.

Common mistakes

  • Driving the same Y with OUT in two places. Search the program for the device number before you add another coil.
  • Using OUT where a latch is intended, then wondering why the output drops when the trigger releases.

What you can now do: You can spot a double coil and rewrite two competing rungs as one.

SET / RST · 7 min · Pro exercise

SET and RST: latch a device on and off

Set and Reset

SET and RST are the "remember this" pair. SET turns a device on and leaves it on. RST turns it off. Between them the device holds its value, whatever the inputs do.

What it does exactly

When the rung before a SET is true, the named device is turned on and stays on after the rung goes false. RST does the opposite: when its rung is true the device is turned off, and it stays off afterwards. While a rung is false the instruction does nothing, and the device keeps whatever value it has.

If a SET rung and an RST rung for the same device are both true in the same scan, the one written later in the program wins, because it executes last. To make a stop dominate, write the RST rung after the SET rung. RST also clears timers, counters and data registers.

The IEC and editor equivalent

SET and RST are the IEC set and reset coils. The same latch is OTL and OTU in Allen-Bradley terms and S and R in Siemens terms.

What the scan does with it

A device set with SET keeps its value across scans like any other device. Whether it survives power loss depends on the device: ordinary M relays are cleared, while latch relays and some other ranges are battery-backed, so a remembered state that must survive power-off is placed in a latched range.

LD  X0
SET Y0
LD  X1
RST Y0
The alarm sets on the level signal and clears on acknowledge.

Common mistakes

  • SET with no RST anywhere, so nothing can clear the alarm.
  • Using SET and RST on a device that is also driven by an OUT coil. The OUT rewrites it every scan and wipes the latched value.

What you can now do: You can latch a device with SET and RST and place the rungs so the right one wins.

OUT T · 8 min · Pro exercise

OUT T: timers that count in 100 ms steps

Timer coil

A timer waits before it says yes. In Mitsubishi code the timer is not an extra block: you write it as a coil on a numbered timer device, with the waiting time as a number after it.

What it does exactly

OUT T0 K30 starts timer T0 counting while its rung is true. The constant K sets how many time units to wait, and the unit depends on the timer range: on the FX family T0 to T199 count in 100 ms steps, so K30 is 3 seconds, while other ranges use 10 ms or 1 ms steps. When the count is reached, the T0 contact turns on, and you read it with LD T0.

When the rung goes false, the timer clears and its contact turns off, so a short pulse never completes the delay. Retentive timers keep their count through a false rung and need an RST to clear.

The IEC and editor equivalent

This corresponds to the IEC TON with PT := T#3s, whose output is T_PUMP.Q. The timer contact LD T0 is the Q output, and the K number times the timer unit is PT.

What the scan does with it

The timer adds time on each scan while the rung is true. The delay is real time, but the contact can change only when the timer instruction executes, so the output can lag the true expiry by up to one scan.

LD  X0
OUT T0 K30

LD  T0
OUT Y0
Pump starts three seconds after the request on a 100 ms timer.

Common mistakes

  • Writing K30 and expecting 30 seconds. Check the timer range: with a 100 ms unit it is 3 seconds.
  • Reusing the same timer number for two timers. Each T number is one timer, and a second OUT on it fights the first.

What you can now do: You can turn a delay in seconds into a K value and read the timer contact to drive an output.

OUT C · 8 min · Pro exercise

OUT C: counters, presets and RST

Counter coil

A counter keeps a tally. In Mitsubishi code it is a coil on a numbered counter device with a target number: every time its rung switches on, the count goes up by one.

What it does exactly

OUT C0 K5 counts each rising edge of its rung. On the FX family the 16-bit counters C0 to C99 count up to the K value, and when the count equals the set value the C0 contact turns on and stays on. The count stops at the set value, so the contact stays on until the counter is reset.

The counter does not clear when its rung goes false. A separate rung with RST C0 sets the count to zero and turns the contact off. Counting happens only on the switching on, so a sensor held on for many scans counts as one.

The IEC and editor equivalent

This corresponds to the IEC CTU with PV := 5, whose output Q is the C0 contact. The RST C0 rung is the reset input R.

What the scan does with it

The counter sees one change per scan at most, so two pulses inside a single scan count as one. Fast pulses use the high-speed counter inputs of the CPU instead of a normal X input.

LD  X0
OUT C0 K5
LD  X1
RST C0

LD  C0
OUT Y0
Counter C0 counts to five parts and RST clears it.

Common mistakes

  • Leaving out RST C0, so the next batch starts with the contact already on.
  • Expecting the count to go up while the input stays on. It counts transitions.

What you can now do: You can count events to a K target and clear the counter with RST.

MOV · 6 min · Pro exercise

MOV: load and copy data registers

Move data

MOV copies a number from one place to another. It is how you load a preset into a register or hand a value from one register to the next.

What it does exactly

MOV takes a source first and a destination last. The source can be a constant written with K (decimal) or H (hexadecimal), or another device such as D0. The destination is typically a data register D. MOV K1200 D0 puts 1200 in D0, and MOV D0 D1 copies D0 to D1. The basic MOV moves 16-bit values and DMOV moves 32-bit values.

Like other application instructions, MOV runs only while the rung in front of it is true, and then it runs on every scan. Add a P suffix, as in MOVP, to run it once on the rising edge of the condition. The instruction does not scale or convert the number.

The IEC and editor equivalent

MOV is the IEC MOVE, written SPEED_REF := MOV(1200); in this editor. The editor runs MOV on every scan with no gating contact, so a conditional MOV with an LD in front is not simulated here.

What the scan does with it

A MOV every scan rewrites the destination every scan, so any other rung that also writes that register is overwritten. A MOVP writes it once and lets other code change it afterwards.

MOV K1200 D0
MOV D0 D1
Load a preset and copy it to a second register.

Common mistakes

  • Reversing source and destination and overwriting a constant register.
  • Putting an unconditional MOV for a value that an operator or HMI is supposed to change. The MOV rewrites it every scan.

What you can now do: You can load and copy data registers with MOV and say when it runs every scan and when only once.

CMP · 7 min · Pro exercise

CMP: above, equal or below in one instruction

Compare

CMP compares two numbers and tells you at once whether the first is bigger, the same or smaller, by turning on one of three devices.

What it does exactly

On the FX family, CMP S1 S2 D compares the two values and sets three consecutive bit devices starting at D: the first is on if S1 is greater than S2, the second if they are equal and the third if S1 is less than S2. Exactly one of the three is on at a time, and they keep their state until the next compare. There are also comparison contacts such as LD> and LD<, which pass the rung when the comparison holds, with no result devices at all.

Constants are written with K or H and registers with D. Because CMP writes the three result bits itself, those devices must not be driven by any other coil.

The IEC and editor equivalent

The IEC functions are GT, EQ and LT, which give one true or false result each. The editor runs the IEC form: IS_ABOVE := GT(COUNT, 50);. It does not simulate CMP or the LD> contacts, so this unit runs as IEC.

What the scan does with it

CMP runs every scan while its rung is on and refreshes all three result devices each time. Once its rung goes off the devices hold the last result, so a stale result can persist after the compare stops running.

IS_ABOVE := GT(COUNT, 50);
IS_EQUAL := EQ(COUNT, 50);
IS_BELOW := LT(COUNT, 50);
Above, equal and below flags for a target of 50 (run as IEC in this editor).

Common mistakes

  • Driving the CMP result devices from another coil as well. The compare and the coil fight over the bit.
  • Assuming the results clear when the rung goes off. They hold their last state.

What you can now do: You can get above, equal and below results from one compare and explain why the result bits hold their state.

PLS · 9 min · Pro exercise

PLS: one scan of output per rising edge

Pulse rising edge

PLS turns a held signal into a single quick pulse at the moment it switches on. It is how you make something happen once per press instead of once per scan.

What it does exactly

PLS followed by an M or Y device turns that device on for exactly one scan when the rung before it goes from off to on. The device is off again on the next scan, even while the input stays on. PLF does the same on the falling edge. There are also edge contacts, LDP for a rising edge and LDF for a falling edge, which pass the rung for one scan with no helper device.

The editor has no PLS, so the exercise builds the same pulse from primitives: LD X0, ANI M0, OUT Y0 means the button is on now and was off last scan, and a second rung, LD X0, OUT M0, stores this scan's value for the next scan.

The IEC and editor equivalent

The IEC equivalent is the R_TRIG function block, whose Q is true for one scan. The two-rung memory-relay pattern here is exactly what R_TRIG does inside.

What the scan does with it

The order of the two rungs matters. The pulse rung must come first, while M0 still holds last scan's value, and the memory rung must come second. Swapped, M0 is already updated and the pulse never fires.

LD  X0
ANI M0
OUT Y0

LD  X0
OUT M0
A one-scan pulse built from LD, ANI and a memory relay.

Common mistakes

  • Putting the memory rung before the pulse rung, which kills the pulse.
  • Using one PLS device in two places, since each PLS needs its own device.

What you can now do: You can make a one-scan pulse from a held input and explain why the rung order matters.

Frequently asked questions

What does K30 mean on a Mitsubishi timer?

K30 is a decimal constant used as the set value. On the FX family the common timer range T0 to T199 counts in 100 ms steps, so OUT T0 K30 waits three seconds. Other timer ranges use 10 ms or 1 ms steps, so check the range of the timer you use.

What is a double coil?

It is using OUT on the same device in two different rungs. Both rungs run every scan and the later one overwrites the earlier one, so the first condition appears to be ignored. Join the conditions with OR in a single rung ahead of one OUT.

What is the difference between OUT and SET?

OUT follows its rung: the device is on while the rung is on and off when it goes off. SET turns the device on and leaves it on until an RST turns it off, so it remembers.

Does the browser editor simulate PLS and CMP?

No. The editor has no PLS, PLF, CMP or edge contacts. The PLS unit builds the same one-scan pulse from LD, ANI and a memory relay, and the CMP unit runs the IEC compare functions, which give the same three results.

Training material. Follow your site procedures, local electrical code and the manufacturer's instructions. Lockout/tagout and a qualified person are required for real equipment.