Learn MITSUBISHI-GX-WORKS with Real Code Examples
Updated Nov 26, 2025
Code Sample Descriptions
1
Hello World Output in GX Works (ST)
IF X0 THEN
Y0 := TRUE;
ELSE
Y0 := FALSE;
END_IF;
A simple ST program that turns on Y0 when X0 is pressed.
2
TON Timer Example (ST)
TON(T_1, X0, T#5s);
IF T_1.Q THEN
Y0 := TRUE;
END_IF;
Using the Mitsubishi TON (On-Delay) timer in Structured Text.
3
CTU Counter Example (ST)
CTU(C_1, X1, 10);
IF C_1.CV >= 10 THEN
Y0 := TRUE;
END_IF;
A simple up-counter that activates Y0 after 10 pulses.
5
Analog Input Scaling (0–4000 to 0–100)
Scaled := (D0 * 100) / 4000;
Scaling Mitsubishi raw analog input range to engineering units.
6
Motor Start/Stop Latch (ST)
IF X0 THEN
M0 := TRUE;
END_IF;
IF X1 THEN
M0 := FALSE;
END_IF;
Y0 := M0;
Classic seal-in motor circuit using X0 and X1.
7
Rising Edge Detection (ST)
Prev := Curr;
Curr := X0;
R_TRIG := Curr AND NOT Prev;
Basic rising edge detection using historical bool.
8
For Loop Array Sum (ST)
Sum := 0;
FOR i := 0 TO 9 DO
Sum := Sum + D[i];
END_FOR;
Summing 10 data registers D0–D9.
9
Simple PID Call (ST)
PID(PV := D100,
SP := D200,
OUT => D300,
EN := TRUE);
Calling a PID block in Mitsubishi ST.
10
PWM Output Example (ST)
IF Duty > 100 THEN
Duty := 100;
END_IF;
PWM_CH1.Duty := Duty;
Simple PWM control using a duty cycle tag.