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
I don't like just copying code i like to know how and why things are done the way they are
Steve
Analogue Filtering Advice
Moderator: Benj
- Steve001
- Valued Contributor
- Posts: 1189
- Joined: Wed Dec 31, 2008 3:37 pm
- Has thanked: 460 times
- Been thanked: 523 times
- Contact:
Analogue Filtering Advice
- Attachments
-
- LPFilter2.fcfx
- (6.77 KiB) Downloaded 351 times
-
- LPFilter.fcfx
- (6.74 KiB) Downloaded 330 times
Success always occurs in private and failure in full view.
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: Analogue Filtering Advice
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
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
- Steve001
- Valued Contributor
- Posts: 1189
- Joined: Wed Dec 31, 2008 3:37 pm
- Has thanked: 460 times
- Been thanked: 523 times
- Contact:
Re: Analogue Filtering Advice
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
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
Success always occurs in private and failure in full view.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Analogue Filtering Advice
Hello Steve,
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)
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.I am looking at the LP1 & 2 Examples - but don't understand the examples could someone please explain to me
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)
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Steve001
- Valued Contributor
- Posts: 1189
- Joined: Wed Dec 31, 2008 3:37 pm
- Has thanked: 460 times
- Been thanked: 523 times
- Contact:
Re: Analogue Filtering Advice
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 ) 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
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 ) 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
- Attachments
-
- Capture.JPG (68.43 KiB) Viewed 8642 times
Success always occurs in private and failure in full view.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Analogue Filtering Advice
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: Analogue Filtering Advice
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
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 I hope this help you too,Analog design is a bit of black Art and every person has its own pros and cons
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
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 I hope this help you too,Analog design is a bit of black Art and every person has its own pros and cons
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
- Steve001
- Valued Contributor
- Posts: 1189
- Joined: Wed Dec 31, 2008 3:37 pm
- Has thanked: 460 times
- Been thanked: 523 times
- Contact:
Re: Analogue Filtering Advice
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...
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
Forgot about this method and i have a excel sheet to do the maths that i did and i have used it before...
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
- Attachments
-
- Capture.JPG (16.59 KiB) Viewed 8602 times
Success always occurs in private and failure in full view.