Integrating numbers from Analog Input

JoeM1

Member
Join Date
Jul 2015
Location
Tucson
Posts
71
Hello,
I have a application where a analog input will be constantly updating a value in a PLC. What I want to do is mathematically integrate these results on a continuous basis.

Has anybody ever done this?
Thanks
 
What system are you using?

Is the analog input connected to a flowmeter and you are wanting to integrate to calculate total flow?

Assuming you are trying to integrate a total flow from a flow rate measurement, here are some general notes.

Create a timer of Xms (could be 100ms, could be 10, could be 5000... sorta depends on the rate you want to do the totalizing).

Have the enable for the timer be its not done state.
Ie. Psuedo code for IEC ST type.
CalcTimer( in= NOT Calctimer.DN, Preset= 1000ms)

When the timer is finished, add the analog input flow rate times a multipier (this is dependent on what the timer rate is and what the analog input represents (ie. flow/min, flow/hr, etc) to the accumulated total.

Example is an analog input that is reading lb/min computing totalized lb every 1 sec.

Pseudo code.
When the timer is done, add the last seconds worth of flow to the totalizer.
If CalcTimer.DN then
FlowTotal = FlowTotal + (Analog_Input_Flowrate_lbmin * 1/60)
end_if

Description of the pseudo code.

Total flow = current total + ( rate (lb/min) * (1min/60sec))

This is only true if triggered every 1sec.
 
I have used a method similar to g.mccormick's response for creating a flow totalizer from a flow rate input. There are a couple of things I'd specify:

1. If at all possible, place this logic in a timed task rather than using a timer, especially if this value is of a critical nature.
2. If using floating point, adding a relatively small value to a relatively large value can be problematic. To overcome this, use an intermediate integral (one that counts to say 1, 10 or 100) then when this preset is reached, subtract that preset amount from your intermediate integral value and add it to your main integral.
 
I have used a method similar to g.mccormick's response for creating a flow totalizer from a flow rate input. There are a couple of things I'd specify:

1. If at all possible, place this logic in a timed task rather than using a timer, especially if this value is of a critical nature.
2. If using floating point, adding a relatively small value to a relatively large value can be problematic. To overcome this, use an intermediate integral (one that counts to say 1, 10 or 100) then when this preset is reached, subtract that preset amount from your intermediate integral value and add it to your main integral.

I agree with RonJohn. A timed task will have less dither than a timer executed (i believe). If your system has LREAL as an option, you can make the totalizer a LREAL then not really have to worry about loss of precision. Otherwise an integer may be the best bet.

Of course, we are speculating a lot on your needs without much to go on. What are you actually trying to do?
 
Ok, so the readings on the analog input come from a "measuring device" which I wont disclose due to IP reasons. What I want is to average all the readings that are in a certain range together and throw out all readings that deviate more than x percent above or below this average. I want this to constantly run, as fast as it can.
 
Ever Flow Meter I have used has a "Pulse Output" that can be programmed to what works best for the application.

Example: each pulse = 100 gal. or 1000 gal or 10 gal..

Once you have the pulse output programmed all you have to do is count the pulses and you could even set it up so that the pulses are counted for a set time and at various times throught the day. This is because the flow rate will in most cases vary.

So at the end of the timeframe if you had 36 pulses over a 6 hour period and it was programmed at 100 gal. per pulse you would have moved 3600 gal. or 600 gal. per hour/avg. because your rate of flow will always vary.

This is how I would probably handle this.
 
What PLC are you using? Logix 5000 comes canned with a totalizer for this function. That said, I agree that counting pulses is a better way of doing it.
 
your two descriptions seem to be different on what you want to do "INTEGRATE" or "AVERAGE", to average you could shift the incoming values into a shift register say an array of 10 on a timed basis then add them up and divide by number of shifts this would give an average, however if you only want values +- a per cent of a given value you would have to check this before shifting the data in to the fifo.
 
Real Time Avg Subroutine

You never said what platform your using and this is for Allan Bradley RSLogix 5000.

It's an exported Subroutine for a machine's cycle time. It figures the average based on the number of entries in the Array. It is set to figure an average for up to 10 cycles but it can modified to do more by increasing the Array's sizes.

Good luck with your project!
 
...to average you could shift the incoming values into a shift register say an array of 10 on a timed basis then add them up and divide by number of shifts this would give an average, however if you only want values +- a per cent of a given value you would have to check this before shifting the data in to the fifo.

The attached Logix5K ladder code is an example of the above, except it uses a fixed acceptance band (+/- 0.5). I would caution against not including the outlying data in the moving average, though, because if there is a step change in the source data it will stop accepting data. That could be OK depending on the expected behavior of the source input.

Also, with this simple approach, you will need a way to make sure the moving average buffer is full before doing the acceptance test (e.g., branch around the limit test with a start-up bit that is energized while filling the buffer for the first time, or after some kind of reset).

MovAve Accept.jpg
 

Similar Topics

I am trying to set a bit to command the Zebra ZT230 to print a label and receive a confirmation bit from the unit via an Automation Direct Click...
Replies
0
Views
667
Good afternoon! For the past several days, I have been trying to set up this Balluff BIS018A RFID head to communicate with a Do-more BRX DM1E-M-D...
Replies
10
Views
5,556
Hello I really need help here.. So I upgraded my wonderware from 10.0 to 10.5 edition. When I try to connecting the OPC(in PC1) to Intouch (In...
Replies
5
Views
1,399
I'm trying to integrate an analog module EXM-AMM 3HT as an extension for Pfxlm 4301 taddc. The documentation I've found so far is awfull. How does...
Replies
0
Views
1,310
Integrating PowerFlex 755, Incremental Encoder, & Proximity Sensors into Ladder Logic Hello All! This is my first post so please give my...
Replies
7
Views
6,391
Back
Top Bottom