Join us today!

Notifications
Clear all

How to reach PLC Task cycle time counter

5 Posts
4 Users
1 Reactions
654 Views
Posts: 5
Topic starter
(@baranorkunz)
Active Member
Joined: 2 years ago

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. 

Reply
4 Replies
3 Replies
twinControls
Admin
(@twincontrols)
Joined: 2 years ago

Member
Posts: 114

@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;

 

counter

 

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. 

basetime
task

 

I hope this is what you needed. 

 

 

Reply
(@baranorkunz)
Joined: 2 years ago

Active Member
Posts: 5

@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 🙂

Reply
Moderator
(@treyem)
Joined: 2 years ago

Member
Posts: 16

@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

 

Reply
Posts: 7
(@theshamot)
Active Member
Joined: 1 year ago

Hey, did you solve the problem somehow? Thank you

Reply
Share: