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,851
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,353
Hello, I am using a Hitachi Micro EHV+ for a small project, and I wanted to have a Web visu, done with Codesys V3.5 SP13 Patch 2. I test the...
Replies
6
Views
305
Hello, I have a requirement to manage the text alignment dynamically. So, for example: 1. English Texts should be displayed from Left in...
Replies
0
Views
93
Hello, I am new to Codesys, and am trying to learn about it for a project we're developing. I've got a couple questions, but first a little...
Replies
1
Views
164
Back
Top Bottom