Hi,
would someone mind checking my code please? I'm having issues with my ADC and can't seem to get it to perform a conversion. I posted the ADC loops, can paste the rest of the code if someone wants.
/*--------------------------------------------------- Initialise the ADC. Single Conversion ---------------------------------------------------*/ void ADC_Init (void) { /*Ensure ADC is not powered down*/ PRR |= (0<<PRADC); /*Disable Digital Buffer on PinC 0 - 8*/ DIDR0 = 0b1111111; /*Voltage Reference selection: AVCC with external capacitor at AREF pin*/ ADMUX |= (0<<REFS1)|(1<<REFS0)|(1<<ADLAR); /*Set frequency scaler to 128*/ ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); } /*--------------------------------------------------- Starting the ADC Conversion Returns a float into an array. ---------------------------------------------------*/ uint16_t ReadADC(uint8_t ch) { //Select ADC Channel ch must be 0-7 ch=ch&0b00000111; ADMUX|=ch; //Start Single conversion ADCSRA|=(1<<ADSC)|(1<<ADEN); //Wait for conversion to complete while(!(ADCSRA & (1<<ADIF))); //Clear ADIF by writing one to it ADCSRA|=(1<<ADIF); return(ADCL); }
I am using a mega324P