Jump to content

Request for commentary- Calculating volume and 'timestamping'


Recommended Posts

Good morning all!  Happy Thursday!

I've got a rung I'm modifying and wanted to pass this by as many eyes as will look.  I think it will work, or is very close to working as intended, but I wanted to solicit as much feedback as I could about the approach, any stylistic feedback, etc. 

[I read a post this morning where Flex727 implored a forum member to put together programs with 1:1 networks to rungs.  My program was not done this way, and I realized I may be learning bad habits, which are probably easiest to break at this point in the learning curve.  Hence, this post.]


Here is the original rung.  It closes a valve filling a tank when the percentage is greater than a set point, and opens to refill when the percentage is less than a set point.



Here is my modifed rung.  It is large, but should be straight forward, I hope.  H1_JH_OUT is the measured level of the tank before converting to percent, UINT16.  I grab the RTC mins, secs and hours, multiply out, add all to the seconds time, and store that as either the time it topped, or time it bottomed.  When it bottoms, I subtract levels and times, with the idea being that I can send those via MQTT to my network and calculate GPM from that.  (Tanks are mostly constant cross section).

The set and reset is because the tank level being greater than or less than the set points is not momentary and I wanted to make it a one shot timestamping and measuring.




Any helpful critiques?  Thanks in advance!


Link to comment
Share on other sites

17 hours ago, Ness said:

It looks like you already know the volume (or it's simple to calculate) and you want to calculate the flow rate?

Wouldn't it be easier to calculate the flow rate in the PLC and send the result via MQTT?

Volume is simple to calculate.  I will likely include the flow rate on the HMI some place for the operator, but until I have it worked out just right I don't want to bother.


I made an attempt at calculating flow rate and had issues with sizes of tags (also used a different approach previously).  The flow rates I'm calculating are between 0 and 4 GPM...Much easier to write some javascript to do some arithmetic in Node-red, then send the data off to a database...

Link to comment
Share on other sites

Do you get a status for the drain valve? If not you could just start calculating flow when the tank volume changes by a certain amount.

If you get feedback from both valves I would just do something like record the time it takes for each 1% level change when a valve is open. You can then just do:

flowrate = (1% tank_volume)/(delta_time)

I guess it mostly depends on what you want to use the measurement for. It also sounds like it's either only filling or draining. If both the fill and drain valve can be open at the same time you could have a situation where you're filling at 4 GPM and draining at 4 GPM and calculate a flow rate of 0 GPM.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...