hi all, i'm doing some testing of using attiny in comparing voltage. i want to use external voltage reference (AREF pin) at 1 volt. and when the adc result below 40 then it turn on a led, here is the code.
void initADC ()
{
ADMUX = 0;
ADMUX |= (1 << MUX1);
ADMUX |= (1 << REFS0);
_delay_ms(10);
ADCSRA =
(1 << ADEN) | // Enable ADC
(1 << ADATE) | // auto trigger enable
(1 << ADIE) | // enable ADC interrupt
(1 << ADPS0) | // Prescaler = 8
(1 << ADPS1); // - 125KHz with 1MHz clock
ADCSRB = 0; // free running mode
sei();
ADCSRA |= (1 << ADSC); // start conversions
}
ISR(ADC_vect)
{
static uint16_t val;
uint8_t low = ADCL; // must read ADCL first - it then locks ADCH
uint8_t high = ADCH; // unlocks both
uint16_t result = (high<<8) | low;
if((result < 40 )){
PORTB |= (1<<PB3);
}else{
PORTB &= ~(1<<PB3);
}
}
when i test it, something strange happen, when the reference voltage is 1V the led not responding to any given input voltage (even the input is connected to ground, the result always bigger than 40 i assume) but if i change the reference voltage to about 1.6 V or above the adc is start responding to input voltage (when i give 0v input then led is turn on). so my question is, is why reference voltage below 1.6 V is not working, is there something that i miss when using attiny85??? please help me
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.