Hello Steve,
I am looking at the LP1 & 2 Examples - but don't understand the examples could someone please explain to me
The low pass filter examples are fairly simple, they allow high frequency variations to be removed by basically combining a portion of the ADC reading with a portion of the previous filtered reading to create a filtered reading.
FilteredReading = (x * ADC_IN) + (y * LastFilteredReading)
In this situation x and y should add up to 1.0 to provide you with a unity gain.
if X is 0.25 and Y is 0.75, starting from 0 with an ADC_IN reading of 1023 you would get an input like this.
(1023 * 0.25) + (0 * 0.75) = 225 + 0 = 225
(1023 * 0.25) + (225 * 0.75) = 225 + 191 = 416
(1023 * 0.25) + (416 * 0.75) = 225 + 312 = 537
(1023 * 0.25) + (537 * 0.75) = 225 + 402 = 627
(1023 * 0.25) + (627 * 0.75) = 225 + 470 = 695
So the high frequency spike from 0 to 1023 has been removed. If you looked at the response on a graph then it would be an exponential type curve.
I've used these types of simple low pass filters on industrial and safety critical projects with great results.
The example I used above uses floating point maths which is not very optimum especially for an 8-bit micro. So if you wanted say 50/50 then you could simply do a right shift which would be vastly more efficient.
FilteredReading = (ADC_IN >> 1) + (LastFilteredReading >> 1)
is the same as
FilteredReading = (0.5 * ADC_IN) + (0.5 * LastFilteredReading)
Another example
FilteredReading = (ADC_IN >> 2) + (3 * (LastFilteredReading >> 2))
is the same as
FilteredReading = (0.25 * ADC_IN) + (0.75 * LastFilteredReading)