I've been playing with the LTC1605 and a mcp9701 temperature sensor with my 2560 mega (just ordered the MCP3208, way less pins to deal with.) In order to get an accurate voltage value, I have to use 5.0*adcvalue/16384 to get an accurate voltage value. From the datasheet the data is two's complement, so the MSP is used to tell if the number is negative or not so the number of possibilities should be 2^15, but for some reason I have to base my calculation on 2^14 to get an accurate voltage value. What am I doing wrong? This is my first time with working with an external ADC.
Datasheet:
Pin 22 is connected to D15
Pin 37 is connected to D0
The BYTE pin is held LOW
float adc;
int cs=51; //pin number connected to the CS pin
int rc=52; //pin number connected to the RC pin
//temp to voltage
//volts per step = 5/16384
void setup() {
Serial.begin(9600);
pinMode(cs,OUTPUT);
pinMode(rc,OUTPUT);
digitalWrite(cs,HIGH);
digitalWrite(rc,HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
adc=0;
inital();
readdata();
Serial.println(adc);
temps();
delay(3000);
}
void inital(){
digitalWrite(cs,LOW);
digitalWrite(rc,LOW);
//delayMicroseconds(1);
//
digitalWrite(rc,HIGH);
digitalWrite(cs,HIGH);
}
void readdata(){
int count=22;
float val2=65536;
while((count)<=37){
val2=val2/2;
if (digitalRead(count)==HIGH){
adc=adc+val2;
}
count++;
}
}
void temps(){
float temp=5.0*adc/16384;
temp= (temp-.5)/.010;
temp = 9/5.0*temp + 32.0;
Serial.println(temp);
}