Codesys Wait function block

r.zarei2010

Member
Join Date
Mar 2016
Location
Tabriz
Posts
2
Hi. I'm writing an CODESYS program with ST.
In diffrent parts of my main program i need my program to pause for a while and continue running after a time elapsed. So i defined Wait function block as below and reused it where it's need (multiple times):

delectation part:

FUNCTION_BLOCK Wait
VAR_INPUT
time_in:TIME;
END_VAR

VAR
ton1:TON;
END_VAR

----------------------------------
body part:

ton1(in:=TRUE,PT:=time_in);
WHILE ton1.Q=FALSE DO
ton1(PT:=time_in);
END_WHILE
ton1(in:=FALSE);

The function block works as expected, but is consume cpu very much, and watchdog stops my program.

what is the alternative way of doing this?

all i want is some thing like this:

Line 1
Line 2
Wait 5 seconds
Line 4
Wait 10 seconds
Line 6
...

Thanks.
 
I would use the done bit (Q) of a timer to let the next step/line continue. For example, start a timer when line 2 is complete. When that timer is complete, allow the next line to process. I would also probably use a sequence step to help keep things clean. I also find it useful to make sure that my timer are being called outside of IF statements to make sure that they are processed each PLC scan.

Code:
sequence : DINT;
t_line2Complete : TON;
line2Complete : BOOL;
firstScan : BOOL := TRUE;

IF (firstScan) THEN
    sequence := 1;  /* line 1 */
    line2Complete := FALSE;
    firstScan := FALSE;
END_IF

IF (sequence == 1) THEN
    [do line 1 things]
    sequence := 2;
END_IF

IF (sequence == 2) THEN
    [do line 2 things]
    line2Complete := TRUE;
    sequence := 3;
END_IF

t_line2Complete(PT := t#5s, IN := line2Complete);

IF ((sequence := 3) AND (t_line2Complete.Q)) THEN
    [do line 3 things]
    line2Complete := FALSE;
    sequence := 4;
END_IF
...

Hopefully that gives you an idea of something that you could do.
 
I would use the done bit (Q) of a timer to let the next step/line continue. For example, start a timer when line 2 is complete. When that timer is complete, allow the next line to process. I would also probably use a sequence step to help keep things clean. I also find it useful to make sure that my timer are being called outside of IF statements to make sure that they are processed each PLC scan.

Code:
sequence : DINT;
t_line2Complete : TON;
line2Complete : BOOL;
firstScan : BOOL := TRUE;

IF (firstScan) THEN
    sequence := 1;  /* line 1 */
    line2Complete := FALSE;
    firstScan := FALSE;
END_IF

IF (sequence == 1) THEN
    [do line 1 things]
    sequence := 2;
END_IF

IF (sequence == 2) THEN
    [do line 2 things]
    line2Complete := TRUE;
    sequence := 3;
END_IF

t_line2Complete(PT := t#5s, IN := line2Complete);

IF ((sequence := 3) AND (t_line2Complete.Q)) THEN
    [do line 3 things]
    line2Complete := FALSE;
    sequence := 4;
END_IF
...

Hopefully that gives you an idea of something that you could do.

Thanks for your reply. I've find better way to that by sleeping running task.
 
you best use SFC for this, but also possible in ST

if line 1 and line 2 done and NOT timer1.IN then Timer1.IN=TRUE....
if Timer1.Q start line4
etc.
The program must be scanning all the time.
or use state programming.
 

Similar Topics

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
294
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
90
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
156
Hi everyone, as this is my first experience with Rockwell Software i would like to know what's the best way to make Enumerations?
Replies
10
Views
509
I am trying to get Codesys to work with a couple of Moxa ioLogik E1200 series DIO devices (E1210 and E1211). I am able to write to the E1211 DOs...
Replies
2
Views
173
Back
Top Bottom