ActiveBanana
Posts: 5
Joined: Tue Apr 08, 2014 11:23 pm
Location: Ann Arbor, MI

Adding a 5v device to a A2D converter with a 3.3V reference

Thu Jun 12, 2014 2:43 pm

I’ve got one 3.3V analog device on pin 0 of a MCP3008-which is using a 3.3V reference. That device operates like a variable resistor, and is working fine. I am now considering adding a second analog input, from a sensor with a 5V operating voltage. Specifically, this one:

http://www.dfrobot.com/index.php?route= ... 5mJsp5dVyL

Datasheet:
http://www.dfrobot.com/image/data/SEN01 ... asheet.pdf

I want to know if I’d run into any trouble doing this. Checking the data sheet for the above sensor, it shows that the output voltage range is 30mV – 50mV. Is this range too small for my converter to produce a usable digital output, will I have enough resolution using a 3.3Vref? That is, will I be able to detect and translate the change of just a few mV in that narrow range into meaningful sensor values?

Thanks in advance

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Adding a 5v device to a A2D converter with a 3.3V refere

Thu Jun 12, 2014 3:38 pm

A MCP 3008 is a 10 bit ADC. The maximum resolution when using a 3.3 reference is 3.3/1023 or .0032 volts per step or 3.2 mv.

So when you read the ADC, and is says "7" that means that it is reading 7*3.2 or 22.4mv
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
mikronauts
Posts: 2709
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Adding a 5v device to a A2D converter with a 3.3V refere

Thu Jun 12, 2014 4:32 pm

Use a simple voltage divider, like the one below

http://www.pololu.com/picture/view/0J1423
ActiveBanana wrote:I’ve got one 3.3V analog device on pin 0 of a MCP3008-which is using a 3.3V reference. That device operates like a variable resistor, and is working fine. I am now considering adding a second analog input, from a sensor with a 5V operating voltage. Specifically, this one:

http://www.dfrobot.com/index.php?route= ... 5mJsp5dVyL

Datasheet:
http://www.dfrobot.com/image/data/SEN01 ... asheet.pdf

I want to know if I’d run into any trouble doing this. Checking the data sheet for the above sensor, it shows that the output voltage range is 30mV – 50mV. Is this range too small for my converter to produce a usable digital output, will I have enough resolution using a 3.3Vref? That is, will I be able to detect and translate the change of just a few mV in that narrow range into meaningful sensor values?

Thanks in advance
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

Noggin01
Posts: 61
Joined: Tue Jan 07, 2014 1:38 pm

Re: Adding a 5v device to a A2D converter with a 3.3V refere

Fri Jun 13, 2014 12:47 pm

Richard-TX started to give the answer to your question, but it looks like he didn't complete the thought.

As he stated, the resolution of the ADC at 3.3v is roughly 3.2mV per count. If you connect the sensor directly to the ADC pin, at 30mV the ADC will register 6 (30mV * 1023 / 5v). At 50mV, the ADC will register 10. You'll likely get a little bit of noise as well. This is likely to give you very terrible results.

To help, you can use a non-inverting amplifier. If you are not familiar with op-amps, don't let that page intimidate you. You just need an op-amp, two resistors, and a small capacitor (the capacitor isn't show, but goes on the power supply for the op-amp). There are two resistors shown on the diagram, Rf and R2. Gain is 1 + Rf/R2. In other words, if Rf is 9k and R2 is 1k, then your gain is 1 + 9k / 1k = 10.

You'd take your output from your CO2 sensor and connect it to the + input of the op-amp. The output of the op-amp would then be 10 times the output of the CO2 sensor. The range would then be 300mV to 500mV. At 300mV, the ADC would read 61 counts and at 500mV the ADC would read 102 counts. The difference between minimum and maximum is 41 counts, not great but much better than the 4 counts from above.

If you went with a 99k resistor for Rf, then your gain would be 1 + 99k / 1k = 100. The output would be 3v to 5v, and your ADC would read 613 to 1023, or roughly 400 counts of difference.

This is all theoretical stuff here. With a gain of 100, you'd be enticing your op-amp to output 5v at the maximum sensor output. If the op-amp is powered from 5v, many of them won't do it. Some of them will actually invert and output 0v (assuming the negative power lead is connected to ground). So, if you go this route, check the op-amp datasheet and make sure it is rail-to-rail, verify it is accurate at the rails, or don't use a gain of 100.

Also, a gain of 100 means that any noise you have in your analog circuit will be magnified by 100 as well. You'll want to take care and filter your results to try and eliminate this noise, ideally in hardware but you might be able to do it in software as well.

Lastly, a better op-amp solution would be a differential op-amp. They are a good bit more complex than the one I linked you to, and in order to be precise they require matched resistors.

A better solution with less headache would be to find a sensor with a higher output value.

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Adding a 5v device to a A2D converter with a 3.3V refere

Fri Jun 13, 2014 1:01 pm

Noggin01 wrote:Richard-TX started to give the answer to your question, but it looks like he didn't complete the thought.

As he stated, the resolution of the ADC at 3.3v is roughly 3.2mV per count. If you connect the sensor directly to the ADC pin, at 30mV the ADC will register 6 (30mV * 1023 / 5v). At 50mV, the ADC will register 10. You'll likely get a little bit of noise as well. This is likely to give you very terrible results.
Ahem with Vref of 3V3 it is for 30mV in counts = 30mV * 1023 / 3.3 = 9

for 50mV in counts = 50mV * 1023 / 3.3 = 15.5 (could read as 15 or 16 depending on level of noise)
A better solution with less headache would be to find a sensor with a higher output value.
First find out what the maximum voltage output of the sensor is under any condition and scale for that.

30 - 50mV could be for any reason including for these devices, incorrect setup, heater not working, incorrect heat/sample cycle (some are weird cycling), not allowing anything upto 4 hours for sensor to warm up and stabilise, some need 24 hours.

Knowing how some read these datasheets I would not be sure that 30 - 50mV is correct for that device.
Any time I look at the datasheet it claims corruption or other issue. Others are not that sort of range.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

Noggin01
Posts: 61
Joined: Tue Jan 07, 2014 1:38 pm

Re: Adding a 5v device to a A2D converter with a 3.3V refere

Fri Jun 13, 2014 1:04 pm

Ahem with Vref of 3V3 it is for 30mV in counts = 30mV * 1023 / 3.3 = 9
Oops, you're right. I came up with a range of 9 to 16 counts, roughly 90 to 160 counts with a gain of 10, and a range of 900 to 1600 roughly with a gain of 100. Of course, 1600 is out of range of the ADC and I thought, "Oh, wrong reference!" and redid everything instead of recognizing that, "Nope... a gain of 100 is far too much."

Thanks for catching that!

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Adding a 5v device to a A2D converter with a 3.3V refere

Fri Jun 13, 2014 1:15 pm

Quick check even on a Wiki page shows the DIFFERENCE bewteen NO CO2 and max concentration is 30-50mV, but it has NO CO2 at 330mv and max concentration around 280mV

So any gain above 10 is pointless as the absolute value not the difference is what you are measuring.

Also can take 60s between some CO2 and returning to "normal" level, so this is a slow slow reading and a couple of 100nF caps on output and input to op-amp will help reduce noise. possibly with 10nF in parallel.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Adding a 5v device to a A2D converter with a 3.3V refere

Fri Jun 13, 2014 4:13 pm

If you want a larger range for your ADC without using an amplifier, create a nice regulated voltage of 1 volt and use that as your reference. A voltage divider would work.

1 volt reference yields a maximum resolution of .001 volts or 1 mv. With it setup like that the readout will be nearly direct. A reading of 50 ~ 50 mv.

Opamp amplifiers are wonderful devices. But they amplify everything... including stray RF, noise, etc. Sometime you have to fight to reduce the bandwidth.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Adding a 5v device to a A2D converter with a 3.3V refere

Fri Jun 13, 2014 4:42 pm

These CO2 sensors change so slowly that any readings faster than 2 seconds apart will only have to be averaged out anyway.

I would put filters on signal.

A 1.024V reference can be bought easily, at that sort of voltage level I would use a precision refrence rather than resistors from power rails as the power supply noise which could easily be 100mV will affect readings.
Would need to check minimum Vref level the MPC3008 allows

Even then capacitors on reference signal as well.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
BAStumm
Posts: 134
Joined: Fri Aug 23, 2013 3:37 pm
Location: Loon Lake, WA USA
Contact: Website

Re: Adding a 5v device to a A2D converter with a 3.3V refere

Fri Jun 13, 2014 7:37 pm

I believe the minimum reference voltage is 0.25 but low reference voltages affect linearity.

Return to “Automation, sensing and robotics”