The Full Wiki

More info on Structured text

Structured text: Wikis

Advertisements

Note: Many of our articles have direct quotes from sources you can cite, within the Wikipedia article! This article doesn't yet, but we're working on it! See more info or our list of citable articles.

Encyclopedia

From Wikipedia, the free encyclopedia

Structured text is one of the 5 languages supported by the IEC 61131-3 standard. It is designed for programmable logic controllers (PLCs). It is a high level language that is block structured and syntactically resembles Pascal. All of the languages share IEC61131 Common Elements. The variables and function calls are defined by the common elements so different languages can be used in the same program.

Complex statements and nested instructions are supported:

  • Iteration loops (REPEAT-UNTIL; WHILE-DO)
  • Conditional execution (IF-THEN-ELSE; CASE)
  • Functions (SQRT(), SIN())

Sample Program

(* simple state machine *)
TxtState := STATES[StateMachine];
 
CASE StateMachine OF
   1: ClosingValve();
ELSE
    ;; BadCase();
END_CASE;

Additional ST Example Programming examples

INTERFACE
    VAR_GLOBAL
        Start_Stop  : BOOL;             // Global variable to represent Operator Input
        ON_OFF      : BOOL;             // Global variable to represent Output Coil
    END_VAR
 
    PROGRAM Monitor_Start_Stop;         // Declare the program
END_INTERFACE
 
IMPLEMENTATION
 
PROGRAM Monitor_Start_Stop              // Actual Program
    VAR                                 // Temporary variables for logic handling
        ONS_Trig    : BOOL;
        Rising_ONS  : BOOL;
    END_VAR
// Start of Logic
    // Catch the Rising Edge One Shot of the Start_Stop input
    ONS_Trig    := Start_Stop AND NOT Rising_ONS;
 
    // Main Logic for Run_Contact -- Toggle ON / Toggle OFF ---
    ON_OFF := (ONS_Trig AND NOT ON_OFF) OR (ON_OFF AND NOT ONS_Trig);        
 
    // Rising One Shot logic   
    Rising_ONS := Start_Stop;
    END_PROGRAM
 
END_IMPLEMENTATION
 
//=======================================================================
// Function Block Timed Counter :  Incremental count of the timed interval
//=======================================================================
FUNCTION_BLOCK FB_Timed_Counter
    VAR_INPUT
        Execute         : BOOL := FALSE;        // Trigger signal to begin Timed Counting
        Time_Increment  : REAL := 1.25;         // Enter Cycle Time (Seconds) between counts
        Count_Cycles    : INT  := 20;           // Number of Desired Count Cycles
    END_VAR
 
    VAR_OUTPUT
        Timer_Done_Bit  : BOOL := FALSE;        // One Shot Bit indicating Timer Cycle Done
        Count_Complete  : BOOL := FALSE;        // Output Bit indicating the Count is complete            
        Current_Count   : INT  := 0;            // Accumulating Value of Counter
    END_VAR
 
    VAR
        CycleTimer      : TON;                  // Timer FB from Command Library
        CycleCounter    : CTU;                  // Counter FB from Command Library
        TimerPreset     : TIME;                 // Converted Time_Increment in Seconds to MS
    END_VAR
 
// Start of Function Block programming
TimerPreset := REAL_TO_TIME(in := Time_Increment) * 1000;  
 
CycleTimer(
    in := Execute AND NOT CycleTimer.Q
    ,pt := TimerPreset);
 
    Timer_Done_Bit := CycleTimer.Q;
 
CycleCounter(
    cu := CycleTimer.Q
    ,r := NOT Execute
    ,pv := Count_Cycles);     
 
    Current_Count := CycleCounter.cv;
    Count_Complete := CycleCounter.q;
 
END_FUNCTION_BLOCK

External links

Advertisements

Advertisements






Got something to say? Make a comment.
Your name
Your email address
Message