theColonel26
Lifetime Supporting Member
Does anyone know of a library that already has a implemented RTO?
I was going to write my own but I'd rather not take the time.
I was going to write my own but I'd rather not take the time.
I am already pretty far along with writing my own Sadly.
uuuuhhh what?36s TON triggers a UDINT count of centih?
uuuuhhh what?
exactly, it's been mentioned many times in this forum, good for about 5Ma, and too simple to not work (famous last words ):Hour meter example
IF reset_rtoch THEN ch_udint := 0; END_IF; (* Bell *)
TON(IN=on AND not rtoq,PT=T#36s,Q=rtoq); (* Here's *)
ch_udint := ch_udint + rtoq; (* the beef *)
display_rto_h_real := 0.01 * ch_udint; (* Whistle *)
FUNCTION_BLOCK RTO
VAR_INPUT
IN : BOOL; // Run (Hold)
PT : TIME; // Run Duration
RST : BOOL; //Reset
END_VAR
VAR_OUTPUT
Q : BOOL; // Done
ET : TIME; // Elapsed Time
TT : BOOL; // Timer Running
Remaining : TIME; // Time Remaining
END_VAR
VAR
previousElapsed : TIME;
IN_R : R_TRIG; // IN Rising Edge
IN_F : F_TRIG; // IN Falling Edge
Q_R : R_TRIG; // Done Rising Edge
timer : TON;
END_VAR
[INDENT]
IN_R(CLK := IN);
IN_F(CLK := IN);
IF IN_R.Q THEN
IF (Remaining > T#0MS) AND NOT Q THEN
timer.PT := Remaining;
END_IF
END_IF
IF RST THEN
Reset();
END_IF
IF IN_F.Q THEN
previousElapsed := timer.ET + previousElapsed;
END_IF
//** Keep before Timer Execution
ET := timer.ET + previousElapsed;
timer.IN := IN AND NOT RST;
timer();
IF timer.IN THEN
Remaining := Timer.PT - timer.ET;
END_IF
IF IN_F.Q THEN
//** Execute after assigning Remaining
timer.PT := T#0MS;
END_IF
// Timer Done Rising Edge
Q_R(CLK := timer.Q);
IF Q_R.Q THEN
ET := timer.PT + previousElapsed;
timer.PT := T#0MS;
Q := TRUE;
END_IF
TT := IN AND NOT Q;
[/INDENT]
ACTION Reset[INDENT]
IN := FALSE;
previousElapsed := T#0MS;
Remaining := PT;
ET := T#0MS;
Q := FALSE;
[/INDENT]
Code:IF RST THEN Reset(); END_IF ... timer.IN := IN AND NOT RST; ...
Code:ACTION Reset[INDENT] IN := FALSE; previousElapsed := T#0MS; Remaining := PT; ET := T#0MS; Q := FALSE; [/INDENT]
If [Remaining] is an output, how can it have a value in the FUNCTION_BLOCK before that function block assigns it a value? Where does the value come from?Code:FUNCTION_BLOCK RTO ... VAR_OUTPUT ... Remaining : TIME; // Time Remaining END_VAR ... [INDENT] IF IN_R.Q THEN IF (Remaining > T#0MS) AND NOT Q THEN timer.PT := Remaining; END_IF END_IF ...[/INDENT]
This could be replaced withCode:...[INDENT] // Timer Done Rising Edge Q_R(CLK := timer.Q); IF Q_R.Q THEN ET := timer.PT + previousElapsed; timer.PT := T#0MS; Q := TRUE; END_IF[/INDENT]
// Timer Done Rising Edge
IF timer.Q and NOT Q THEN
ET := timer.PT + previousElapsed;
timer.PT := T#0MS;
END_IF
Q := timer.Q;
If IN_F.Q is 1, then previousElapsed will be incremented by timer.ET, and then it will be incremented by timer.ET again to write the value of ET. Is that double-dipping?Code:[INDENT] IF IN_F.Q THEN previousElapsed := timer.ET + previousElapsed; END_IF //** Keep before Timer Execution ET := timer.ET + previousElapsed;[/INDENT]