MCP3208 12-bit SPI question

I've setup an MCP3208 chip like it describes here to an Arduino Mega:

http://www.arduino.cc/playground/Code/MCP3208

Here's my setup.

My primary question is what do I plug into the pin 15. From the above link:

15 Vref -> reference voltage (that gives max adc reading)

Does this mean that if I have a signal that will have a range of 0 to +5V, I would connect the pin to the +5V on the Arduino output?

If I don't plug anything into the Vref, I get 4095 on the serial monitor.

And will 4095 always be the highest voltage range, and zero will be the value for the lowest voltage in the voltage range?

If I don't plug anything into Vref, I get 4095.

If I plug Vref into GND, I get 4095.

If I plug Vref into pin1, I get some fluctuations on the digital value outputed.

And, if I had a signal that was +-5V, would I plug +5V into Vref, and -5V into AGND?

if I had a signal that was +-5V, would I plug +5V into Vref, and -5V into AGND?

nooooooooooooooooooooooooo

You can only have these voltages between the main power rails.
AGND should be connected to ground and Vref to a voltage that is equal to or less than the power rails (+5v).
What ever voltage you chose that will be the voltage you get the maximum signal from. However if it is too low you get noise on the least significant bits.

Ok, so the chip can't sense voltage ranges that are outside of the power range?

As you can imagine, I'm just starting to learn electrical circuits.

So, just that I'm clear, it's OK to connect Vref on the chip to the power rail +5V?

If I hook it up that way, and I don't have anything connected to the pin I'm sampling should I be getting 4095 ADC value?

And if I connect the pin I'm sampling to GND, shouldn't I get zero as an ADC value?

it's OK to connect Vref on the chip to the power rail +5V?

Yes it's ok to do this. It's not the best thing you can do but it is what is done about 90% of the time. The down side is that any voltage you measure is referenced to the actual voltage of your supply. This might not be (will not be) exactly 5V.
Everything you have seen is consistent and understandable. With nothing connected the input is floating, that is it is subject to noise which is not very big and so the noise on the un connected input is bigger so you get the maximum value.

and I don't have anything connected to the pin I'm sampling

With nothing connected to an input all bets are off and there is no predicting what you will see.

Awesome! Thanks.

I just did that and it seems to be spitting out subtle fluctuations representing noise of some sort.

I was wondering about what you just described about the +5V fluctuation inducing some inaccuracies. Would putting some type of capacitor in btwn help?

What would be the preferred method for holding a constant Vref?

I just did that and it seems to be spitting out subtle fluctuations representing noise of some sort.

That would be noise :slight_smile:

With a 10-bit ADC (1024 steps) each step represents 5V/1024 --> 4.88mV. That kind of voltage is easily induced by fluorescent lights, microwave ovens, random galactic emissions, etc.

Putting a capacitor on VREF helps, as does isolating VREF from the supply voltage using an LC filter. See Section 23.6.2 of the ATmega328 datasheet:

As important as keeping VREF constant is conditioning the actual sensor input. Where is it going and how are you getting it to your board? The shorter the wire the better. Can you send it over twisted-pair wire in which one wire is GND?

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, light sensor, potentiometers, pushbuttons

What would be the preferred method for holding a constant Vref?

The best way is to use a stable source of voltage for Vref. There are a great number of voltage reference chips out there so one of those would be best. If you can't manage that then a zener diode, resistor and capacitor would be better than nothing.
Yes a capacitor would help, also a capacitor across the supply of the chip. I would put a 20R (or so) to the +5v and Vref and then another capacitor across the Vref input.
If you have 12 bits spread over 5V then you have a step size of 1.22 mV, this is quite small and I doubt you will get that level of quietness on a solder-less breadboard like you have.

This is called decoupling and it is a good idea anyway.

The main issue however is that you do not know your voltage....
When you use an external supply, your voltage is around 5.02 volts.
When you use a PC USB port it will be around 4.8 V. When you connect to a notebook it can be even lower.

So make a test:
Connect a 1.5 volts battery to the ADC input and take a reading. Then connect an external power supply to your Arduino. The reading will now be around 5% lower!

However there are (simple) means to make corrections for this...

This is called decoupling and it is a good idea anyway.

If you haven't seen it before:-
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

Ok, so something like this for a voltage reference:

Although, I don't see where to go online to find it.

I'll be doing away with the breadboard when I'm done assembling & coding, and the sensor I'll be trying out has a very clean, precise output.
And I really need to know where zero is in a bi-directional signal, so it looks like this is the best way to go.

Ok, so something like this for a voltage reference:
Mixed-signal and digital signal processing ICs | Analog Devices

Although, I don't see where to go online to find it.

Digi-Key, Mouser, and Newark all seem to have it in stock, though not in all package variants.

--
The Quick Shield: breakout all 28 pins to quick-connect terminals

And I really need to know where zero is in a bi-directional signal, so it looks like this is the best way to go

But how do you want to handle bi-directional signals?
If you offset them to 1/2 of supply voltage than it is not necessary at all to know the supply voltage for zero detection....

But how do you want to handle bi-directional signals?
If you offset them to 1/2 of supply voltage than it is not necessary at all to know the supply voltage for zero detection....

What I meant was that I have a 0 to 5 volt signal that is centered around 2.5 volts. Less than 2.5 volts represent one direction and greater is the other direction. It's a flow sensor, and I need to know when the flow changes direction fairly precisely.

How come this flow sensor knows about 5 volts?

How come this flow sensor knows about 5 volts?

I dunno.

You have to supply it a voltage of btwn 7 & 16 Volts, and it will output the signal as I mentioned.

If the sensor was ratiometric (and +5V was sufficient) would it be reasonable to use the same power rails and assume that whatever fluctuations there were in power would be equally represented in the sensor and in the ADC?

Well, if it needs between 7V and 16V then 5V isn't sufficient so the question is academic.

Can we get a part number/datasheet?

--
The Quick Shield: breakout all 28 pins to quick-connect terminals

None of the datasheets there are exactly like the one I have since the one I have is an old sample, and was likely never mass-produced.

Unfortunately that didn't help much as all of the datasheets there listed 5V devices, some ratiometric, some not.

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, light sensor, potentiometers, pushbuttons

This got me thinking in more general terms.

If precision is important, am I better off supplying power to low-power sensors (~2mA) with a voltage reference chip? Or is that silly cause they aren't meant to supply any current. Is a capacitor better for some current draw?

If the sensor was ratiometric (and +5V was sufficient) would it be reasonable to use the same power rails and assume that whatever fluctuations there were in power would be equally represented in the sensor and in the ADC?

Brilliant! That was my hope to end all troubles :wink:
But it seems the sensor derives an internal 5 volt from the > 7 volts supply (the value of 7 volts is tell-taling..). This will be hardly done by a very high precision (?). So the 2.5 Volts zero level has to be questioned wrt its accuracy. Maybe you have to calibrate for this "zero" level.

It will make no sense to measure something with 12 bit resolution which has an error of 0.5%...