ElectricShock 2016. 3. 11. 18:22


- AVCC : 아날로그 VCC가 연결되는 핀입니다.
- AREF : 아날로그 VCC의 기준 전압이 되는 핀입니다.
▼Datasheet에 나와있는 내용
AVCC : AVCC is the Analog Supply Voltage pin for Port F and the A/D Converter. 
It should be externally connected to VCC, even if the ADC is not used. 
If the ADC is used, it should be connected to VCC through a low-pass filter.
(Ranage : Vcc-0.3 ~ Vcc+0.3)


Link
The Atmega168 has 2 digital supply voltage pins, VCC and AVCC
AVCC supplies power to PC0-PC5. 
When these pins are used as analogue inputs, the AVCC power needs to be very stable.
This is achieved by using a low pass filter comprising of an inductor and capacitor.
(방금 위에서 언급했던 내용)

 
AREF : AREF is the analog reference pin for the A/D Converter.
(Aref = Vref)

AVCC, AREF를 함께 short시키고 Vcc로 묶어서 연결






//Program for ADC to read from channel 0 and show the 8 bit o/p on PORTB 
 
#include<avr/io.h>
#include<util/delay.h>
 
void ADC_init(void);
unsigned int ADC_read(unsigned char);
 
// ------------------------------------------------
int main(void)
{
unsigned int value;
DDRB=0xFF;                //포트B를 모두 출력으로 지정 (LED출력)
DDRD=0x03;                //0b00000011 으로 포트D의 0,1포트
ADC_init();             // Initialization of ADC
// ch=0;

while(1)
{
value=ADC_read(0);     //ADC0의 40번 핀을 ADC로 지정.......8비트resolution의 값
PORTB=value;                    //이값을 8비트의 LED출력으로 보낸다.
_delay_ms(500);
}
}
//------------------------------------------------
 
void ADC_init(void) // Initialization of ADC
{
ADMUX=(1<<REFS0); // AVcc with external capacitor at AREF
//ADMUX::REFS1 REFS0 ADLAR MUX4 MUX3 MUX2 MUX1 MUX0
//Vref is equal to AVcc
//ADC0 채널을 이용
ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
// Enable ADC and set Prescaler division factor as 128
//ADCSRA::ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0
//ADEN은 필수로 Set, 나머지 비트는 Prescale따라서 조정 (128이 최고치)
}
 
unsigned int ADC_read(unsigned char ch)
{
ch= ch & 0b00000111; // channel must be b/w 0 to 7
ADMUX |= ch; // selecting channel
     
ADCSRA|=(1<<ADSC); // start conversion
while(!(ADCSRA & (1<<ADIF))); // waiting for ADIF, conversion complete
ADCSRA|=(1<<ADIF); // clearing of ADIF, it is done by writing 1 to it
 
return (ADC);
}