Ability to ignore certain input values for totalizers



I am having an issue that I am not sure how to solve. I am fairly new to opto so it may just be a lack of experience. We have several flow meters that are analog inputs but either due to instrument drift or non steady current will sometimes read a negative value, especially when the meter is idle. We use these values for totalizers which then add these negative values which makes the total go down so we overshoot the target load.

For some cases I think this can be fixed by setting a variable equal to the total value at the end point so it won’t keep totaling the idle values or the other thought I had was essentially to disable communication to the analog point when not trying to load through the meter so the total doesn’t change.

The main problem I am not sure how to solve is certain totalizers work with PID loops and sometimes those loops need to stop and start flow in the middle of loading a batch. Is there a built in function to where the totalizer can just ignore values less than zero or would I need to figure out a way to program a self check and throw out negative values. Please let me know thanks.


Super quick question…

What is your analog input for the flow meter scaled to?

Here you can see what I mean, whats your actual and scaled settings for those analog inputs you are totalizing?


It depends on the meter. Typically it is a 4 to 20 mA with 4 being set to 0 and 20 being the upper range say 3000 lbs/min


So where is the big negative number coming from then?
Our modules will go a little under and a little over range, but not the extent that your first post suggests.

Can you see the big negative number in debug mode while looking at the analog input?


The analog input never gives a very large negative number. Typically i won’t see more than a -1 and usually it is no more than -.05 but the problem is with the totalize function. If I use the GetAnalogTotalizerValue function to get the flow through a meter it will be off because it also totals the negative values from the input and over time these can add up to a lot. So I was wondering is there a way to have it ignore the negative values.


Sorry I misunderstood, I thought you were seeing some big numbers that were throwing things off.

Its been a while, so I had to read the fantastic manual…
We only offer clamping on output modules, not input.
Rather than move the input channel to a variable and do the clamping and totalizing math on that variable, I am wondering if we cant slightly offset the input scaling to remove that negative error… Thinking out loud (never a good idea), I wonder if, since it is only a small under-range from your transducer, is it possible to change the lower scaled value to remove that small error?
For example, set the 4 to 20 to be 0.05 to 3000.


That is tricky because it is generally not constant. I have seen the same input be -.05 one minute and -.1 the next and then .05 the next.


Hi Guys,

While you’re totalizing, check out this post, especially the warning in the middle re: QNANs because those will mess up your total, too!

There’s also this discussion, which includes some sample code that might be helpful:

Happy coding!


How to Create a Custom Totalizer

If the flow is stopped (are you controlling this?) then perhaps it would be possible to store the totalized value in a variable and restart the totalizer when flow is commanded again.

I haven’t used analog totalizing, but after RTFMing on this, I find some confusing statements in the documentation.

On Set Analog Totalizer Rate:
Totalizing will be bi-directional if the input range is bi-directional, such as -10 to +10.
He is using a 4-20, but it seems he is still getting bi-directional behavior.

On Set Analog Totalizer Rate:
Setting the sampling rate to 0.0 seconds will discontinue totalizing, but not clear or change the total.
Setting the sampling rate to a non-zero value will clear any existing total.
From Get Analog Totalizer Value:
Use Get & Clear Analog Totalizer Value to clear the total before actual readings begin

Looks like setting the sampling rate will clear the readings as well, if true, maybe the docs should show that as well on Get Analog Totalizer Value

Totalizing will stop when the total reaches either limit. Totalizing will resume after using Get & Clear Analog Totalizer Value.

What limits, what does this mean?

Totalizing will stop if the input goes under range

What is under range here? Would 3.99 mA be under range? If this happens does the totalizer continue to totalize when the input goes back in range - the documentation seems to suggest that you have to restart the totalizer after it goes out of range. The strategy would have to carefully watch for out of range values if that is the case.


For some cases I can have it pull a value and save. The case I have trouble with is when we are controlling the flow. Essentially a set point is entered on the total amount to charge but often the flow rate is controlled by a PID loop that tries to maintain pressure or temperature by adjusting the flow rate. In these cases if the pressure gets too high then the flow might stop for a while and while nothing is moving the flow meter reads negative values that get totaled but the loop is still active trying to control flow. When the flow resumes once the pressure has dropped low enough the total will have gone down from the last time it stopped. So to reach the total setpoint more material has to be loaded than the desired amount. I need away to ignore those values when the flow reads negative.


Here is some sample code that could work. Question - how do you deal with accumulated error (kind of like dead reckoning error)? Any way to measure volume in the vessel?

if(aiFlowRate < fMinimumRate) then //Could also use your control valve output - may want some hysteresis here too
  //Stop the totalizer
  SetAnalogTotalizerRate(0, aiFlowRate);
  fFlowAccumulator = fFlowAccumulator + GetClearAnalogTotalizerValue(aiFlowRate); //Should probably check for QNAN here first
  if(nTotalizerStopped) then
    //Restart the totalizer
    SetAnalogTotalizerRate(fTotalizerRate, aiFlowRate);
    GetClearAnalogTotalizerValue(aiFlowRate); //Not sure if this is needed - docs are fuzzy

//Total flow - fFlowTotal will have the total accumulated flow
fFlowTotal = fFlowAccumulator + GetAnalogTotalizerValue(aiFlowRate);


@mstjohn Why is there no GetAnalogTotalizerRate function?


Since you are using an analog input to totalize than maybe just use if value is greater than 0 (I used .5 for my application) totalize like I set up a handful of years back for MM Coriolis mass flow meter tank truck loading and validated using certified truck scales. This is about like Phillip posted above.

//Get VOLUME FLOW 0 - 100 GPM Totalizer Value EVER 2 SEC IF SPG > .7
IF (FT_205B_VOLUME_FLOW_GPM > .5) then
FT_205B_VOLUME_FLOW_SAMPLE = GetClearAnalogTotalizerValue(FT_205B_VOLUME_FLOW_GPM);