Sign in to follow this  
Followers 0
bearsgone

How to accumulate gallons from a flow meter

20 posts in this topic

Hello I have a flow meter Signet 2551. Trying to figure how to convert 4-20ma output to gallons and add gallons to a total count. Using Micrologix 1400. Thank you for your help

Share this post


Link to post
Share on other sites
Having never used the Micro logix 1400 - just to clarify, is the input max really 5000 ? in the past with SLC it was I believe 16384 for 20mA ... just curious... OR were you miss using the SCL function because your eng unit is 20..... (so were you really trying to scale the analogue from 4-20mA = 0 - 5000 gallons ? Then once you have your scaling worked out correctly, for example 4-20mA (signal) = (xxxx - xxxxx PLC values unscaled) = 0 - 10 gal / sec scaled, think of how you could totalise something. Ie if you had a jar and were adding candy one at a time... jar_total = jar_total + 1. the same can be said for flow every one second, ie do the following calc on a positive edge of a 1 sec pulse flow_period_total = flow_period_total + X gal/sec. You can work out the logic.

Share this post


Link to post
Share on other sites
FYI, If the OP is using the ML1400's base analog inputs then their raw data is 12 bit 0-4095. They are voltage inputs. See picture below. If the OP is using an analog expansion module then they have there own resolution. As you pointed out the OP needs to tell the forum what the 4-20ma represents ( engineering units) and what its connect to. Edited by Mickey

Share this post


Link to post
Share on other sites
Or are we using an analog expansion module. 4-20mA on those is 6240 to 31200.

Share this post


Link to post
Share on other sites
Depends on the input and settings. From AB Technote 19719: In raw/proportional mode, 0 mA = 0, 4 mA = 6241, 20 mA = 31206, 21 mA = 32767 In "scaled for PID" mode, 0 mA = -819, 4 mA = 0, 20 mA = 16383, 21 mA = 17407 It's a 15 bit bipolar (aka 16 bits with sign) ADC (does not say but most likely delta-sigma or successive approximation). There is no resolution "loss" in either mode. Since zero is zero with the "scaled for PID" mode, I'd go for that mode and use a simple multiply instead of dealing with the vagaries of the SCP instruction if you are out of range (over/under). Suppose the scale with the Signet is 0-1000 GPM = 4-20mA, then 16383 counts = 1000 GPM, so multiply by 1000/16383 = 0.061038882. If the output is under/overrange, you'll get something <0 or >1000 GPM which is easily verified. You can also use the over/under-range bits on the analog input card if you want to. You must also make sure the dip switches in the top of the module are set correctly (down/"on" in the current mode). The Signet module you are referring to is loop powered. So you must supply an external power supply to make it work. The "common" is not electrically connected to the chassis, but the 4 inputs are single ended and they do not supply loop power. So connect your 24 VDC power supply V+ to the transmitter V+, transmitter V- to IN+, and connect "common", IN-, and the power supply V- together (for 2-wire). Connect shield to common/ground as well at the IO module ONLY (or alternatively at the IO module ONLY, never both) if you are using shielded wiring. As a followup, I've had zero luck with insertion mags and Signet in particular. It's not a "real magmeter". Accuracy is about as good as a flume, orifice plates/vortex/targets, or transit time ultrasonics. For the money/effort, I'd go with one of the others, leaning towards transit time flow meters since they don't require cutting holes in pipes (orifice plates, vortex, targets), don't clog up (targets/vortex meters), and don't have special mounting requirements (flumes). Real magmeters are expensive but have the highest accuracy for the money in the 6-24" size range. Low end coriolis beats them out on the small diameter end, and they are cost prohibitive on the upper end. The biggest downside of them is fluid compatibility, and wear (in slurries).

Share this post


Link to post
Share on other sites
Paul is heading in right direction. Before embarking on programming up the application, one should develop or review the specifications for the application. You may spend a lot of time programming a solution to find that the accuracy is too wide for the results one garners. The analog value from the flowmeter will have an accuracy range; sampling the analog value (i.e., 1 sec snapshots), totalizing and averaging to get an average flow rate (i.e., over 1 minute) with be accruate to +/- (potential variation of the process). What is the purpose for the flowmeter gallons figure? If this is a regulation monitoring application, such as recording effluent discharge gallons, the permit requirements may dictate a different method with a lower range of variation (i.e., higher accuracy). I personally was given a similar project some years ago that would have saved a lot of programming hours had I analyzed the specification of the application and the instrument prior to jumping in with both feet. The physics of the application (discharge pipe not full at all times, large variation in flow rates) and the instrument yielded an end result with variation far greater than the requirements of the discharge monitoring permit. End result was a replacement of the instrument with a model of higher accuracy.

Share this post


Link to post
Share on other sites
Hello Thank you everybody for your feedback. I am using Micrologix 1400 with 1762-IF4 AI card. Input is coming into IF4 card. At 0 gpm I get 6265 Raw and at 180gpm I get 31283 Raw. 4-20ma. Was wondering if somebody can post an example of how to accumulate gallons based on gpm. It is always easier to understand by looking at an example. Thank you in advance

Share this post


Link to post
Share on other sites
Your code for the scl function is still wrong. You have the parameters in your statement above. To totalise the flow ie total gallons, simlpy sample the scaled value every second, divided that figure by 60 (ie min -> seconds) and write logic that will represent total = x + total. At least have a go at trying to work this out. A lot of people have led you in the right direction, show a bit more effort on your behalf.

Share this post


Link to post
Share on other sites
I apologize for asking so many questions. I am new to this. Not sure how to find out what would be the scale in gpm? Ex. 0-1000gpm. Is it calculated based on pipe size? Once I have scale where do I do suggested conversion(0.061038882): "Suppose the scale with the Signet is 0-1000 GPM = 4-20mA, then 16383 counts = 1000 GPM, so multiply by 1000/16383 = 0.061038882" I am getting a reading(nothing is flowing) every second but it does not add two floats together? I am using 1762-IF4 with 4-20ma and Scaled PID Once again, I thank everybody for their time.

Share this post


Link to post
Share on other sites
Two different issues. First off, the conversion is simply 1000 / 16383 = 0.061038882. Instead of SCL or SCP, you'd use a simply MUL (multiply) instruction. Simply plug in your range (was it 0-120 GPM) in for the "1000" to get the exact scaling factor you'll need. Now as for your totalizing. There are two parts to this. First, the ADD instruction does this. Start by using floats instead of integers because you get more bits (bigger maximum totals before things overflow). So say you have your GPM reading in F8:0 and you want the total in F8:1. Then simply using an ADD instruction where you add F8:0 and F8:1 and store the result in F8:1 (yes, adding F8:1 to itself) does the trick. Whenever you need to clear the totalizer, simply zero F8:1 in this example. The second trick is that you need to consider TIME in the calculation. Unless you have a flow that changes REALLY slowly, you'd never use GPM directly as I described above. Normally you'd use GPS (gallons/second). So dividing by 60 gives you the right number to be adding to your total. Second, you need to execute the instruction exactly once per second. So either use an STI (look it up in the instruction set reference manual) or else use a timer. If you use a timer, watch out for using self-resetting timers. You need to either trigger off the RTC or else use an "infinite timer" (search for it on the forum).

Share this post


Link to post
Share on other sites
Actually another issue. While the precision after conversion and division by 60 looks impressive that precision will soon be lost after multiple additions. I would add one more thing to the one second STI. Each time the float accumulated total is equal to or greater than 1.0... then add 1 to a DINT total and subtract 1.0 from the float. The DINT will go up in whole gallons allowing a truly large number while continuing adding to the float will over time begin to lose the least significant results of your scaling and division. After a while you would see no accumulation at all because all the lower significant digits are being lost. To see what I mean create a continuously running rung with an addition block adding .0000001 to a float. You'll see it operate for a while but then no additional increase will take place.

Share this post


Link to post
Share on other sites
Thank you for your tips I have total flow and flow GPM calculated: Total Flow in GPM samples every second: F8:19 * (Scaled Max/Input Max/60 seconds)* 2 (because RTC:0:SEC only does update every two seconds in MicroL1400) + F8:22 Existing Flow in GPM: F8:19 * (Scaled Max/Input Max/ 2(because of RTC scan)) Are those formulas correct or am I missing something? I also have panelview compact which has a scale connected to F8:23 to show present flow and even though F8:23 has 0 reading, PanelView shows solid -.19 instead of 0? Thank you for your help Edited by bearsgone

Share this post


Link to post
Share on other sites
There is no reason to divide by 2 if your intent is to get GPM. If you are doing all the scaling in the CPT blocks, then the SCP instruction is no longer needed at all. The purpose of the SCP instruction is to do a linear scale from one range to another. ie, m=(ymax-ymin)/(xmax-xmin), b=ymax-xmax*m, y=m*x+b. This is the full linear scaling formula assuming you know the endpoints. If ymin=xmin=0, then it simplifies considerably to simply y=m*x where m=ymax/xmax and the SCP instruction is much less useful than a simple MUL or CPT. Be aware also that CPT is slower than the basic math instructions (CLR, ADD, SUB, MUL, DIV, MOV). Whenever practical, convert to the basic instructions.
1 person likes this

Share this post


Link to post
Share on other sites
I use flow totalizers in a lot of the programs i write. Assuming you are getting flow in GPM, what i usually do is divide the input by 60 and move it into a new register, say F112:0. That new register represents Gallons per second. Then create a one second timer, we'll call it T4:0. When T4:0/DN is true (once a second) you add F112:0 to a register like F112:1, and put the result IN F112:1. that way it compiles your total flow every second. Then to get more depth, on the next rung, say if F112:1 > 1000 you add .001 to a new register like f112:2 and move IT into f112:2 to compile, and then you move a zero into F112:1, reseting it. this new F112:2 is your flow total in Millions of gallons. So essentially you add your gallons per second to a register every second, and every time it hits a thousand you add a .001 to a new register giving you your total in millions. Let me know if i need to explain it better

Share this post


Link to post
Share on other sites
Thank you for the feedback The other question I had was: I also have panelview compact which has a scale connected to F8:23 to show present flow and even though F8:23 has 0 reading, PanelView shows solid -.19 instead of 0? How can I set it so that Panelview would ignore +- values or is there another way of dealing with this? Thank you

Share this post


Link to post
Share on other sites
No don't move a zero into F112:1, subtract 1000.0 from F112:1

Share this post


Link to post
Share on other sites
Subtracting actually does seem like a more accurate measure now that i think about it, that way you dont lose whatever few gallons passed through before the rung was executed

Share this post


Link to post
Share on other sites
There are two problems with your code. Before going any further, please consider this HUGE hint. Accumulators, totalizers, sums, whatever you call them, are highly sensitive to accumulated errors. So any time that you drop or ignore any sort of fraction by any means other than rounding/truncating (so that the accumulated error is nonbiased), it will eventually bite you. I have been bitten by these kinds of things over and over and over until eventually I started to recognize them. First, the fractional gallon problem. You are suggesting to ZERO a floating point register even though you are using it to totalize fractional (floating point) amounts. You are periodically throwing away the fraction which can lead to accumulated errors. This was already pointed out earlier. Second. you are recommending using a free running timer. It is NOT, I repeat, NOT a "1 second timer" as you suggested. And if you run experiments over any reasonable length of time, you will notice it. Try simply counting the number of seconds over a 1 day time period and you will quickly see what I mean. The classic free running timer code goes like this: XIO T4:0/DN TON 4:0 0.01 100 0 In English: If T4:0/DN bit is a 0, then run the timer. Timer resolution is 0.01 seconds. When the timer accumulator equals or exceeds the value of 100, put a 1 in the T4:0/DN bit. Now this seems to work just fine if all you are doing is blinking lights or doing something noncritical which is immune to accumulated errors. But for totalizers, it is flat out a bad idea. See, when the timer expires, then it resets itself, and starts again. BUT, the reset function takes one program scan. So on a Micrologix for instance, this amounts to say 10 ms for an average program. So the timer isn't 1.0 seconds, it's 1.01 seconds, on average. Over the course of a day (86,400 seconds), it ends up undercounting by 864 seconds or 14.4 minutes. It's a 1% error but it's still a huge error that adds up over time especially with a totalizer. Worse yet, depending on what your program is doing (and as edits are made over time), the amount of error will fluctuate as the program scan fluctuates. Now, PLC clocks are not known for high accuracy and can be off by a few seconds per day, but not hundreds of seconds per day! Now, if you are a true accuracy nut then you'd probably figure out a way to plug a GPS or an atomic clock of some kind into your PLC. If not, then you can probably live with a few seconds a day, which is an error closer to 0.1% or even 0.01%. Except for coriolis meters, most flow meters aren't even that accurate. So if you can live with something a little worse than an atomic clock but much better than a free running timer, here are your choices: 1. Use an STI (PLC/5, SLC, Micrologix technique) or a periodic task (ControlLogix, CompactLogix). This is a ladder that fires on an exact timer interval (within the limits of the PLC's internal clock). So you write your totalizer code but there's no timer at all. Just the ADD statements. I usually have one of these anyways because it clears up a similar time problem with PID instructions. 2. Use the real time clock in the PLC. Just monitor the seconds reading and use that to trigger your code once per second (or even once every other second). 3. Use an "infinite timer". This is very much like the free running timer idea, but never lets the timer reach "done". First, create a timer with say a 2 second time interval. There is no need for conditions on this timer. You can use either the RTO (retentive) or TON (nonretentive) timers but for this use, it doesn't matter which one. We'll stick with the SLC/PLC-5/Micrologix world and assume that the best you can get is a 0.01 second resolution. Use the highest resolution timer available (this is a general rule, not just for this case). Now, manually check the accumulator like this: GEQ T4:0.ACC 100. So whenever the count in T4:0 exceeds 100, we've got our 1 second. Now SUBTRACT 100 from T4:0.ACC to "reset" it and trigger any other code that you want off this "one second timer". Internally, the PLC uses a higher resolution timer to keep track of fractions so as long as we just subtract out "1 second" as needed, the fractions will be correct. And that gives you an accurate "1 second timer", as good as any of the other two methods. Advantages of method 1: Method 1 works on an interrupt. Whenever the periodic timer bell goes off, the PLC does it's best to stop whatever it is currently doing, even in the middle of a program scan, and go off and run the periodic task (or STI) code. Once the code finishes, it returns to whatever it was working on. This means that the code execution is very even and methodical (very little jitter). Disadvantages: Method 1 is a little more confusing to technicians in the PLC-5/SLC/Micrologix world because there's no "main ladder". I usually have several ladders and I put them all in one "main routine". But one of them will look like this: AFI JSR xxx And it has a comment attached explaining that this is an STI and NOT to remove the AFI. That way technicians can see that the STI is there without looking at the PLC settings. Method 1 can also be tricky when it comes to "regular scan" code vs. the STI/periodic task code. If you read the "total gallons" some place in your program and trigger something else to happen, be sure that you only read the "total gallons" ONCE and set a bit. If you don't, then "X > 1000 gallons" might be FALSE in one place in your code, and TRUE in another, during the same scan! This happens whenever the interrupt happens right in the middle of your "regular program" between the two checks. Advantages of method 2: Pretty much fixes all the the disadvantages of method 1 because it runs in the "regular scan" of the program. Disadvantages: Timing is limited usually to 1 second or 1 minute intervals. If someone synchronizes the "clock" to a PC, this can interfere with the totalizer. I usually run with the HMI PC synchronized to an atomic clock somewhere and then the PC in turn synchronizes the PLC. If you use the PLC's clock on the screen, this avoids issues with daylight savings time. Plus PC clocks these days tend to be good for a few seconds per month at most, while PLC's are good for a few seconds per day. Synchronizing to an atomic clock network eliminates even this small error. Timing jitter is going to be scan-dependent and much more of an issue than method 1. So one "second" might be 1.01 seconds while the next might be 0.99 seconds, but the long term AVERAGE is still pretty darned close to 1.000 seconds, even if it is a little early or late from one clock tick to the next. Advantages of method 3: Fixes all the disadvantages of methods 1 & 2, except the jitter issue. Disadvantages of method 3: Jitter. But the jitter isn't any worse than method 2.
1 person likes this

Share this post


Link to post
Share on other sites
as for zeroing out a floating point youre right, as stated above, a better idea is to subtract 1000 so you dont knock off the decimal. As for the timer issue, my applications have never been critical enough to where its become a problem, but you are 100% right. I think the infinite timer is the most straightforward approach

Share this post


Link to post
Share on other sites
All of the errors that have been discussed are why I normally don't use the 4-20 ma option on their flow meters. Next time consider putting a 1 instead of a 2 at the end of your part number. You can connect this directly inputs 0-7 on the Micrologix 1400 and configure an EII to do simple ADD instruction. This way one pulse equals X amount of water. Actually if you are using their 515 or 2536 series paddlewheels ever, don't even bother purchasing a transmitter such as a 8550. You can connect the pulse off of the paddle wheel directly to the Micrologix input. Just put a 5K resistor between your 24VDC and the input.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0