Logix5000 CPT instruction

Join Date
Mar 2006
Location
Gothenburg
Posts
10
Is there any way I can use a string in a compute (CPT) instruction's expression field?

I want to store vessel profiles in an array, and then compute the volume from the level. The vessel profile (Level to Volume equation) will be stored in a string, and then copied into the compute function expression. This will be run through a loop so I dont have to do every vessel individually.

Is this possible?
 
It is possible, but not with the CPT instruction. If you want to do it using a string then I suggest you write a ST routine to parse the string and perform the calculation.

However, why not create a UDT that contains the vessel profile information? Then you can pass the UDT tag(s) to a SBR that calculates the volume. You can pass the UDT tags to the routine so that you do not have to code each vessel individually. UDTs were made for this stuff.
 
I have made the UDTs, as there are also other factors involved such as what substance is in the tank.

I have an equation (different for each vessel) that correlates level to volume, and ST isn't an option due to SIL2 solutions and client specs.

One of the DT in my UDT is the equation in string form, and I was hoping to just paste this into a CPT function and run it in a loop to batch process the calcs.

I guess if I pass the array reference into a SBR that has a CPT for each tank than this would work. I was hoping for a way to process the equation from sting form.
 
Here is something I threw together really quick. The UDT will accomodate rectangular tanks, vertical cylindrical tanks, and horizontal cylindrical tanks and can be expanded for conical and domed tanks. The compute routine uses ST, but it should be fairly simple to convert it to Ladder. It could be called individually or in a loop - each time passing the tank TankFarm[index] into the subroutine where it will be copied into _tank and processed and then passed back out with the result copied back into TankFarm[index]. Its not anything close to a complete soultion, but I hope it gives you some ideas.

It's in version 15. If you can't open it then get back.
 
One quick modification to the subroutine above. The case 2 equation should be:

2: _tank.Volume := _tank.Length * ((_tank.Diameter * _tank.Diameter * .3926991) - ((_tank.Diameter * _tank.Diameter)/4 * ASIN(1 - _tank.Level/_tank.Diameter/2)) - ((_tank.Diameter/2 - _tank.level) * SQRT (_tank.level* (_tank.Diameter-_tank.Level))));
 
Showshocka:

It appears the Alaric's Tank Calculations is in a Block Program, that you may not be able to open.

Stu....
 
The original post dates back to version 15, before AOIs. I agree that this would be a good candidate for an AOI now.

For those who don't have the ST language extension, here is the ST code:
Code:
//subroutine accepts an object of type Tank passed to it and calculates the volume of fluid in the tank in engineering units.
//Tank can be one of three types.
//   0 - rectangular tank\
//   1 - vertical cylindrical tank
//   2 - horizontal cylindrical tank

sbr (_tank);  //declare a tank passed to the subrioutine as _tank.


case _tank.Type of
  0: _tank.Volume := _tank.Width * _tank.Length * _tank.Level;

  1: _tank.Volume := _tank.Diameter * _tank.Diameter * 0.785398;     //vertical round tank. Diameter^2 * PI/4

  2: _tank.Volume := _tank.Length * ((_tank.Diameter * _tank.Diameter * .3926991) - ((_tank.Diameter *  _tank.Diameter)/4 * ASIN(1 - _tank.Level/_tank.Diameter/2)) -  ((_tank.Diameter/2 - _tank.level) * SQRT (_tank.level*  (_tank.Diameter-_tank.Level)))); 		
       //  A = pi*r^2/2 - r^2*arcsin(1-h/r) - (r-h)*sqrt(h(2r-h))
end_case;

_tank.EUVolume := _tank.Volume * _tank.Scalar;

_tank.LLLA := _tank.EUVolume < _tank.LowLowLevel;
_tank.LLA := _tank.EUVolume < _tank.LowLevel;
_tank.LHA := _tank.EUVolume > _tank.HighLevel;
_tank.LHHA := _tank.EUVolume > _tank.HighHighLevel;

Ret (_tank);
 
Last edited:
What do you want to do with it? So far all we have from you in the way of information is "This is all I got." which is just not very informative.

The program allows you to handle multiple tanks of different types, so it uses a subroutine with passed parameters. The L5K program contains a udt declaration for a tank. You can open that and see how it is set up. The tank tags are passed into and out of the subroutine. You create a locally scoped tag of the tank UDT that is named _tank. the _tank tag is used only in the subroutine for passing tank tags. Define as many tags as necessary of whatever scope you choose for the tanks. You can name these whatever you want. You predefine the various values in those UDT tags to describe your tank, then pass each one to the subroutine for processing.

If you have only one tank then this isn't a very efficient way to handle it - just pick the part of the code that applies to your tank and use it.

Without some specifics I can't answer a question like "Now what?"
 
Last edited:
Ok, Now I'm totally lost.

The "TankLevelCompute" ST routine needs to be "called" for each tank you want to compute the contents of.

You do this with a JSR instruction in your code, passing parameters as required, and as described by Alaric, specifically you will need to pass your tank tag both as an Input Parameter, and a Return Parameter.

Does that help ?
 

Similar Topics

I am used to the SCP function in the Rslogix500 but I'm not quite sure how to scale inputs using the CPT instruction and I need to use it because...
Replies
5
Views
4,121
Hi! So my problem is a little funky, I had Studio 5000 v 24 and 30 installed, but forgot to install RSLogix (which I cannot go without). Is there...
Replies
2
Views
119
So I had an odd request from a customer for the above. I have written the logic and tested it all in one PLC with only using 7 outputs and 7...
Replies
15
Views
428
I'm a Siemens person, and this is one of my first AB programs. The customer wants everything programmed in Ladder. I have a lot of data (3...
Replies
14
Views
220
Good day everyone. if you have a logic for 3 pumps (lead/lag/off), would you please email it to me? I really appreciate it!
Replies
7
Views
218
Back
Top Bottom