Page 1 of 1

Analogue Filtering Advice

Posted: Sat Apr 21, 2018 8:17 pm
by Steve001
Evening All

As a test i am reading an analogue input as a string using a TL431 voltage reference set at 2.5 volts, this is ok.
After 2 decimal places the reading is not stable i would like to read to 4 / 5 decimal places.

Looking at the wiki
https://www.matrixtsl.com/wikiv7/index. ... bit_sample

I am looking at the LP1 & 2 Examples - but don't understand the examples could someone please explain to me :( :oops:

I don't like just copying code i like to know how and why things are done the way they are

Steve

Re: Analogue Filtering Advice

Posted: Mon Apr 23, 2018 8:11 pm
by Jan Lichtenbelt
Hi Steve

Using an 10-bits ADC means that in accuracy will be 1/1024. in case of a 12-bits ADC it will be 1/4096. If you want to read a voltage between 0-5 volt with an accuracy of 4 or 5 decimals, then you need an ADC with about 16-20 bits ADC.

The example files you gave are even worse, it uses only a 8-bit reading of the ADC. And moreover, the filtering used divides the results by 4 which decreases the accuracy even to 6 bits ADC. It will be better to use e.g. the GetInT function and in connection with a better filtering method, if needed,

Succes

Jan

Re: Analogue Filtering Advice

Posted: Thu Apr 26, 2018 12:44 pm
by Steve001
Hi JAn,

That you for that I have since found a guidance note on this subject just trying to read it and make sense of it all. :?

Steve

Re: Analogue Filtering Advice

Posted: Fri Apr 27, 2018 11:59 am
by Benj
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)

Re: Analogue Filtering Advice

Posted: Fri Apr 27, 2018 5:39 pm
by Steve001
Hi Ben,

Thank you for explaining to me i need to have read through again to get my head round it.
I am using a op amp with a RC Low pass filter (hope my maths is correct :lol: ) in my circuit so just thinking out allowed is this not required ?

The -0.232 volts is from a TI LM7705 to enable full 0 - 5 volts span without exceeding 5.5 volts across the amplifier.

I am looking at using a PIC16F18875 - is this going to be over the top for this device with 5 off inputs measuring like this ?


Steve

Re: Analogue Filtering Advice

Posted: Fri Apr 27, 2018 5:44 pm
by Benj
Hi Steve,

A hardware low pass filter is a very good idea.

The software low pass filter is not completely required as well as the hardware filter but can provide additional filtering for spikes induced onto the traces after your hardware filter or for anything not completely caught by the hardware filter.

Re: Analogue Filtering Advice

Posted: Fri Apr 27, 2018 7:36 pm
by QMESAR
Hi Steve,
Just my 2 cents for what it is worth Ben gave you an execelnt example of a basic SW filter
However I always avoid to use a HW filter in the way as you showed it for the simple reason the micro ADC has an maximum input impedance value
shown in the Datasheet under ADC electrical specifications (for PIc16 and 18 ) it is normally around 2KOhm. as your RC filter is after the OPAMP your ADC pin will see the 20KOhm resistance/impedance , I like to use the opamp and the RC Components in a Active Filter design as shown here as an example
1.jpg
1.jpg (22.67 KiB) Viewed 9049 times
In this configuration you can adjust for Anti Aliasing and you have the Low Output Impedance of the OPAMP as a impedance match situation(your ADC is not affected by the Resutances of the RC Filter components . You can Down load the filter Design tool from MC web page(FilterLab) and play with it to see what you can achieve for your requirement Here is an example of the Filter charateristics( Cuttoff and Phase)for the circuit I showed you
As you will see the -3dB or cutoff point is at 159Hz that is the point where your output signal will be 0.707 of the input signal
2.jpg
2.jpg (100.85 KiB) Viewed 9049 times
I hope this help you too,Analog design is a bit of black Art and every person has its own pros and cons :D :D

Re: Analogue Filtering Advice

Posted: Sun Apr 29, 2018 8:10 am
by Steve001
Hi Peter,

Forgot about this method and i have a excel sheet to do the maths that i did and i have used it before... :oops: :oops:
I was fixated on using a op amp follower trying not to load up test signal that i was wanting to measure and getting the measurement correct along with the accuracy.

I will go have a look at the software you suggested better than my sheet

Steve

Re: Analogue Filtering Advice

Posted: Fri Oct 23, 2020 3:56 pm
by AbhijitR
Hello! All
good evening

Many thanks for this post.

Abhi