Timers in PLC - Structured Text

How do timers work in PLC Structured Text (ST)? How do we announce them?

I studied PLC standard (IEC 61131-3) and they don't talk about timers in ST. I know most PLC programmers do them in ladder logic, but in this particular case I really need to declare the timers in ST.

I am using Rockwell PLC.

+5


source to share


6 answers


You can find explanations about timers and how to use (declare) them in the help system of your IDE. For example, in CODESYS you can read about standard library timers.

In general, you can declare a timer delay (TON) as:

VAR
    MY_TON: TON;
END_VAR
(* standard.library should be added to the project *)

      

Then you can use it:

MY_TON(IN:= IN_VALUE,PT:= TIME_SET);
(*IN_VALUE - is BOOL variable that activates your timer
  TIME_SET - is TIME variable*)

SOME_OUTPUT := MY_TON.Q;
(*Q - is the timer output, and it can be used as BOOL variable. *)

      



You can also use constants to set up the timer:

MY_TON(IN:= True, PT:= t#5s);

      

As a BOOL variable, the timer output can be used in IF and WHILE statements:

IF MY_TON.Q THEN
    (*Some statements...*)
END_IF

WHILE MY_TON.Q DO
    (*Some statements...*)
END_WHILE

      

All examples run in CODESYS v3.5 SP5 and v2.3. For other IDEs, there may be nuances.

+8


source


I solved it in Gx-Works (Mitsubishi / FXCPU):

TON_1(IN:= Enable_Timer,PT:= PresetTime ,Q:= Output,ET:= TimeLeft);

      



Don't forget to include TON_1 :)

+1


source


The timer works so that it TON.Q

goes high only if it is TON.IN

constantly high, at least for the duration TON.PT

.

This ensures that it TON.Q

will only be high if it TON.IN

is in a stable high state.

This can be useful, for example, to ensure that the output is only turned on if the button is pressed for at least the duration TON.PT

.

+1


source


Typically, you set a preset time and start a timer. After this time, a certain bit will be executed. When you reset, the time will be reset.

0


source


I did it with OMRON PLC which supports ST language.

There is a timer interrupt in the PLC, and we used it to create our own timer in ST, and then we could drop the PLC restrictions. When the PLC is powered on, the code inside the interrupt task is executed every interrupt, and you can write "A = A + 1" inside the interrupt handler.

When you start using the timer, just write down the current data A. Let's say A1; interval:

Interval= Current_Data_Of_A-A1

      

Then compare Interval

with the desired time. If Interval

more than needed, run the following code.

0


source


We also created our own timer structure using the millisecond counter provided by the PLC so that we can create (Schneider Electric) timer arrays when we need and exceed the PLC limit.

TTIMER
 Count: UINT 
 timclock :INT 
 OUT :BOOL
 IN: BOOL 
END_STRUCT;
TIM_SOD=ARRAY[0..1] OF TTIMER;

(*This part runs every cycle of PLC*)
FOR I:=0 TO 1 DO
  IF TIM_SOD[I].IN (*timer on*)
  THEN
   IF (TIM_SOD[I].Count)>0 (*number of seconds left*)
   THEN
    IF ABS_INT(IN:=timclock-TIM_SOD[I].CLK)>=100 (*timclock -mSec counter*)
    THEN aTIM_SOD[I].Count:=TIM_SOD[I].Count-1;
     TIM_SOD[I].CLK:=TIM_SOD[I].CLK+100;
    END_IF;
   ELSE
    TIM_SOD[I].IN:=0; (*timer off*)
    TIM_SOD[I].Out:=1; (*Timer have run out*)
   END_IF;
  END_IF;
 END_FOR;
(*-------------------------------------------------*)

(*This part runs once when we need start timer*)
  TIM_SOD[0].COUNT:=H690; (*delay in seconds*)
  TIM_SOD[0].CLK:=TIMCLOCK; (*current value of mSec counter*)
  TIM_SOD[0].IN:=True; 
(*-------------------------------------------------*)

(*This part runs once when we need stop timer*)
  TIM_SOD[0].IN:=False;


(*Checking timer*)
IF TIM_SOD[0].OUT
THEN
  (*doing smth......*)
END_IF;

      

0


source







All Articles