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 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
202
Hello to all, I'm just starting with using CodeSys. Immediately, I have noticed that Codesys doesn't use data blocks like for example S7 does...
Replies
11
Views
217
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
7
Views
438
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
130
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
218
Back
Top Bottom