Hi, I'm trying to use ADC without AnalogRead() function.
I look into documentation and write a code which is not working and i don't know why. ;/
I selected Analog In number 2:
ADMUX=_BV(MUX1);
And i set ADC ENABLE, ADC AUTO TRIGGER ENABLE, ADC START CONVERSION and prescaler:
ADCSRA = _BV(ADEN)|_BV(ADATE)|_BV(ADSC)|_BV(ADPS2);
I'm getting all the time 5.00 value...
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#define VREF 5
volatile float result;
volatile uint8_t counter;
//volatile float measure1,measure2;
void init_adc(void)
{
ADMUX=_BV(MUX1);
ADCSRA = _BV(ADEN)|_BV(ADATE)|_BV(ADSC)|_BV(ADPS2);
}
void setup()
{
init_adc();
Serial.begin(9600);
}
void loop()
{
result=(float)(ADCL | ADCH<<8)/1024*VREF;
delay(1000);
Serial.print("Analog 2 = " );
Serial.println(result );
}
Can anybody help?