Timers in PLC - Structured Text

懵懂的女人 提交于 2021-02-04 15:39:07

问题


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

I've been studying a standard of PLC (IEC 61131-3), and they do not speak about timers in ST. I know the great majority of PLC programmers do them in ladder logic, but in this particular case I really need to declare timers in ST.

I am using a Rockwell PLC.


回答1:


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

In general, you can declare 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's output, and it can be used as BOOL variable. *)

You can also use constants to set up your timer:

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

As a BOOL variable, the timer's 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 are run in CODESYS v3.5 SP5 and v2.3. For other IDEs there might be nuances.




回答2:


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

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

Remember to declare TON_1 :)




回答3:


The timer works so that TON.Q goes high only if TON.IN is continuously high for at least the duration of TON.PT.

This makes sure that TON.Q only goes high if TON.IN is in a stable high state.

This could be useful for instance to ensure that the output is only enabled if a button is pressed for at least a duration of TON.PT.




回答4:


Typically, you set a preset time and enable the timer. When it elapses, there will be done sort of done bit set true. When you reset the enable, the time will reset as well.




回答5:


I have done this with an OMRON PLC which supports the ST language.

There's a timer interrupt in the PLC, and we used it to build our own timer in ST, and then we could skip out of the PLC limitations. When the PLC power on, the code inside the interrupt task is executed every interruption, and you can write "A=A+1" inside the interrupt handler.

When you start to use the timer, just record the current data of A. Let's say A1; the interval is:

Interval= Current_Data_Of_A-A1

Then compare Interval to the time you want. If Interval is bigger than the time you want, then execute the next code.




回答6:


We also have built our own timer structure with using milliseconds counter provided by PLC, so we could make arrays of timer (Schneider Electric) when we need and exceed PLC limitation.

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;


来源:https://stackoverflow.com/questions/25682962/timers-in-plc-structured-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!