Hello all!
I dont know if this is a ADC problem or a arduino(code) problem. Long story short is that i get some wrong output from my ADC.
On the left column is the voltage the the ADC has as input and on the right one is the number that i get from it.
0 v 0
0.5 380
1 v 720
1.5 v 1050
2 v 1380
2.5 v 1720
3 v 2050
3.5 v 2430
4 v 2890
4.5 v 3370
5 v 4095
I guess i should have for 2.5v = 2048, right ?
Any tips ?
Also here is the code that i use:
#include <SPI.h>
#define CS_3202 10
void setup()
{
Serial.begin(57600);
pinMode(CS_3202,OUTPUT);
digitalWrite(CS_3202,HIGH);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV8);
}
void loop()
{
Serial.print("CH0 =");
Serial.println(Read3202(0,CS_3202));
Serial.print("CH1 =");
Serial.println(Read3202(1,CS_3202));
delay(300);
}
int Read3202(int CHANNEL, int CS){
int msb;
int lsb;
int commandBytes = B10100000 ; // channel 0
if (CHANNEL==1) commandBytes = B11100000 ; // channel 1
digitalWrite(CS, LOW);
SPI.transfer (B00000001); // Start bit
msb = SPI.transfer(commandBytes) ;
msb = msb & B00001111;
lsb = SPI.transfer(0x00);
digitalWrite(CS, HIGH);
return ((int) msb) <<8 | lsb;
}