Is there a Way to Create an Array of Timers ?
Hello:
I need to be able to create, Monitor and Control upto 400 Timers (TON).
The easiest way would be to create an ARRAY of TON (Data Types), but this is not available.
Do you know of another way to accomplish this ?
Thank you !
Peter.
Comments
Hey Peter,
I have run into this in the past. From what I found it is not possible to create a datatype that is tied to the TON FB.
Alternatively, you can create your own user-defined datatype that is made up of a structure and an array. The structure can contain the elements of the timer (i.e. IN, PT, ET, Q). Then an array of that structure can be created which will give you an array of TON elements.
Please see attachments for the user-defined datatype and how to use it in a program.
Josh:
Since the TON Block is the Same Instance and just uses Arrays to acces it, this does not work as I need it to.
Each Array needs to have different PT Values, Start Times, etc....
The Array Data as you described for each is not independant, since they are based upon a Single TON Instance..
The TON will only have the Values from the Last Array sent to it.
Thanks !
Hey Peter,
The array in the example would have the ability to store info about/for multiple timers.
The array can also be referenced implicitly instead explicitly like the example shown
For example, change arrTimers[1] to arrTimer[iIndex] and now you can change that index however it needs to fit that instance of the TON.
Hi guys, sorry to butt in to this conversation ... I like Josh's solution but I think I can see what Peter is saying.
If I understand Josh's solution correctly, the array can hold information for the 400 timers that Peter needs, and this makes it easy to process this information using for-next loops (for example).
However, I believe that for this to work, there must be 400 instances of the TON function block created, with each FB instance "tied" to one single set of array elements. This is because there are internal variables in the FB instance that keep track of (for example) the elapsed time. And I understand that Peter does not want to create those 400 FB instances, but is looking for a way to create an array of FB instances.
I have passed this question on to the PLCnext Engineer support team, and I hope that they have a solution that will suit Peter's requirements (if I understand them correctly).
~ Martin.
Matin:
Yes, I need 400 instances.
Thank you for looking into this for me and I look forward to a response.
Regards,
Peter
Hi Peter,
Unfortunately what you want to do is not possible with the current version of PLCnext Engineer.
So at this point - if you want to use PLCnext Engineer - you will need to create 400 function block instances and connect each instance to its own inputs and outputs.
~ Martin.
Hi guys! Two years have past sine your original disscussion and I stubled onto the same problem. Has anything changed since 2020? Is now possible creating an array of TONs?
Unfortunately the answers to these questions are "no" and "no" (sorry).
The requirement is still in the PLCnext Engineer development backlog, but unfortunately there is still no schedule for the implementation of this feature.
The following is pseudocode in structured text. It requires the PLCNext Base libraries.
I'd probably just do an array of TON_typ with the IN, INh, ET, PT, ST, and Q variables in the type. ST is Start Time. INh is in history (we need a stateless R_Trig). I'm using an external tick value to reduce system calls. This also frees up the values so they can be available like any other variable to other programs or the HMI.
If these are all being processed at once, I'd probably do something like this then:
PBCL_DateTimeGet(dtDateTime => tick_DateTimeVar)
for n := 0 to 399 do
TON_Arr(in tick_DateTimeVar, inout TON_Typ[n])
end_for;
function TON_Arr(in tick_DateTimeVar, inout TON_Typ)
if IN and not INh then
ST := tick_DateTimeVar;
INh := TRUE;
end_if
if IN then
timediff := SUB_LDT_LDT(ST, tick_DateTimeVar);//This will be in nanoseconds)
ET := timediff / 1000000);//move to milliseconds
Q := (ET is greater or equal to PT);
else
Q := false;
INh := false;
end_if
end function