Code
Code
const int LTC_CS = 10; //set ADC chip select pin to Arduino pin
10
const int CalButton = 2; //set calibration button to use D2
long adcread; //reading from the ADC (LTC2400)
int CalSetup = 0; //calabration check
float cal = 0; //calibration adjustment factor
float volt; //voltage reading
float v_ref = 4.096; //Reference Voltage used
String v; //string to select V, mV or uV on display
float trim = 0; //calibration error trim factor
const int samples = 4; //set number of sample readings to take
int ct = 190; //ADC converstion time (plus additional
program loop time)
int d = 0; //integer that holds number of decimal
places displayed on LCD
int dV = 6; //set number of displayed decimal places
on Volt range
int dmV = 2; //set number of displayed decimal places
on MilliVolt range
int duV = 0; //set number of displayed decimal places
on MicroVolt range
//
***********************************************************************************
****************************
void setup() {
//
***********************************************************************************
****
void loop() {
int i;
long sum = 0;
for (i=0; i<(samples); i++) //loop to take sample readings
{
adcread = Spi_Read(); //read data from LTC2400 ADC
delay(ct); //allow ADC converstion time
sum += adcread; //sum equals running total
}
} else {
v = "V"; //if 1 volt or higher use letter V on
display after voltage reading
d = dV; //set display characters to show V
}
//*********************************************************************************
**************************************
long Spi_Read(void){ //SPI(Serial Peripheral Interface) read
sub-routine to read data form the LTC2400 ADC
//and transfer 8 bits (1 byte) at a time -
total of 4 bytes.
long result = 0; //result represents rolling total of the
bytes transferred
long b; //b is result of reading ADC output bytes
digitalWrite(LTC_CS, LOW); //LTC2400 chip select pin taken low to
allow data transfer from Adc
delayMicroseconds(1); //timing delay but may not be required
int i;
long sum = 0;
for (i=0; i<(samples); i++) //loop to take sample readings
{
adcread = Spi_Read(); //read data from LTC2400 ADC
delay(ct);
sum += adcread;
}
lcd.setCursor(0,0);
lcd.print("Adjust Factor");
lcd.setCursor(0,1);
lcd.print(cal);
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Millivolt Meter");
}
//
***********************************************************************************
***************************************