Join us today!
How to reach PLC Task cycle time counter
Hello, recently I was working on some framework and I needed to access the PLC task cycle counter. I need to access it because I want to have some flag that does and action and wait for 1 task cycle to execute the other action. Since its an OOP library and the method is not being called cyclicly in my program, I tried to make a binding between PLC task counter and my Library. The problem is; when I use Beckhoff infosys _TaskInfo function it counts system cycle, not the PLC task that I call my main program. For example, the cyclecounter value from _TaskInfo function is increased like 50 for each call of my main program.
I hope the problem is understandable. If anyone can help I would be glad.
@baranorkunz Hi, you can create a variable in global variable list and increase it by 1 in a program which is being called in the task you'd like.
VAR_GLOBAL nPLCTaskCycleCounter : ULINT; END_VAR
And increase it in the MAIN program:
GVL.nPLCTaskCycleCounter := GVL.nPLCTaskCycleCounter + 1;
I set the cycle ticks to 1000 and my real time base is 1 ms, so the PLC task is running every 1s for this example.
I hope this is what you needed.
In case you want to say thank you !)
We'd be very grateful if you could share this community with your colleagues and friends. You can also buy us a coffee to keep us fueled 😊 This is the best way to say thank you to this project and support your community.
twinControls - https://twincontrols.com/
@twincontrols Hey, thank you for your answer. However, the problem is that the project is a library project and it has no dependency to any concrete POU. The user of the library just needs to instantiate it and use it without concerning about any implementation etc. The only idea that came to my mind was to bind it to some system variable so that it can get it anytime its called. But I cant just put a property that is depended to some concrete POU and expect the user to call this every cycle, if forgot, the function will not work anymore 🙂
@twincontrols @baranorkunz If you need to set task 2 once task 1 is complete and a full scan cycle has finished, put task 2 above task 1 in the sequence. Once task 1's conditions are met, set a flag that will allow task 2 to run on the next scan cycle. In Task 2, clear the flag set by task 1.
PROGRAM MAIN VAR bStartTask1 : BOOL; bStartTask2 : BOOL; END_VAR
IF bStartTask2 THEN // Task 2 code bStartTask2 := FALSE; END_IF IF bStartTask1 THEN //Task 1 code bStartTask1 := FALSE; bStartTask2 := TRUE; END_IF
Hey, did you solve the problem somehow? Thank you
- 17 Forums
- 267 Topics
- 924 Posts
- 0 Online
- 737 Members