Average a analog input?

bkp_80

Member
Join Date
Mar 2015
Location
Texas
Posts
3
First off, I'm very rusty at the moment when it comes to programming, last time I did any programming was 15 years ago, and now this project has been dropped in my lap. The Controller is a 1769-L30ER with a 1769-IF40F2 analog card.

In this project there is a plunger pump that pressurizes a vessal 0-1000 PSI and a pressure transducer that measures the pressure inside this vessal, the problem is the transducer is picking up on the spikes the pump produces, so the "live reading" inside the program is bouncing up and down but steadily rising until the pump turns off. In the program the analog input is used to feed a "Greater than or Equal to" that once it reaches the set-point it starts a timer, since the reading is bouncing up and down, it will start the timer then drop the timer and then restart, and repeat until the bouncing range is above the set-point at which time the pump shuts off. After talking with a tech from Rockwell Automation, he suggested a MAVE to provide a "Running Average", basically it would take a so many samples, then average them, as the PSI is rising. I'm having a tough time trying to figure out the code to produce this. If anyone has some experience with this, I would truly appreciate it.

Thanks
 
The MAVE command is available in 'Function Block' and 'Structured Text' but not in ladder. If you are using either of the first two then go to the 'Help' and view the usage of the instruction.

If using ladder an equivalent would be to use FFL and FFU to keep an array filled with readings. Then use the AVE command to derive an average of a number of readings.

Another method is a 'low pass filter'. When you have a 'New' analog reading perform the following:

'Filtered Reading' = (('Filtered Reading' * 'Filter Factor') + 'New Reading') / ('Filter Factor' + 1)

Use 'Filtered Reading' in your comparison.

A 'Filter Factor' of '0' means no filtering. Raise the 'Filter Factor' (try just adding '1' at a time) to dampen the reading (but note that this will also delay response).

Edit - another consideration is to dampen just the spikes. If a new reading is more than a certain amount above the average then limit it to that amount. Feed that to the filter code. This would be based on the maximum possible pressure rise rate. Set the amount to just a bit above that so that the system can't possibly lag behind.
 
Last edited:
Thanks for the help Bernie, the software here is Studio 5000 mini edition, which I've noticed doesn't have the function block editor, so I'll have to approach it using ladder. I'll have look into the FFL and FFU instructions to see how they work, if anyone has a example of them being used that would be awesome. The filtered reading looks interesting, but I have no idea how I would implement that into the ladder, I'm just not familiar enough with this software and programming in general at the moment.

Thanks again.
 
An alternative for ladder is to use the copy command with the average command . Create an array of , say , 10 variables . Copy variable 1 to variable 0 length 9 . Move the input value to the last variable in this case 9 . Use the average command as Bernie suggested , on the entire array .
All these commands are called by the done bit of a free running timer , which is set for the period you require for your average .

Paul
 
Neither a low pass filter or average seems to be what you really want.
The pressure spikes are valid. They aren't noise. The average and filtered value will always move slightly up and down.

If your sampling is fast enough you can try to catch the lowest or highest values for a cycle. If you opt for catching the lowest pressure for a cycle then you can just wait for that value to be greater than your set point.

How to you catch the lowest value of a cycle?
Code:
if pressure(n-1) < pressuer(n) and pressure(n-1) < pressure(n-2) then
   lowestpressure = pressure(n-1)
end_if
 
Not sure that input module part # you gave is a good one, or I'm unfamiliar with that one.
You could also go to the module configuration and use the filter thats in module setup. If available on that input module.
 
This is a sample - The DIV and ADD instructions are for calibrating the input . Replace them with a MOV instruction .
 
If you are wondering why the new reading from the analog source is not entered at the start of the array - when copying from / to the same array , the copy works from the 1st to the last so copy array [0] to array [1] , copy array [1] to array [2] and so on , so always copy 'down ' .
 
No need for an array. Here is an example of a 2% filter (it applies 2% of the current reading to the running average). Set the free running timer however you like:

Filter.png
 
Thanks for the help guys, I really appreciate it, still trying to figure out how it all works, but I do appreciate it.

Rootboy, On your example, how does the CPt get a value for "filteredPSI" the first time it tries to calculate it?

Also does anyone know of a company that makes a emulator or software that lets you turn your PC into a simulated PLC, and maybe be able to tie LED's or coils to outputs, so that you can actually work on a project and see it working without having a PLC in front of you?

Thanks
 

Similar Topics

hi I have to take average of my analog input data from analog input module FX 2N-2AD using with FX1N plc. As I cant treat REAL NUMBERS in FX1N...
Replies
0
Views
2,037
Hi I am trying to find out , how to get an average of an analog input for 24 hours. I am interest to know the average of analog input value for...
Replies
6
Views
7,047
Hi all-- I need to create code in a Micrologix 1400 project that requires minimum, maximum and running average calculated values (Flows and...
Replies
17
Views
3,744
Hello, I'd like to obtain average of my analog input value which will be displayed on SCADA. For examplle, analog value should be sampled avery...
Replies
2
Views
2,128
I have a Banner LT3 laser sending 4-20ma signal to a Compact Logix System. The signal is the level of product on a conveyor. The signal is fast...
Replies
6
Views
8,750
Back
Top Bottom