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);
}