0
\$\begingroup\$

I am using the MCP3204 ADC with my Arduino. The chip is powered by 5V from my LM338 PSU. Since I don't have a proper reference at hand, I use the supply voltage as Vref as well. When I give it 5V, it shows 4093 which is full deflection of 12 bit ADC. I voltage divided it down to 2.5V with two 10k's then it's 1757. I checked with my DMM and it's 2.513... huh? I suck at math but am sure that's not 1/2 of 4093.

original code in C from tutorial http://extremeelectronics.co.in/avr-tutorials/interfacing-12-bit-spi-adc-mcp3204-with-avr-micro/

uint16_t ReadADCEx(uint8_t ch) {    uint8_t byte,data_high,data_low;

   byte=0b00000110;

   if(ch>3)
      byte|=0b00000001;

   CS_LOW();

   SPIWrite(byte);

   byte=ch<<6;

   data_high=SPIWrite(byte);

   data_high&=0b00001111;

   data_low=SPIWrite(0xFF);

   CS_HIGH();

   return ((data_high<<8)|data_low); }

My arduino eqivulent

#include<SPI.h>
const int ssPIN = 10;
void setup() {
  // put your setup code here, to run once:
  pinMode(ssPIN,OUTPUT);
  SPI.begin();
  Serial.begin(9600);
}
uint16_t ReadADCValue(uint8_t ch)
{
    uint8_t value,data_high,data_low;

  //active MCP3204
  digitalWrite(ssPIN,LOW);
  value = 0b00000110;
  SPI.transfer(value);
  value= 1 << 6;
  data_high=SPI.transfer(value);
  data_low=SPI.transfer(0xFF);
  digitalWrite(ssPIN,HIGH);
   return ((data_high<<8)|data_low);
}

void loop() {
Serial.println(ReadADCValue(1));
delay(1000);
}
\$\endgroup\$
0
\$\begingroup\$

ADCs usually have 15 or 20pF sample caps. Try a 1000pF cap from the divider node to ground to lower source impedance driving the ADC.

\$\endgroup\$
6
  • \$\begingroup\$ Nope 102 ceramic cap makes it only slightly higher. Is this an indication my code is driving the ADC correctly? I just need to use a proper external ref \$\endgroup\$ – Ageis May 10 '14 at 0:09
  • \$\begingroup\$ @Ageis - Haven't read your code, and not familiar with arduino. But high impedance sources into ADCs are limiters. Since you get a good result with sampling 5V from LM338, which probably has an impedance less than 10 Ohms, but have problems with ~5KOhm source ... seems suspicious. What is sample frequency? At ~ 1MHz, 1000pF is ~200 Ohms, which may still be too high. MCP3204 datasheet says ADC source needs to be low impedance (p19). usually an amplifier is used. \$\endgroup\$ – gsills May 10 '14 at 3:01
  • \$\begingroup\$ I don't understand why an amplifier would help. Doesn't that make it hi impedance. For example if I was to connect my voltage divider into a opamp (voltage follower) it isolates the adc from the divider. The source of power becomes the supply rail feeding the opamp \$\endgroup\$ – Ageis May 10 '14 at 11:37
  • \$\begingroup\$ @Ageis OpAmps have high input impedance, but low output impedance. Yes the OpAmp would isolate the divider from the ADC input. By using an OpAmp you get an accurate (non loaded) voltage from the divider and a low impedance source to the ADC, so the sample and hold can better represent the signal. It is even easy to incorporate an anti-aliasing filter around the OpAmp. \$\endgroup\$ – gsills May 10 '14 at 15:13
  • \$\begingroup\$ Thanks for the explanation gsills. Ok I do have a voltage follower now. I do get a good reading occasionally but must of the time the reading is very high. IT's way out of the range of the adc. Like 65000. Why is this? I have tried decoupling the adc with 100nf capacitor. \$\endgroup\$ – Ageis May 11 '14 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.