Hi!,
I am learning ADC with a butterfly trying to get a 10 bit value, but the max i can get is a reading of 187.
I have 3 volts supplied from one of the output pins wired to a 10k pot. With no load with a 10 bit value shouldn't my readings be close to 1024?
My max values of 180-190 are always stored in ADCL. I can't figure out how to read ADCH, i'm ashamed to admit that i've been trying all day. Someone?
:?
here is my modified stolen code:
void ADC_init(char input) { ADMUX = input; // external AREF and ADCx ADCSRA = (1<<ADEN) | (1<<ADPS1) | (1<<ADPS0); // Take a dummy reading , which basically allows the ADC // to hack up any hairballs before we take any real readings input = ADC_read(); } int ADC_read(void) { char i; int ADC_temp; int ADCr = 0; sbi(PORTF, PF3); // mt sbi(PORTF, PORTF3); // Enable the VCP (VC-peripheral) sbi(DDRF, DDF3); // sbi(DDRF, PORTF3); sbi(ADCSRA, ADEN); // Enable the ADC //do a dummy readout first ADCSRA |= (1<<ADSC); // do single conversion while(!(ADCSRA & 0x10)); // wait for conversion done, ADIF flag active for(i=0;i<40;i++) // do the ADC conversion 8 times for better accuracy { ADCSRA |= (1<<ADSC); // do single conversion while(!(ADCSRA & 0x10)); // wait for conversion done, ADIF flag active ADC_temp = ADCL; // read out ADCL register } cbi(PORTF,PF3); // mt cbi(PORTF, PORTF3); // disable the VCP cbi(DDRF,DDF3); // mt cbi(DDRF, PORTF3); cbi(ADCSRA, ADEN); // disable the ADC return ADC_temp; }
void getVolt1() { char voltintpart[]= {'0','0','0','\0'}; char voltfractpart[]= {'0','0','0','\0'}; int intpart = 0; int fractpart = 0; int ADCresult = 0; // int test = 65555; ADCresult = ADC_read(); itoa(ADCresult, voltintpart, 10); sendString("The reading is "); sendString(voltintpart); ADCresult=ADCH; itoa(ADCresult, voltintpart, 10); sendString("The reading is "); sendString(voltintpart); }