I have a task who call a program in my codesys. But i want other program run after the man setup program is finished?
I sett the main setup program at prior #1 and after that program has finished, other program can now loop.
How do i can figure that?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2016-06-12
Originally created by: scott_cunningham
I do this with only one task. My main program (PLC_PRG) calls both my setup program and main program. There are several ways to do this, but here is one way:
SetupCode();IfNOTSetupCode.DoneTHEN
  RETURN;END_IFMainCode();MoreCode();
Your SetupCode program must be smart enough to set a Done output and stay there.
There are other ways... Some people use a VAR_INPUT on every POU to Enable running the code instead of using a IF/THEN/RETURN like above... Some people use a state machine (CASE statement) with state 0 = setup, state 1 = run, etc
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2016-06-22
Originally created by: scott_cunningham
Your question hints at a problem I had when I started with IEC61131-3 programming. If the following is already clear to you, I apologize in advance!
IEC61131-3 is PLC style code. That means the program loops over and over. It is not like a PC program where the first line is the beginning and the last line is the end and it quits. PLC code has a hidden forever loop outside of the main PLC_PRG program. This means if you make a large FOR/NEXT or WHILE/WEND loop that takes too long, you will get a crash - basically a watch dog error. It also means you don't want 20 tasks running at once with different priorities, because all of the tasks will always be called.
I would suggest only starting with one task (PLC_PRG) and use the following in your PLC_PRG program:
CASEStepOF
  0: //setup
    Setup();
    IFSetup.DoneTHEN
      Step :=1;
    END-IF
  1: //main
    DoMainWork();
   Â
END_CASE
Then your Setup program can step through what it needs to do over however many PLC scans (1 or 1000 calls). When Done is set true, then the state machine moves to the main program and Setup is not called anymore.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
travlytle hat geschrieben:
I do something like the attached file:
Only one problem.
A PLC cannot wait/delay.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2016-06-27
Originally created by: scott_cunningham
You must handle a wait/delay in a PLC way:
Delay();
IF Delay.Q then
Setup := TRUE;
END_IF
Where Delay is a TON timer.
Think of slicing your program - it must run in small steps until it is finished. For example, a FOR/NEXT loop of 10000 will probably fail. Instead, one iteration for PLC scan until all 10000 are completed.
This is how a "machine" can keep running all of the time without "hanging" while some delay runs. This is what I mean about not programming in a PC way.
If you are still having issues, then specifically lay out what you are trying to do and someone will give you some code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello!
I have a task who call a program in my codesys. But i want other program run after the man setup program is finished?
I sett the main setup program at prior #1 and after that program has finished, other program can now loop.
How do i can figure that?
Originally created by: scott_cunningham
I do this with only one task. My main program (PLC_PRG) calls both my setup program and main program. There are several ways to do this, but here is one way:
Your SetupCode program must be smart enough to set a Done output and stay there.
There are other ways... Some people use a VAR_INPUT on every POU to Enable running the code instead of using a IF/THEN/RETURN like above... Some people use a state machine (CASE statement) with state 0 = setup, state 1 = run, etc
This will be like programming with arduino ?
Originally created by: scott_cunningham
Your question hints at a problem I had when I started with IEC61131-3 programming. If the following is already clear to you, I apologize in advance!
IEC61131-3 is PLC style code. That means the program loops over and over. It is not like a PC program where the first line is the beginning and the last line is the end and it quits. PLC code has a hidden forever loop outside of the main PLC_PRG program. This means if you make a large FOR/NEXT or WHILE/WEND loop that takes too long, you will get a crash - basically a watch dog error. It also means you don't want 20 tasks running at once with different priorities, because all of the tasks will always be called.
I would suggest only starting with one task (PLC_PRG) and use the following in your PLC_PRG program:
Then your Setup program can step through what it needs to do over however many PLC scans (1 or 1000 calls). When Done is set true, then the state machine moves to the main program and Setup is not called anymore.
I do something like the attached file:
Only one problem.
A PLC cannot wait/delay.
Originally created by: scott_cunningham
You must handle a wait/delay in a PLC way:
Delay();
IF Delay.Q then
Setup := TRUE;
END_IF
Where Delay is a TON timer.
Think of slicing your program - it must run in small steps until it is finished. For example, a FOR/NEXT loop of 10000 will probably fail. Instead, one iteration for PLC scan until all 10000 are completed.
This is how a "machine" can keep running all of the time without "hanging" while some delay runs. This is what I mean about not programming in a PC way.
If you are still having issues, then specifically lay out what you are trying to do and someone will give you some code.