4. Structured Text (ST)
- Description: A high-level programming language with syntax similar to Pascal or C. Very powerful and flexible.
- Applicable Scenarios: Complex mathematical calculations, algorithms, data processing.
- Example: Analog Temperature PID Control (Simplified)
- Control Requirements: Read the temperature value, compare it with the set point, and output a control signal through PID computation.
- Character Diagram (Code Block):
+—————————————–+ | // Temperature PID Control Program | | VAR | | ActualTemp : REAL; // Actual Temperature | | SetPoint : REAL := 80.0; // Set Temperature | | Output : REAL; // Output Value | | END_VAR | | | | ActualTemp := AI_Temp; // Read analog input | | | | // Simple Proportional Control | | IF ActualTemp < SetPoint THEN | | Output := (SetPoint – ActualTemp) * 0.5;| | ELSE | | Output := 0.0; // Stop heating when temperature is reached | | END_IF; | | | | AQ_Heater := Output; // Output to analog | +—————————————–+
- Program Explanation:
- This is a simplified control logic, not a complete PID.
- The program reads the actual temperature ActualTemp.
- It uses the IF…THEN…ELSE statement to determine: if the actual temperature is lower than the set point, it outputs a signal proportional to the temperature difference (proportional control); otherwise, it outputs 0.
- Finally, the calculated result Output is sent to the analog output address AQ_Heater (e.g., heater).
5. Instruction List (IL)
- Description: A low-level programming language similar to assembly language. Composed of a series of instructions.
- Applicable Scenarios: Now rarely used, mainly for maintaining legacy systems or in cases with extreme size constraints on code.
- Example: Implementing Basic AND Logic
- Control Requirements: When I0.0 and I0.1 are both 1, let Q0.0 output 1.
- Character Diagram (Code List):
+—————-+ | LD I0.0 | // Load (read) the value of I0.0 to the current result | AND I0.1 | // Perform AND operation with I0.1’s value | ST Q0.0 | // Store (output) the current result to Q0.0 +—————-+
- Program Explanation:
- LD I0.0: Loads the state (0 or 1) of input I0.0 into an invisible “accumulator”.
- AND I0.1: Performs a logical AND operation between the value in the “accumulator” and the value of I0.1, placing the result back in the “accumulator”. The result is 1 only if both are 1.
- ST Q0.0: Sends the final result of the “accumulator” to output Q0.0.
Summary
|
Language |
Type |
Advantages |
Typical Applications |
Core Example |
|
Ladder Diagram (LD) |
Graphical |
Intuitive and easy to understand, friendly to electrical backgrounds |
Logic control, interlocking |
Start/Stop circuit, self-locking |
|
Function Block Diagram (FBD) |
Graphical |
Clear signal flow, easy to modularize |
Process control, signal processing |
AND block + Timer |
|
Sequential Function Chart (SFC) |
Graphical |
Very clear sequential flow structure |
Sequential machinery, process flow |
Steps and Transition Conditions |
|
Structured Text (ST) |
Text-Based |
Powerful and flexible, suitable for complex algorithms |
Calculations, algorithms, data processing |
IF-THEN-ELSE statements |
|
Instruction List (IL) |
Text-Based |
Compact code |
Legacy systems, specific optimizations |
LD, AND, ST instructions |