I have made a function block using CODESYS to perform energy metering. The inputs of the function block is current and voltage and the output is energy. Now, we need to have 1000 instances of this function block to run the code for 1000 meter we have. Writing (and possibly copy and pasting) of these instances doesn't seem to be the most interesting work. Wondering if anybody has a smarter way of doing this numerous instantiation.
For example, here is how the code (in CODESYS) looks like for 2 instances:
meter_instance1(CURRENT:=I1, VOTAGE:=V2);
Energy1:= meter_instance1.ENERGY;
meter_instance2(CURRENT:=I2, VOTAGE:=V2);
Energy2:= meter_instance2.ENERGY;
And we like to have 1000 instances of it. Any idea is highly appreciated.
Just make an array of the function block:
Also make arrays of the voltage and the current:
Then you can use it like that:
As you use different arrays with the same size, I would prefer to define some global constant:
Then you can define the array like that: