Click the blue text
PLC Automation Hub
Follow us
Master ST language to make your PLC programming more efficient and intuitive
What is ST Language?
ST (Structured Text) is a high-level PLC programming language that resembles Pascal or C language, adopting a structured programming approach. Compared to Ladder Diagram, ST language is more convenient and efficient for handling complex calculations, loop control, and data structures.
Huichuan PLC fully supports the ST language defined in the IEC 61131-3 standard, providing engineers with powerful programming tools.
Basic Syntax of ST Language
1. Variable Declaration (Using Chinese Variable Names)
Before programming, we need to declare variables. Using Chinese variable names makes the program more readable:
VAR
Counter: INT; // Integer variable
CurrentTemperature: REAL; // Real variable
MotorStatus: BOOL; // Boolean variable
Message: STRING; // String variable
StartButton: BOOL; // Input signal
StopButton: BOOL; // Input signal
END_VAR
2. Assignment Statements
Counter := 100; // Integer assignment
CurrentTemperature := 25.6; // Real assignment
MotorStatus := TRUE; // Boolean assignment
Message := ‘System is ready!’; // String assignment
3. Basic Operators
-
Arithmetic Operators:
<span><span>+</span></span>,<span><span>-</span></span>,<span><span>*</span></span>,<span><span>/</span></span> -
Comparison Operators:
<span><span>></span></span>,<span><span><</span></span>,<span><span>=</span></span>,<span><span>>=</span></span>,<span><span><=</span></span>,<span><span><></span></span> -
Logical Operators:
<span><span>AND</span></span>,<span><span>OR</span></span>,<span><span>NOT</span></span>,<span><span>XOR</span></span>
First ST Program: Motor Control
Let’s learn ST programming through a simple motor control example.
PROGRAM MainProgram
VAR
StartButton: BOOL; // Start button input
StopButton: BOOL; // Stop button input
MotorRunning: BOOL; // Motor running status
RunTime: INT; // Runtime counter
FaultSignal: BOOL; // Fault detection signal
END_VAR
// Main program logic – Motor start/stop control
IF StartButton AND NOT StopButton AND NOT FaultSignal THEN
MotorRunning := TRUE;
ELSIF StopButton OR FaultSignal THEN
MotorRunning := FALSE;
END_IF;
// Runtime statistics
IF MotorRunning THEN
RunTime := RunTime + 1;
END_IF;
// Fault detection logic
IF RunTime > 10000 THEN
FaultSignal := TRUE;
Message := ‘Motor running timeout, please check!’;
END_IF;
Advanced Example: Temperature PID Control
Next, we will look at a more complex example – a temperature PID control system.
PROGRAM TemperatureControlProgramVAR SetTemperature: REAL := 100.0; // Set temperature value ActualTemperature: REAL; // Actual detected temperature HeaterPower: REAL; // Heater output power TemperatureError: REAL; // Current temperature error LastError: REAL; // Last temperature error IntegralTerm: REAL; // PID integral term ProportionalGain: REAL := 0.8; // P parameter IntegralGain: REAL := 0.01; // I parameter DerivativeGain: REAL := 0.1; // D parameter SystemStatus: STRING; // System status descriptionEND_VAR
// PID control algorithmTemperatureError := SetTemperature - ActualTemperature;
// Integral term calculation (with anti-windup protection)IF ABS(IntegralTerm) < 1000 THEN IntegralTerm := IntegralTerm + TemperatureError;END_IF;
// PID output calculationHeaterPower := ProportionalGain * TemperatureError + IntegralGain * IntegralTerm + DerivativeGain * (TemperatureError - LastError);
// Limit output range to 0-100%IF HeaterPower > 100.0 THEN HeaterPower := 100.0;ELSIF HeaterPower < 0.0 THEN HeaterPower := 0.0;END_IF;
// Update last errorLastError := TemperatureError;
// System status monitoringIF TemperatureError < 5.0 AND TemperatureError > -5.0 THEN SystemStatus := 'Temperature Stable';ELSE SystemStatus := 'Temperature Adjusting';END_IF;
Timer Application Example
PROGRAM TimerControlProgramVAR StartSignal: BOOL; // Start signal DelayTimer: TON; // On-delay timer RunIndicator: BOOL; // Run indicator light TimerDuration: TIME := T#5S; // Set delay timeEND_VAR
// Timer applicationDelayTimer(IN := StartSignal, PT := TimerDuration);
// Output controlRunIndicator := DelayTimer.Q;
// Timer status monitoringIF DelayTimer.ET > T#3S THEN Message := 'Timer is about to complete';END_IF;
Array and Loop Application Example
PROGRAM DataCollectionProgramVAR TemperatureArray: ARRAY[1..10] OF REAL; // Temperature data array AverageTemperature: REAL; // Average temperature value LoopIndex: INT; // Loop counter TotalTemperature: REAL; // Total temperatureEND_VAR
// Calculate average temperatureTotalTemperature := 0.0;FOR LoopIndex := 1 TO 10 DO TotalTemperature := TotalTemperature + TemperatureArray[LoopIndex];END_FOR;AverageTemperature := TotalTemperature / 10.0;
// Temperature anomaly detectionIF AverageTemperature > 80.0 THEN Message := 'High temperature warning!';ELSIF AverageTemperature < 20.0 THEN Message := 'Low temperature warning!';ELSE Message := 'Temperature normal';END_IF;
Advantages of ST Language
-
Strong Mathematical Calculation Capability: Suitable for complex mathematical calculations and algorithm implementations
-
Clear Code Structure: Facilitates writing and maintaining large programs
-
High Execution Efficiency: Fast speed when processing large amounts of data
-
Easy Portability: Code can be migrated between different brands of PLCs
-
Good Readability: Using Chinese variable names aligns with the reading habits of Chinese engineers
Learning Suggestions
-
Start Simple: First master the basic syntax and common instructions
-
Practice More: Deepen understanding through practical projects
-
Reference Manuals: Always refer to the Huichuan PLC programming manual
-
Naming Conventions: Use meaningful Chinese variable names to improve code readability
-
Complete Comments: Add detailed comments for complex logic
Conclusion
As an important tool for PLC programming, ST language plays a significant role in Huichuan PLC. By using Chinese variable names, the readability and maintainability of the program can be greatly improved. In practical applications, flexibly utilizing various features of ST language according to specific project requirements will greatly enhance programming efficiency and quality.
Master ST language and embark on an efficient PLC programming journey!
Welcome to follow our public account for more PLC programming tips and industrial automation knowledge!
Recommended Reading:
- Use all your strength! Nine steps to ensure stable operation of Siemens PLC
- Siemens S7-1500 PLC Troubleshooting: Transform into an industrial “doctor” to quickly “cure” production line downtime!
- [10-Year Siemens PLC Veteran Upgrade Path] From screwing modules to mastering communication architecture: My blood and tears technical stack guide
- Three “weapons” of servo motors: Detailed explanation of position/velocity/torque control (with practical Siemens SCL code)
- Core secrets of Siemens PLC programming: What are FB, FC, DB, OB? You will understand after reading this!
- Why can’t PLC engineers with a monthly salary of 20,000 stay? The “career burnout” behind high salaries is consuming this industry!
- Siemens PLC Programming: Ladder Diagram vs SCL, which one is for you? A comprehensive beginner’s guide + practical code!
- Say goodbye to “spaghetti code”! Siemens PLC step programming “three-step method”, double efficiency without pitfalls!
- Siemens SCL communication heartbeat monitoring: Practical guide for industrial-grade heartbeat programs
- Siemens 1200 and Weintek tag communication: Say goodbye to manual address filling, this “smart translator” makes debugging three times faster!
- Siemens SCL Practical: Step-by-step guide to writing station control function blocks
- Siemens S7-1200 Mixed Programming Practical: The golden combination rules of SCL and LAD
- Electrical automation encirclement: Ten years of hard work for this heartfelt industry experience summary
- Siemens SCL workstation control program: Start/stop control + three-color light + buzzer alarm
- Mitsubishi FX3U PLC dual pump constant pressure water supply explained: Frequency + power frequency intelligent switching + safety emergency stop system
- Electrical automation major graduation guide:
- Employment direction and salary prospects fully analyzed
- Electrical automation college students: Starting salary not inferior to undergraduates? Full disclosure of the technical counterattack roadmap!
- Siemens S7-200 SMART free port communication explained: Introduction to flexible serial communication solutions
- Ultimate solution for Siemens SCL full-function servo control: 8 motion modes + 5 levels of safety protection
- Let data speak! A scientific guide for choosing majors for science vs. liberal arts students (with employment salary & trend analysis)
Share to let more people see

Like
Collect
Share