As many have noted the FMD/Fx ADC readings dance around a bit from sample to sample. I have not been alone in observing this behavior.
The PLC's have some options for enabling a moving average filter within the ADC firmware. And this helps with the noise.
I have been using a simple digital filter that acts as a low pass filter to reject the random noise and at the same time increase the resolution of the ADC channel from 12 to 13 bits (0..8191).
This is the simplest version of the code:
DM32[1] = ((DM32[1] * 31) + ADC(1) + ADC(1)) / 32
[/font][/color]
How do I use it? I invoke this code 10 times every second usually timed to the Clk:0.1Sec signal. My actual application only needs to look at the computed ADC value once every second or two. I'm not working with stuff that changes all that rapidly.
How does it work? This is a simple single pole IIR (Infinite Impulse Response) low pass filter. Each time the code is called the output, calculated output value, DM32[1] is updated. The new output value is 31/32 of the previous value with the "new" ADC value contributing only 1/32 of the "new" output value. This is a digital implementation of an analog filter that might consist of a series resistor and a capacitor to ground. Google "IIR low pass filter" for the real science.
Why do I add the ADC(1) value into the equation twice? I wanted to double the resolution of the ADC from 12 bits to 13 bits as a byproduct of over ADC over sampling. I found that if I use two separate ADC samples that this works much better. There is actually a requirement for a bit of noise from the ADC conversion to make the oversampling work. Google ADC oversampling for the technical details.
Ok what is the down side of this trick? Response time. If the input makes a big change in value, the output, DM32[1] will take a few seconds to respond to the change. The two constants 31 and 32 in combination with the sampling rate (0.1 Hz) determine the time constant for this filter. If the filter is too sluggish for your requirements, increase the sampling rate or change the filter constants to 15/16 or 7/8.
I have been working, with systems that the analog values cannot change very rapidly. One of my clients monitors the levels in 100,000 liter fuel tanks using a pressure gauge. It takes over 2 hours to fill the tank and about a week to empty into transit buses. So from one second to the next the level in the tank cannot change so the filter delay is insignificant in this application.
So I am happy to trade off some response time to get stable ADC readings and double the resolution of the ADC from 12 to 13 bits.
Best regards,
Gary D*ickinson