Home >Documents >MIKROKONTROLER ATMEGA BERBASIS CODEVISION AVR .pb5 pb6 pb7 pa0 pa1 pa2 pa3 pa4 pa5 pa6 pa7 pc0 pc1

MIKROKONTROLER ATMEGA BERBASIS CODEVISION AVR .pb5 pb6 pb7 pa0 pa1 pa2 pa3 pa4 pa5 pa6 pa7 pc0 pc1

Date post:16-Apr-2019
Category:
View:219 times
Download:0 times
Share this document with a friend
Transcript:

MIKROKONTROLER ATMEGA BERBASIS CODEVISION AVR

(ADC DAN APLIKASI TERMOMETER)

D E P O K I N S T R U M E N T S dins

ADC

Konsep Dasar ADC ADC = Analog to Digital Converter Pengubah sinyal analog menjadi sinyal digital (bit) Rumus dasar ADC:Data_ADC = (Vin/Vref)*(Maksimal_Data_Bit)

Vin = Tegangan analog input yang akan diubah ADC. Vref = Tegangan referensi yang dipakai oleh ADC sebagai

acuan pengubah.Maksimal_Data_Bit = Kemampuan maksimal data yang

dapat dihasilkan oleh ADC.

Fitur ADC C. ATmega16A

8 Kanal ADC: PORTA.0 = ADC(0); PORTA.1 = ADC(1); PORTA.2 = ADC(2); PORTA.3 = ADC(3); PORTA.4 = ADC(4); PORTA.5 = ADC(5); PORTA.6 = ADC(6); PORTA.7 = ADC(7);

Maksimal_Data_Bit = 10-bit = 0 1023 Vref ADC:

VCC VCC Aref

Vin ADC = 0V 5V

DI-Smart AVR.16 System(Sistem Plus C. ATmega16A)

Y111059200

C1

20pFC2

20pF

R1

1K

SW1RST

VCCX1

X2RST

RST

PB0PB1PB2PB3PB4PB5PB6PB7

PA0PA1PA2PA3PA4PA5PA6PA7

PD0PD1PD2PD3PD4PD5PD6PD7 PC0

PC1PC2PC3PC4PC5PC6PC7

X1X2

12345678910

P1PORTB

12345678910

P3PORTD

12345678910

P0PORTA

12345678910

P2PORTC

VCC

VCCVCC

VCC PB0PB1PB2PB3PB4PB5PB6PB7

PA0PA1PA2PA3PA4PA5PA6PA7

PC0PC1PC2PC3PC4PC5PC6PC7R1 IN

13R2 IN8T1 IN11

T2 IN10

GN

D15

V+

2

V-

6

VCC

16

R1 OUT 12R2 OUT 9T1 OUT 14

T2 OUT 7C1+1C1 -3

C2+ 4C2 - 5

U2

MAX232CPE

+

C91uF

+

C131uF

+

C111uF

+

C101uF

VCC

162738495

DB1SERIAL

+C4470uF

Vin1

GN

D2

+5V 3U0 LM7805CT

+ C510uF

+ C6100nF

C7100nF

VCCD14002

C3

100nf

R3

2K2L10POWER

VCC

VCC

11

23

W 2

VR1

10K

AREF

AREF

VCC

PD0PD1PD2PD3PD4PD5PD6PD7

AGND 31X113X212

RESET9

PD2 (INT0)16

PD3 (INT1)17PD4 (OC1B)18PD5 (OC1A)19

PB0 (T0)1

PB1 (T1)2PB2 (AIN0)3PB3 (AIN1)4

PB4 (SS)5

PB5 (MOSI)6PB6 (MISO)7

PB7 (SCK)8

PA0 (ADC0) 40

PA1 (ADC1) 39PA2 (ADC2) 38PA3 (ADC3) 37

PA4 (ADC4) 36

PA5 (ADC5) 35PA6 (ADC6) 34

PA7 (ADC7) 33

PC0 22PC1 23PC2 24PC3 25PC4 26PC5 27

(TOSC1) PC6 28(TOSC2) PC7 29

PD7 (OC2)21PD6 (ICP)20

AREF 32

AVCC 30

PD1 (TDX)15PD0 (RXD)14

IC1 AT MEGA

PB5

PB6PB7

VCC

LEDRST

1 23 45 67 89 10

P4ISP PROG

S2

PD2

S3

PD3

PD2

PD3

L8PC0

VCC

L7PC1

L6PC2

L5PC3

L4PC4

L3PC5

L2PC6

L1PC7

PC0

PC1

PC2

PC3

PC4

PC5

PC6

PC7

C17100nF

D0D1D2D3D4

D6D5

D7

D0

D1

D2

D3

D4

D6

D5

D7

PD0 PD1TXD SERIAL

TXD ISP

RXD SERIAL

RXD ISP

+ C121uF

123

JP1123

JP2

123456789

RP1

12

JP3LED CONNECTED

TXD ISPRXD ISP

TXD SERIAL

RXD SERIAL

POWER9-12VDC

1

2 34

56

7

8

9

DI-Smart AVR.16 System

1. ATmega16A2. Crystal3. Reset4. ISP5. Power6. Vref ADC7. RS2328. LED Array9. Push Button

1

2

34

56

8

7

9

PORTA=

ADC

Vref

Pemrograman ADC pada CVAVR

Inisialisasi WizardPemilihan VrefVCC VCCV@Aref

Pemilihan ClockAktivasi ADC

Pemrograman ADC Ditampilkan LCD (Setup Wizard)

1 3

4

2

Pemrograman ADC Ditampilkan LCD (Subprogram Hasil Wizard)

read_adc(channel)adalah subprogram untuk membaca data dari kanal adc. Dengan channel adalah 0 7.

Pemrograman ADC Ditampilkan LCD (Inisialisasi ADC Hasil Wizard)

Inisialisasi ADC sesuai dengan yang diinputkan saat Wizard.

Pemrograman ADC Ditampilkan LCD (Membaca dan Menampilkan ADC) [1/2]

#include

#include

#include

#include

#define ADC_VREF_TYPE 0x00

unsigned int read_adc(unsigned char adc_input)

{

ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);

delay_us(10);

ADCSRA|=0x40;

while ((ADCSRA & 0x10)==0);

ADCSRA|=0x10;

return ADCW;

}

Pemrograman ADC Ditampilkan LCD (Membaca dan Menampilkan ADC) [2/2]

unsigned char cstr[16];

unsigned int idata;

void main(void)

{

ADMUX=ADC_VREF_TYPE & 0xff; ADCSRA=0xA6; SFIOR&=0x1F;

lcd_init(16);

while (1) {

lcd_clear();

idata = read_adc(0); sprintf(cstr,"Data ADC: %04d",idata);

lcd_puts(cstr);

delay_ms(250);

}

}

Aplikasi ADC Termometer berbasis Sensor LM35DZ

LM35DZ adalah sensor temperatur analog ekonomis namun cukup baik dalam mengukur temperatur. Jangkauan: 0 100 oCSensitivitas: 10 mV/ oCOperasional: 4 30 V

Fungsi Transfer Sensor LM35DZ

Tinjau-ulang dasar ADC:Data_ADC = (Vin/Vref)*(Maksimal_Data_Bit)Data_ADC = Hasil konversi ADC internal ATmega16AVin = Tegangan LM35Vref = Sesuai pengaturan di Wizard CVAVR = 5VMaksimal_Data_Bit = 10 Bit = 1023

Sensitivitas LM35 = 10 mV/ oC Temperatur terukur (T):

T = (Vin/10 mV) oC T = ((Data_ADC*5V/1023)/10 mV) oC

Termometer berbasis Sensor LM35DZ(Skrip Program CVAVR) [1/3]

#include

#include

#include

#include

#define ADC_VREF_TYPE 0x00

unsigned int read_adc(unsigned char adc_input)

{

ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);

delay_us(10);

ADCSRA|=0x40;

while ((ADCSRA & 0x10)==0);

ADCSRA|=0x10;

return ADCW;

}

Termometer berbasis Sensor LM35DZ(Skrip Program CVAVR) [2/3]

unsigned char cstr[16], T; //T = Temperatur

unsigned int idata;

float fdata; //Nilai pecahan agar perhitungan baik.

void main(void)

{

ADMUX=ADC_VREF_TYPE & 0xff; ADCSRA=0xA6; SFIOR&=0x1F;

lcd_init(16);

while (1)

{

lcd_clear(); idata = read_adc(0);

sprintf(cstr,"Data ADC: %04d",idata);

lcd_puts(cstr);

Termometer berbasis Sensor LM35DZ(Skrip Program CVAVR) [3/3]

fdata = (((float)idata*5)/1023)/0.01;

T = (char)fdata;

sprintf(cstr,"Temperatur: %02d C",T);

lcd_gotoxy(0,1); lcd_puts(cstr);

delay_ms(250);

}

}

Click here to load reader

Embed Size (px)
Recommended