ถ้าคุณเคยเขียน PLC แบบ Ladder Diagram มาตลอด แล้วเจอโปรแกรมที่เขียนด้วย Structured Text (ST) ครั้งแรก อาจรู้สึกว่ามันคล้าย Code Python หรือ C มากกว่า Ladder สัญลักษณ์ที่คุ้นเคย บทความนี้อธิบาย Structured Text ตั้งแต่พื้นฐาน เหมาะกับงานไหน และต่างจาก Ladder อย่างไร สำหรับวิศวกรที่ทำงานกับ PLC Mitsubishi และ Siemens ในโรงงานชลบุรีและระยอง

Structured Text (ST) คืออะไร?

Structured Text เป็น 1 ใน 5 ภาษา PLC มาตรฐาน IEC 61131-3 มีรูปแบบคล้าย High-Level Programming Language เช่น Pascal หรือ C PLC ที่รองรับ ST ได้แก่ Siemens S7-1200/1500 (TIA Portal), Mitsubishi iQ-R, iQ-F (GX Works3), Omron NJ/NX (Sysmac Studio), Beckhoff TwinCAT

Structured Text ต่างจาก Ladder Diagram อย่างไร?

Ladder Diagram (LAD)Structured Text (ST)
รูปแบบGraphical — Rung, Contact, CoilText-based — IF/THEN, FOR, WHILE
เรียนรู้ง่ายถ้ามีพื้นฐานElectrical / Relay LogicProgramming / IT Background
เหมาะกับSequential Logic, Basic I/OCalculation, Algorithm, Complex Logic
อ่านง่ายเมื่อLogic ไม่ซับซ้อนLogic ซับซ้อน มีการคำนวณ
Code ยาวแค่ไหน10 Condition = 10 Rung10 Condition = 10 บรรทัด IF
Debuggingเห็น State ทุก Contact Real-timeต้องใช้ Watch Variable

Syntax พื้นฐานของ Structured Text

IF/THEN/ELSIF/ELSE

(* ตัวอย่าง: ควบคุม Motor ตามอุณหภูมิ *)
IF Temperature > 80.0 THEN
    Motor_Cool := TRUE;
    Motor_Run  := FALSE;
ELSIF Temperature > 60.0 THEN
    Motor_Cool := FALSE;
    Motor_Run  := TRUE;
ELSE
    Motor_Cool := FALSE;
    Motor_Run  := FALSE;
END_IF;

FOR Loop

(* คำนวณผลรวม Array 10 ตัว *)
Total := 0;
FOR i := 0 TO 9 DO
    Total := Total + DataArray[i];
END_FOR;
Average := Total / 10;

CASE Statement

(* State Machine สำหรับ Recipe Selection *)
CASE MachineState OF
    0: (* IDLE *)
        Output_Enable := FALSE;
    1: (* RUNNING *)
        Output_Enable := TRUE;
        ProcessTimer(IN:=TRUE, PT:=T#5S);
    2: (* FAULT *)
        Output_Enable := FALSE;
        AlarmBit := TRUE;
END_CASE;

งานที่ Structured Text เหมาะมากกว่า Ladder

ข้อควรระวังเมื่อใช้ Structured Text ใน PLC

ST กับ Ladder ใช้ร่วมกันได้ไหม?

ได้! PLC รุ่นใหม่อย่าง Mitsubishi iQ-R, Siemens S7-1500 และ Omron NJ สามารถใช้ทั้ง Ladder และ ST ในโปรเจกต์เดียวกันได้ Best Practice คือ:

ควรเรียกผู้เชี่ยวชาญเมื่อไหร่?

สรุป

Structured Text เป็นภาษา PLC ที่ทรงพลังมากสำหรับงานคำนวณและ Algorithm ที่ซับซ้อน ทำงานร่วมกับ Ladder ได้ดีเยี่ยม ทีม Xeniel Automation รับเขียนโปรแกรม PLC ทั้ง Ladder และ Structured Text สำหรับโรงงานในชลบุรีและระยอง

ต้องการวิศวกร PLC ที่เขียน Structured Text ได้?

Xeniel Automation รับเขียน PLC ทั้ง Ladder และ Structured Text ทุก Platform Mitsubishi Siemens Omron Beckhoff บริการนิคมชลบุรีและระยอง

ปรึกษาวิศวกรฟรี ทันที!
โทร 098-965-3845 | LINE: @xeniel.24

ตัวอย่างโค้ด Structured Text ที่ใช้จริงในโรงงาน

ตัวอย่าง 1: PID Temperature Control

(* Temperature PID Control *)
IF Enable THEN
    Error := Setpoint - ActualTemp;
    Integral := Integral + (Error * ScanTime);
    Derivative := (Error - PrevError) / ScanTime;
    Output := (Kp * Error) + (Ki * Integral) + (Kd * Derivative);
    
    (* Output Limiting *)
    IF Output > MaxOutput THEN Output := MaxOutput; END_IF;
    IF Output < 0.0 THEN Output := 0.0; END_IF;
    
    PrevError := Error;
END_IF;

ตัวอย่าง 2: Recipe Management

(* Recipe Selection *)
CASE RecipeNo OF
    1: Setpoint := 80.0; Speed := 150; MixTime := 120;
    2: Setpoint := 95.0; Speed := 200; MixTime := 90;
    3: Setpoint := 70.0; Speed := 100; MixTime := 180;
    ELSE: Setpoint := 0.0;
END_CASE;

ตาราง: Ladder vs ST เลือกอะไรสำหรับงานแบบไหน

ลักษณะงานแนะนำ Ladderแนะนำ ST
Digital I/O Control ง่ายๆ
Sequence Control ทั่วไป
PID Control / Math
Recipe Management
String Processing
Array / Data Table
Function Block Reuse
Maintenance ทีมช่างทั่วไป

ควรเรียกผู้เชี่ยวชาญเมื่อไหร่?

สรุป

Structured Text ไม่ใช่มาแทน Ladder แต่เป็นเครื่องมือเพิ่มเติมสำหรับงานที่ Logic ซับซ้อน โดยเฉพาะ PID, Recipe และ Math Calculation Xeniel Automation รับเขียนโปรแกรม PLC ทั้ง Ladder และ ST สำหรับโรงงานในชลบุรีและระยอง

ต้องการเขียนโปรแกรม PLC ด้วย Structured Text? ปรึกษา Xeniel

Xeniel Automation รับเขียนโปรแกรม PLC ทั้ง Ladder, ST, FBD สำหรับงาน PID, Recipe, Motion ออนไซต์ชลบุรีและระยอง

ปรึกษาฟรีทาง LINE โทร 098-965-3845