# Problem with ADC configuration - atmega328p

What's up folks?

I've been developing a project using atmega328p and avr-gcc. Recently, I've tried to configure the ADC to single sample. The codes below show my main.c, ADC.c and ADC.h

//main.c

#include <avr/io.h>
#include <stdint.h>
#include <avr/sleep.h>

volatile int timer_counter = 0; //value of timer_counter
volatile uint8_t converteu;

int main (void){
CLKPR = (1<<CLKPCE); // enabling bit writing in clock divider
CLKPR = 2; //clock divider = 4, from 8 MHz to 2 MHZ
configure_ADC(); // clock = 62.5 KHz, AREF = AVCC, single sample

DDRB = 7; // PB0, PB1, PB2 as output

while(1){
sei();
set_sleep_mode(SLEEP_MODE_IDLE);
sleep_mode();
}
}

//ADC.c

#include<avr/io.h>
#include<avr/interrupt.h>

PORTB ^= 2;
}

ADMUX |= (1<<REFS0); //short circuiting AVCC with AREF, ADC0 is the port enable to be read

PRR &= ~PRADC; // no low power on ADC
}


//ADC.h


These code should do nothing, just configure ADC to run in single sample. However when I run it in my microcontroller, without activating ADSC (bit that starts a conversion), the PORTB 2 is activated. The only place that enables PORTB 2 is in the ADC's ISR.

The ISR is executed without activating the ADSC bit.

What's happening with this code?

• What does PORTB gets activated mean? Feb 9 '20 at 4:41
• "These code should do nothing, just configure ADC to run in single sample." - but the comment says "auto triggering enabled, trigger_event = free running"! Feb 9 '20 at 7:24
• The free running comment is a past configuration that I tried. I forgot to erase it. I will edit the question. Feb 9 '20 at 12:40
• @User323693 PORTB gets activated means that a logic one is written on the pin. Feb 9 '20 at 12:42
• What is teh default state of the pin? If you comment that port B Part in ADC ISR wil it still behave the same? Feb 9 '20 at 16:30