I'm fairly new to Arduino projects, and only recently did I acquire an Intel Galileo board. One thing that has bugged me during my initial experiments is that I am unable to reach the maximum read value (1023) with the analogRead() function. With A0 pin shorted to 5V, the returned value is roughly 996~997. Same thing does not happen with ground, I get 0 when I short A0 to ground.
What happens if you short it to AREF instead of +5V?
fungus:
What happens if you short it to AREF instead of +5V?
It reads "5"
If you shorted it with a big loop of wire, you may be picking up RFI.
There should also be a bypass capacitor from Aref to ground. Some Arduino variants don't have a capacitor there. Two is good, 0.01uF and 10uF. Or in a pinch, just a 0.1uF capacitor.
Thanks for the info, however I've just come across this bit on Galileo's datasheet:
AREF is unused on Galileo. Providing an external reference voltage for the analog inputs is not
supported.
o For Galileo it is not possible to change the upper end of the analog input range using the AREF pin
and the analogReference() function
So does this means it is not possible to adjust upper value? I guess the AREF pin is just a placeholder in order to allow support for UNO's shields.
The external ADC chip used on the Galileo is rated for 0-2.5V input. But the Galileo board says its analog inputs accept 0-5V, so there must be a voltage divider on each pin (it says 8 separate converters). You may just be looking at a combination of ground noise and the tolerance of the voltage dividers.
So what about your connections to ground and 5V? Directly from an analog input to ground or 5V, or by a big loop of wire? Or does it first pass through a shield and a protoboard? You might try putting a 0.001uF (1nF) capacitor from the analog input to ground.
Somehow I kept misreading what you said about what happens when the analog input is grounded.
It is connected by a medium sized wire, about 50 cm. I will test with a shorter wire.
And pardon the noob question, but what exactly would the capacitor do when placed fron the analog pin to ground?
The capacitor might bypass noise. It sounds like it might be either (or both) noise from the 5V source, and/or the tolerance of whatever is dividing the input 0-5V down to 0-2.5V.
Oh! Another thing... since that ADC chip has its own 2.5V reference, it may simply be that the 5V line is a little low. 5V is never exactly 5V. The reference 2.5V in that chip is no doubt made to be much higher accuracy than the 5V regulator.
polymorph:
So what about your connections to ground and 5V? Directly from an analog input to ground or 5V, or by a big loop of wire? Or does it first pass through a shield and a protoboard? You might try putting a 0.001uF (1nF) capacitor from the analog input to ground.
The analog inputs already have 150nF capacitors on them, this wouldn't achieve anything.
(*)
The discrepancy in not reading 1023 is because, as has been mentioned, the ADC is
measuring w.r.t an accurate voltage reference, not the 5V rail. If you measure the
5V rail you should see its about 4.87V (give or take, the resistive divider uses 1%
resistors).
The actual chip used, according to the schematic, is capable of reading 12 bits, not 10,
but I don't have a Galileo to check this.
(*) This does limit the bandwidth of the analog inputs, note.
MarkT:
polymorph:
So what about your connections to ground and 5V? Directly from an analog input to ground or 5V, or by a big loop of wire? Or does it first pass through a shield and a protoboard? You might try putting a 0.001uF (1nF) capacitor from the analog input to ground.The analog inputs already have 150nF capacitors on them, this wouldn't achieve anything.
(*)The discrepancy in not reading 1023 is because, as has been mentioned, the ADC is
measuring w.r.t an accurate voltage reference, not the 5V rail. If you measure the
5V rail you should see its about 4.87V (give or take, the resistive divider uses 1%
resistors).The actual chip used, according to the schematic, is capable of reading 12 bits, not 10,
but I don't have a Galileo to check this.(*) This does limit the bandwidth of the analog inputs, note.
Actually, when I measure with a multimeter the 5V pin, I get 5.02V, with the corresponding measured value being 4.85~4.86 due to not reaching highest value. How exactly did you arrive at 4.87V from 1% tolerance values?
And how accurate is your meter?
polymorph:
And how accurate is your meter?
Can't really answer that, don't have enough info - it's a UniVolt DT81RS (writen on the device), however I can't find any information about it anywhere.
So I should really trust the Galileo more than the multimeter? Having a 5V rail actually makes sense that 4.85 would correspond to a ~995 level on the ADC.
So I should really trust the Galileo more than the multimeter?
No it is not the board but the board's power supply. I wouldn't trust either of them to be better than 1% and that is if you are lucky.
I tried measuring directly the output of the Galilleo PSU, I got 5.05V, which is slightly more than what I get on the 5V pin (5.02V). This is still not enough to explain the discrepancy, as even considering this drop I should be able to values up ~1015.
So I guess it's safe to assume that the ADC is using a voltage higher than the 5V rail as VREF, and that the voltage divider couple to each analog pin causes an addtional voltage drop on the measured values.
That being said, I don't really have anything to compare as I'm still waiting for my Uno R3 to arrive, but it seems to me like a rather big limitation on this board.
So I guess it's safe to assume that the ADC is using a voltage higher than the 5V rail as VREF,
No.
It is using 2.5V as Vref. Any input signal is nominally reduced by half so an input of 5V will give you 2.5V on the A/D which will give you "full house" or all the 1s.
The potential divider resistors are marked on the schematic as 4.99K @ 1%
Remember that this applies to both resistors in the potential divider so the most likely explanation is that these are reducing the input by a touch more than half, leading to a 5V input on the analog pin is not quite producing a 2.5V voltage on the input to the A/D converter.
So apparently this issue might also be related with the multiplexer used in the analog input pins 0-3, which is different from the one used for A4 and A5. After opening a similar topic on the Intel Communities website, I got the following answer:
I've tested the ADC of my Galileo and I have found out that the A0, A1, A2, A3 are giving values below the 1023 that they should provide on 5V, but the pin A4 and A5 are working properly. I looked at the schematics of the Galileo and the only difference I noticed is that those pins are also connected to another multiplexer for the SDA and SCL. Maybe that could be causing the issue, but let me make some more research about it since I could be wrong. In the meantime I recommend you to use A4 and A5 pins for the Analog digital conversion.
No he is wrong, that has nothing to do with it. Those pins are only connected that way because they have to serve as the Arduino compatible I2C pins. This will have no effect.
Any difference between the channels is down to the resistor tolerance. The resistors are all going to be different values.
I'm sure the resistor tolerance have a part in it, however I think there might be something else related to this. I've just tested with my Galileo and can confirm that the values go full range on A4 and A5, therefore there must be something different on these analog pins that somehow affects ADC behaviour.