Hi There. The attached c-code is working. However, the order in which the results are displayed is wrong.
ADC1 and SDC2 are swapped.
Please assist.
Regards
Francois
//2 channel 8bit adc
#include <avr/io.h>
#include <avr/interrupt.h>
int analogResult = 0;//variable to store ADC value
int analogResult1 = 0;
float VCC = 5.025;//measured with DMM.
void setup() {
// put your setup code here, to run once:
DDRC &=~(1<<DDC1);//ADC1 as input
Serial.begin(9600);
ADMUX |=(1<<REFS0);//|(1<<MUX0);//Vcc as ref and and adc 1
ADMUX |=(1<<ADLAR); //left adj
ADCSRA |=(1<<ADEN)|(1<<ADATE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);//(1<<ADSC)|
ADCSRB &=~(1<<ADTS2)|(1<<ADTS1)|(1<<ADTS0); //set free running mode
DIDR0 = 0x07;
}
void loop() {
// put your main code here, to run repeatedly:
ADMUX = 0x61; //display ch1
ADCSRA |= (1 << ADSC); //start single conversion
while(!(ADCSRA & (1<<ADIF))); //Wait for conversion to complete. this flag is set when adc conversion completes
ADCSRA|=(1<<ADIF); //Clear ADIF by writing one to it. Set bit to 1 to clear flag
analogResult =ADCH;//<<8)|(ADCL);//get 10bit result
Serial.print("analogData: "); //print "analogData: “Serial.print(analogResult); //print data in analogData variable
Serial.print(” ");
float volt = (analogResult/255.0)*VCC;
Serial.print(volt);
//delay(500);
//ADCSRA |= (1 << ADSC); //start single conversion
ADMUX = 0x62;//display ch2
ADCSRA |= (1 << ADSC); //start single conversion
while(!(ADCSRA & (1<<ADIF))); //Wait for conversion to complete. this flag is set when adc conversion completes
ADCSRA|=(1<<ADIF); //Clear ADIF by writing one to it. Set bit to 1 to clear flag
analogResult1 =ADCH;//<<8)|(ADCL);//get 10bit result
Serial.print(" ");
Serial.print("analogData: "); //print "analogData: “Serial.print(analogResult); //print data in analogData variable
Serial.print(” ");
float volt1 = (analogResult1/255.0)*VCC;
Serial.println(volt1);
delay(500);
//ADCSRA |= (1 << ADSC); //start single conversion
}