View previous topic :: View next topic |
Author |
Message |
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
How can I stabilize the ADC reading? |
Posted: Wed Dec 16, 2020 2:13 am |
|
|
Hello to everyone
I am reading millivolts from adc input. The processor and clock frequency I use have been stated below.
Code: |
#include <18F46K22.h>
#device ADC = 10
#use delay (clock = 64MHz, crystal = 16MHz)
|
My question:
What can I do to read stable voltage at adc input?
1. What can be done with the software.
2. What can be done as hardware.
3. What can be done using both.
Can we get a stable reading with ADC by sending voltage directly to the input pin of the processor?
According to my research unless the PIC has build-in averaging for the ADC and most don't, your options are to either do the averaging in software, or design the hardware so the input signal is really stable.
I don't design hardware but usually put a capacitor between the signal and ground close to the pin or a low pass filter will work I think.
Personally, I will use the resolution of the ADC peripheral that the PIC has. Usually 10 or 12 bits. But setting it to a lower resolution, say 8 bits, would be one way to filter out the noise. Because I guess the compiler always drops the least important bits. How do you think?
But I haven't gained experience yet. I set up the circuit and I will start work. I am waiting for your valuable masters' experiences and support. _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19480
|
|
Posted: Wed Dec 16, 2020 2:37 am |
|
|
It is always best to remove noise earlier. So start in hardware.
The first critical question is what you are using as your Vref?. The reading
has noise from both the signal, and the Vref. Unless the Vref is very stable
and smooth, it is pointless to look further. Genuine Vref sources that
provide a signal to actually offer 12bit resolution are expensive and rare...
Then there is the physical design everywhere round the chip. If there are
ripples on the supplies (and even more importantly on the ground), accuracy
plummets. This is why on some chips the ADC has a separate Vss/Vdd, so
these can be smoothed more to help.
Good analog design is key. Everything introduces noise. Even a resistor
adds noise to a signal. However the levels are small. However heat things up
and noise rises. Make absolutely sure that ground paths do not get crossed
by anything drawing any significant current.
Once you have a stable repeatable analog signal, you can then improve
things by software. It is possible to oversample, and actually extend the
accuracy of an ADC. So with care you can get >13bit results from a 12bit
ADC. The actual filtration method needed depends on the 'nature' of the
remaining noise. If it is normal 'random' noise, simple averaging is good.
However for 'spike' noise, something like an Olympic filter will give better
results.
Start by getting the hardware right. Then look at software. |
|
|
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Wed Dec 16, 2020 3:48 am |
|
|
Mr. Ttelmah, I will take all your words into consideration. I am considering using the LM336 for Vref constant voltage. I reviewed the datasheet. Not very sensitive. Also this information caught my attention:
"± 1% initial tolerance available" I also reviewed the notes for the application. I examined the Absolute Maximum Ratings values. It is not very precise, but I think I can achieve a stable work by creating an offset value with the software.
I also thought of using the constant voltage value inside the processor. for example, VREF_4v096. Do you think it makes sense to use it? The accuracy of tolerance and stable reading is very important. But lm336's low sensitivity will not bother me much. Should I be able to handle the rest with software? But I think PICs are susceptible to interference very quickly. I think I'm facing electronics now. And I have to find ways to offset these damn parasites. The best part is that I think it is a very nice feeling to do research, experiment and come to a solution on these issues. Or because I'm more new, my energy is in full. As time passes, I wonder how I will be : D _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9216 Location: Greensville,Ontario
|
|
Posted: Wed Dec 16, 2020 6:11 am |
|
|
From table 27-3 of the datasheet..
specs for the 4.096 VR value
min typ max
3.891 4.096 4.342
Not exactly a precise, accurate voltage reference !!
Though I've never used it, I'd assumed it'd be better.
Obviously the best Vref would be an external device which might cost more than the PIC.
Whatever signal you are reading should be fed into an opamp 'buffer' to reduce any 'bad readings' due to loading the ADC front end . As Mr. T points out, getting the 'hardware' right is the critical first step so the PIC has a known, repeatable, accurate signal to sample. For the 'digital' or 'software' side, there are lots of 'filter' algorithms. Which one you use depends on how much time you have for sampling. For temperature, say using an LM34, I use the 'Olympic averaging'. You take 10 readings, toss out the highest and lowest, then /8 for the average. It's fast (int16 math), gets rid of 'spikes', compact code.
Jay |
|
|
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Wed Dec 16, 2020 6:28 am |
|
|
I'm not a hardware designer. But what can I do about such an issue. For example, what kind of opamp circuit should I set up at the input of adc? Also how can I free the processor from interference. I connected a 100nf capacitor to the VDD legs. What else do you think should I do? _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9216 Location: Greensville,Ontario
|
|
Posted: Wed Dec 16, 2020 8:20 am |
|
|
re: opamp.....
1st, select an opamp that is BOTH 'rail-to-rail' on input AND output.
2nd, configure as a 'voltage follower'.
3rd, be sure to add small cap (.1mfd ?) nearr the opamps power pins.
4th, add a 1M ? resistor from the opamp input pin to gnd.
The resistor will reduce 'noise' from entering the opamp/adc circuit
the cap also reduces(filters) 'noise'.
Voltage follower means the output will 'follow' (be the same) as the input.
'Rail to rail' means the input and/or output will 'swing' (go to and from ) VDD to VSS (+5 to 0 volts ). Not ALL opamps are designed as 'rail-to-rail' ! so you have to read the datasheets.....
If you plan on more than 1 analog input, use a 'quad' version opamp. Cost is about the same and usually projects 'grow'.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19480
|
|
Posted: Wed Dec 16, 2020 8:48 am |
|
|
On the PIC itself that is down to the design of the board, and particularly
it's power supply.
The PIC is not particularly sensitive to noise. In fact it is several orders
of magnitude better than many other parts. All electronics is noise sensitive
and when you start dealing with low level signals the designs become
harder.
If you study a PC motherboard, you will find hundreds of capacitors in the
supply, and then ones adjacent to pretty much every IC. Close to the IC,
with a solid ground plane. Round the analog parts (audio in and microphone),
you will probably find a break in the ground plane often linked by wires
or tracks, to a single point selected for low noise, and possibly inductors
in the supply rails feeding this part and yet more capacitors. All of these
cost money, but they are included because they are needed.
If you want to work with signals at reasonable noise levels, you are going to
have to learn about how to layout and design the board to reduce noise.... |
|
|
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Wed Dec 16, 2020 11:37 am |
|
|
Could you please share opamp circuit diagram if Mr Jay exists. _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9216 Location: Greensville,Ontario
|
|
Posted: Wed Dec 16, 2020 12:25 pm |
|
|
Use Google 'opamp voltage follower design' or similar keywords, you'll get 1,000s of designs. Keypoints are to use a rail-to-rail, both input and output op amp designed for whatever VDD you're using (+3 or +5), also be sure to use 'bypass caps' close to the power pins.
Jay |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Wed Dec 16, 2020 3:13 pm |
|
|
temtronic wrote: | Use Google 'opamp voltage follower design' or similar keywords, you'll get 1,000s of designs. Keypoints are to use a rail-to-rail, both input and output op amp designed for whatever VDD you're using (+3 or +5), also be sure to use 'bypass caps' close to the power pins.
|
And the Op-Amp should directly drive the ADC input. You can use a low ohm buffer resistor if you want, but typically no capacitors tied to GND to the output of the Op-Amp.
Do your filtering (LC/RC networks on in the op-amp's input.)
And Jay -- you funny. 'mfd' -- no one uses that anymore. (nor 'mmfd' HAHAHA)
I always like to poke fun at the sad and forgotten nF. Seems everyone is either uF or pF these days.
no room for the nanoFarad. Sad. Lonely. Forgotten.
Well -- NOT ON MY SCHEMATICS.. :D :D (Hahahah)
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Wed Dec 16, 2020 3:27 pm |
|
|
bkamen wrote: | And Jay -- you funny. 'mfd' -- no one uses that anymore. (nor 'mmfd' HAHAHA) |
Times change, language changes, terms change. For example, now a person simply has diabetes. My mother, however, calls it "sugar diabetes".
+++++++++++++++
Removed diabetes from spam word list.
It now displays properly.
- Forum Moderator
+++++++++++++++
bkamen wrote: | no room for the nanoFarad. Sad. Lonely. Forgotten.
Well -- NOT ON MY SCHEMATICS.. :D :D (Hahahah) |
I'm with you there, nF all the way! |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Wed Dec 16, 2020 3:35 pm |
|
|
newguy wrote: | bkamen wrote: | And Jay -- you funny. 'mfd' -- no one uses that anymore. (nor 'mmfd' HAHAHA) |
Times change, language changes, terms change. For example, now a person simply has [spam]. My mother, however, calls it "sugar [spam]".
|
Spam? Did the filters get ya?
And for nF -- I love when other engineers hear me use it and you see the look on their face that they have to think about it for a moment. (because they almost never hear it.) _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Wed Dec 16, 2020 3:45 pm |
|
|
bkamen wrote: | newguy wrote: | bkamen wrote: | And Jay -- you funny. 'mfd' -- no one uses that anymore. (nor 'mmfd' HAHAHA) |
Times change, language changes, terms change. For example, now a person simply has [spam]. My mother, however, calls it "sugar [spam]".
|
Spam? Did the filters get ya?
And for nF -- I love when other engineers hear me use it and you see the look on their face that they have to think about it for a moment. (because they almost never hear it.) |
Yeah, must have. Think disease which has a type 1 and a type 2, is treated with something called in-sul-in, and rhymes with "beetus". |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19480
|
|
Posted: Thu Dec 17, 2020 1:21 am |
|
|
I wonder what percentage of the people here actually suffer from that?.
I suspect it may be quite a few of us. I've been Type 1 for over 55 years.
My grandfather was Type 1, before in-sul-in was available. Only just
survived till it came along. In those days it had a very short shelf life,
so they had to get it from the chemist every day.... |
|
|
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Thu Dec 17, 2020 5:39 am |
|
|
I installed the circuit on a perforated copper plate to test it now. What I did in the project:
I reviewed the MCLR link datasheet sheet. I made my setup with the values it specified. I have my OSC connection linked with 16mhz 22pf. I put 100nf capacitor on my VDD pins. I made my ICSP connections. I applied analog filtering to the ADC interference with opamp. I intend to use the opamp as a amplifier if it doesn't provide any benefit. I plan to turn it into a 1/20 gain circuit. Yes, this will be my first project. I have no experience like you. But there is high voltage where I will test the card in the first place. I will give an output according to the voltage information. That's it for now. _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
|