Codesys 2.3, retain timer

Lahotron

Member
Join Date
Aug 2015
Location
Oslo
Posts
4
Hi,

I'm using IFM CR0401 controller.
Can enyone explain me why my retain timer (TON), is set to true after power loss (doesn't hold old value, ET = PT).

I tried with very simple piece of test code.
Seems that test variable and counter hold their old values, but not the timer.

VAR RETAIN
test_timer: TON;
test_counter: CTU;
test_variable: BOOL;
END_VAR

test_timer(IN:= TRUE, PT := T#300s);
test_counter (CU := test_variable, PV := 10);
 
Thanks for replies.
I was confused because counter works fine as retain... why timer shouldn't.
My case is to count up time in a loop of 5 min, after power failure the timer should continue from the point before failure.
Solution looks like that:

Code:
VAR
  test_timer: TON;
  startup: BOOL := TRUE;
  set_time: TIME;
END_VAR

VAR RETAIN
  elapsed_time: TIME := T#0s;
END_VAR

IF startup THEN
  set_time := T#300s - elapsed_time;
  startup := FALSE;
END_IF

IF test_timer.Q THEN
  test_timer.IN := FALSE;
  set_time := T#300s;
ELSE
  test_timer.IN := TRUE;
END_IF;

test_timer (PT := set_time);
elapsed_time := test_timer.ET;
 
Last edited:

Similar Topics

I'm working myself into a bit of a lather. I'm in need of some assistance with programming an 'Hour Meter' in Codesys V3. I'm using a Wago...
Replies
5
Views
3,883
A couple questions regarding retentive and persistent variables in Codesys v2.3 using the wago 750-841. Cannot seem to find any information in the...
Replies
3
Views
10,418
Hello, I would like to execute code saved in initialization FB on the first start of the PLC. It is basically something like OB100 in the Siemens...
Replies
5
Views
109
Hi! What is the way to convert the code from the Codesys code to the Tia Portal? Regards, WK
Replies
4
Views
124
Hello to all, can you please provide an example of obtaining a current working directory as a string in CodeSys? For example, during starting the...
Replies
7
Views
238
Back
Top Bottom