I am trying to read a 4-20 ma pressure sensor on an anolgue input of an ATMega168 set up like Arduino on a breadboard. My analogRead() commands are coming up with figures varying up and down for a static pressure.
Thinking it was noise through the 1 metre sensor cable, I tried it using a pair of resistors as a voltage divider without the sensor connected.
I got random values between 707 and 721 for 2.3 volts using an AREF of 3.3 volts. (When measured with a multimeter the voltage remains constant to three decimal places)
I can only assume that the variation is noise.
I have a 100uF and 100nF across the input of power to the breadboard and a 100nF across AVcc and ground. I have a 10uH inductor between Vcc and AVcc as per the Atmel datasheet. However I note that the new Arduinos use a 100uH and the Bare bones uses a 15uH! Which is the best value to use if I only want DC to come through to the analogue port?
(What is the difference between the three types of filters:
Lone Capacitor
Resistor/capacitor
Inductor/capacitor)
Has anyone got any ideas how to calm down my analogue readings?
(I am already using averaging on a 5 sample basis but would like the original readings to be as accurate as possible to avoid fluctations even after averaging).
That's the problem. try to eliminate that by putting an amplifier at the sensor end of the cable. Failing that feeding the sensor into a differential amplifier will remove common mode interference and noise.
My ARef is derived from my power supply and filtered through the previously mentioned 100uF and 100nF caps. I am running the micro at 3.3 volts which is provided by a small switched mode regulator. This voltage is stable.
The ADC noise reduction mode would be too limiting and looks like it is difficult to get it to wake up safely. (I'm a noob at these low level operations).
I only have a couple of resisitors on the same breadboard as the micro thereby removing the variable of the sensor cable or noise coming in through any other long cables.
So basically there is a variation on the A/D readings with a potential divider close to the chip.
One way might be to slow down the conversion rate of the A/D you can do it on the chip but I am not sure how this is done in this environment.
Another is to put plenty of decoupling on the Vref.
As you say you will not see noise on a DVM as the conversion rate is only about 3 a second normally.
My ARef is derived from my power supply and filtered through the previously mentioned 100uF and 100nF caps. I am running the micro at 3.3 volts which is provided by a small switched mode regulator. This voltage is stable.
Have I understood this correctly:
You have a power supply from which you:
a) derive a 3.3V as an external reference for the ADC;
b) supply a switching regulator to produce 3.3V for Vcc.
What circuit are you using to generate the 3.3V reference?
Can you use the internal reference when running at 3.3V?
I use the power supply to provide the 3.3 volts to Vcc and AVcc.
I understood that the default was that the micro would use AVcc as the analogue reference.
Isn't the internal reference something like 1.1 volts?
The default is to use Vcc as the reference for the ADC.
This link describes how to use an external voltage on the Aref pin: analogReference() - Arduino Reference
Its funny what you learn when looking into things ... it turns out the AVR chip does have a sepearte ground (AGND) for the ADC. So some work on the ground layouts of the circuit can be done if needed.
I'm still a little confused as to your circuit. Can you post a sketch showing how you have connected to the VCC, AVCC, AREF, GND and AGND pins?
I had not issued the command "analogReference(EXTERNAL);"
However as I was using only 3.3volts to power the unit, it is unlikely that it would be able to use the default 5 volt reference and would fall back to the max that Vcc could provide which is 3.3. volts.
I suppose that this is why my analogue readings of ~700 for 2.3 volts on the pin are in the correct range for an Aref of 3.3 v instead of 5v which would yield lower readings.
Thanks but what does,
"Another is to put plenty of decoupling on the Vref. "
mean? How is this implemented?
Connect the AREF (pin 21 sometimes called Vref because it is a voltage reference) To Vcc with an inductor or something like a 100R resistor (10K is too big). Then connect a capacitor (0.1uf to 0.01uF ceramic) between the AREF and ground.
That way you decouple the reference voltage. A noisy reference voltage will give just the symptoms you say as will problems with the ground planes as mentioned by BigMike.
Edit.
Just seen in the data sheet that AREF is always connected to internal reference so if you continue to use Vcc then still connect a capacitor to it to ground. (don't connect with a resistor to Vcc unless you use an external reference)
I have included the "analogReference(EXTERNAL);" in my setup and followed the instruction:
"Connect the AREF (pin 21 sometimes called Vref because it is a voltage reference) To Vcc with an inductor or something like a 100R resistor (10K is too big). Then connect a capacitor (0.1uf to 0.01uF ceramic) between the AREF and ground. "
It seems to have done it!
My lowest reading is 723 and my highest 728 (taken over 60 seconds with a constant voltage). Percentage wise this is much more acceptable.
I am not clear if the fix was configuring for the external reference, cleaning up the voltage, or both. I wonder if it's not too difficult, could you try it without the filtering and see if you get the same readings.
Would an inductor be better than a resistor? If so, I have a 100uH and a 10 uH at hand. Which would be better?
An inductor would be better. In a perfect world the higher the better, but in this real one it depends on the high frequency response of the component you have.
Due to stray capacitance you sometimes get better HF rejection using the lower inductive. It's a bit counter intuitive but is the same with a capacitor they both have a self resonant frequency. Above which they start behaving the other way round (an inductor looks like a capacitor and via versa)