×

Subscribe to newsletter

subscribe to our weekly newsletter to get notified with latest story and article Subscribe now!




PLC BLOG | Codesys Plc timer
Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


codesys ladder programming timer: TOF,TON and TP

in codesys ladder programming have three types of timer, pulse timer TP, turn-off delay TOF and turn on delay timer TON, input IN and preset time (PT) are input and elapsed time (ET) and output Q are output.To add an enable input and enable output to the instruction, select [With EN/ENO] from the "Instructions" pane (LD, FBD or IL editor).

  • IN (input) :- bool data type input for start and stop timer.
  • PT (preset time) :- preset time or clock period of a timer.
  • Q (Output) :- bool type output, it is depend on types of timer.
  • ET (elapsed time) :- data type for ET is time elapsed time of timer.it is elapsed period of timer.
  • instances :- contains the name of the module instance.
instances is important when you define any type of function block, By declaring the function Block(FB) you create a copy of the original FB. This copy is saved under instance name. A separate data area is reserved for this copy.diffrent timer instace name and type
  • TP : instance type TP
  • TON : instance type TON
  • TOF : instance type TOF


TP, a pulse timer

The function block TP allows you to program a pulse timer with a defined clock period. input IN and Preset time PT are input variables of the BOOL and TIME data types respectively. output Q and elapse time ET are output variables of the BOOL and TIME data types. when IN is False or set to 0 then Q is FALSE and set to 0 and ET is 0. if IN set to true or set to 1 then timer begin to be counted in milliseconds until PT = ET then remain constant. Q is TRUE or set to 1 if IN is set to TRUE and ET is less than or equal to PT. Otherwise it is FALSE.

  • instance TP_instance data type TP
  • IN start_timer data type BOOL. Rising edge starts the pulse timer and sets Q to TRUE
  • PT preset TIME for example t#10s or t#10ms . Length of the pulse.
  • ET data type time. Elapsed time since pulse timer started. It will then remain constant after PT is reached.
  • Q output data type bool


TOF: turn-off delay

The function block TOF allows you to program a switch-off delay. in TOF input variables are IN and PT data type BOOL and TIME. Q and E are output variables BOOL and TIME are data types. If IN is TRUE, the outputs are TRUE. when IN becomes true to false, timer start counting in milliseconds until its value is equal to PT, then It will then remain constant. Q is FALSE when IN is FALSE and ET equal to or less then PT. Otherwise it is TRUE.

  • instance name data tye TOF
  • IN data type is BOOL. Falling edge: starts delay counter and Rising edge: resets delay counter
  • PT preset TIME for example t#10s or t#10ms .Time for the delay counter [ms].
  • ET data type time. Elapsed time since falling edge at IN.
  • Q output data type bool


TON:turn-on delay

The function block Timer On Delay implements a turn-on delay.TON(IN, PT, Q, ET) means: IN and PT are input variables of the BOOL and TIME data types respectively. Q and ET are output variables of the BOOL and TIME data types respectively. If IN is FALSE , Q is FALSE and ET is 0. As soon as IN becomes TRUE, the time will begin to be counted in milliseconds until ET = PT then remain constant and output Q is TRUE. Q is True PT = ET Otherwise it is FALSE. Thus, Q has a rising edge when the time indicated in PT in milliseconds has run out.
  • instance name data tye TON
  • IN data type is BOOL. Rising edge: starts delay counter,Falling edge: resets delay counter
  • PT preset TIME for example t#10s or t#10ms .Time for the delay counter [ms].
  • ET data type time. Elapsed time since falling edge at IN.
  • Q output data type bool, FALSE if IN is FALSE TRUE if IN is TRUE and delay time PT elapsed


Time Constant

TIME constants can be declared in CoDeSys. These are generally used to operate the timer in the standard library. A TIME constant is always made up of an initial "t" or "T" and a number sign "#".
  • days identified by d. example t#1d
  • hours identified by h. example t#10h;
  • minutes identified by m. example t#10m;
  • seconds identified by s. example t#10s;
  • milliseconds identified by ms. example T#10ms;


convert another data type into time

so if you want to convert int, DINT, DWORD etc. in TIME format so you can use convert block like DATATYPE_TO TIME and if you want to conver time into another data type use TIME_TO_DATATYPE.
  • WORD_TO_TIME, WORD in TIME
  • WORD_TO_TIME converts a value of the data type WORD into a value of the data type TIME.
  • DWORD_TO_TIME, DOUBLE WORD in TIME
  • DWORD_TO_TIME converts a value of the data type DWORD into a value of the data type TIME.
  • INT_TO_TIME, INTEGER into TIME
  • INT_TO_TIME converts a value of the data type INT into a value of the data type TIME.
  • DINT_TO_TIME, DOUBLE INTEGER into TIME
  • DINT_TO_TIME converts a value of the data type DINT into a value of the data type TIME.
  • REAL_TO_TIME, REAL into TIME
  • REAL_TO_TIME converts a value of the data type REAL to a value of the data type TIME.

conversion of time value to other data types

for conversion of time value into another data type used following blocks
  • TIME_TO_WORD, TIME into WORD
  • TIME_TO_WORD converts a value of the data type TIME into a value of the data type WORD.
  • TIME_TO_DWORD, TIME into DOUBLE WORD
  • TIME_TO_DWORD converts a value of the data type TIME into a value of the data type DWORD.
  • TIME_TO_INT, TIME into INTEGER
  • TIME_TO_INT converts a value of the data type TIME into a value of the data type INT.
  • TIME_TO_DINT, TIME into DOUBLE INTEGER
  • TIME_TO_DINT converts a value of the data type TIME into a value of the data type DINT.
  • TIME_TO_REAL, TIME into REAL
  • TIME_TO_REAL converts a value of the data type TIME to a value of the data type REAL.
"NOTE:_in codesys you can convert more data types into time but above are useful in industry purpose."


example of timer

consider a simple example, in this programming example timer input bit (IN) is depended on equal compare block output. compare block compare preset (PT) and elapsed time(ET) value if both are equal output of compare block set to true this condition stop timer as soon as when timer stop estimate timer(ET) value set to 0 and not equal to preset value so output of compare block set to false then timer again start from begining.

 
Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


Suggested Post


 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

comment


nkelly
neil.kelly@ccamatil.com.au 2022-04-14
Thank you for this content, this is very helpful for me as a plc programming beginner.