Praktek 4 AVR Internal ADC
-
Upload
muhammad-rizani-rusli -
Category
Documents
-
view
6 -
download
3
description
Transcript of Praktek 4 AVR Internal ADC
Praktek 1
Praktek 4Internal ADC
Tujuan:
Mahasiswa mengerti cara melakukan pembacaan tegangan analog dengan menggunakan rangkaian Internal ADC yang terdapat dalam mikrokontroller AVR Mahasiswa mengerti cara membuat program C pada mikrokontroller AVR untuk pembacaan data internal ADC Mahasiswa dapat membuat program Visual Basic untuk digabungkan dengan mikrokontroller AVR yang sudah diprogram untuk melakukan komunikasi serial
Peralatan yang digunakan:
modul AVR Modul LED dan switch Kabel serial RS232 (cross)
Potensiometer
Deskripsi/ Dasar Teori:
Mikrokontroller AVR dilengakapi dengan rangkaian ADC dengan resolusi 10 bit (dari 0 sampai 210=1023). Terdiri dari 8 channel ADC, yang bisa dipakai secara bersamaan.
Gambar4.1. Setting Internal ADC (awal)
Gambar4.2. Setting Internal ADC (awal)
Gambar4.3. Setting percobaan pembacaan data ADCPERCOBAAN 1
Membaca data ADC 1 channel dan ditampilkan datanya ke LED 8 bit#include
#include
#define ADC_VREF_TYPE 0x20
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCH;
}
void main(void)
{
int a;
PORTA=0x00;
DDRA=0x00;
// ADC initialization
// ADC Clock frequency: 1000,000 kHz
// ADC Voltage Reference: AREF pin
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x83;
while (1)
{
a=read_adc(0);
PORTA=a;
}
}Hasil Output program
PERCOBAAN 2
#include
#include
// Alphanumeric LCD functions
#include
#define ADC_VREF_TYPE 0x20
// Read the 8 most significant bits
// of the AD conversion result
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCH;
}
void main(void)
{
int a,n,j;
PORTA=0x00;
DDRA=0xFF;
// ADC initialization
// ADC Clock frequency: 1000,000 kHz
// ADC Voltage Reference: AREF pin
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x83;
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTD Bit 0
// RD - PORTD Bit 1
// EN - PORTD Bit 2
// D4 - PORTD Bit 4
// D5 - PORTD Bit 5
// D6 - PORTD Bit 6
// D7 - PORTD Bit 7
// Characters/line: 16
lcd_init(16);
while (1)
{
a=read_adc(0);
n=a/(255/14);
lcd_clear();
lcd_putchar('E');
lcd_gotoxy(15,0);
lcd_putchar('F');
lcd_gotoxy(1,0);
for(j=1;j