30
  LAPORAN JOBSHEET 05 MATA KULIAH MIKROKONTROLER INTERFACING Timer dan Counter  NAMA : MoH Lutfi Andrian  NIM : 4.35.11.0.14 PROGRAM STUDI D4 TEKNIK TELEKOMUNIKASI POLITEKNIK NEGERI SEMARANG 2013

Laporan job 5_Moh. Lutfi Andrian

  • Upload
    andrew

  • View
    37

  • Download
    0

Embed Size (px)

DESCRIPTION

mikrokontroler and interfacing

Citation preview

  • LAPORAN JOBSHEET 05

    MATA KULIAH MIKROKONTROLER INTERFACING

    Timer dan Counter

    NAMA : MoH Lutfi Andrian

    NIM : 4.35.11.0.14

    PROGRAM STUDI D4 TEKNIK TELEKOMUNIKASI

    POLITEKNIK NEGERI SEMARANG

    2013

  • MODUL V: Timer dan Counter

    5.1 DASAR TEORI

    Gambar 5.1 Prinsip Dasar Timer/Counter pada Mikrokontroler

    Ttimer = Tosc*(256-TCNT0)*N (8 bit = 256)

    Ttimer = Tosc*(65536-TCNT1)*N (16 bit = 65536)

    Gambar 5.2 Diagram Blok Timer/Counter pada Mikrokontroler keluarga AVR

  • 5.2 TIMER SEDERHANA MENGGUNAKAN FASILITAS delay.h

    A. Langkah kerja

    1. Buat program sebagai berikut:

    #include #include void main(void) { // Declare your local variables here PORTC=0x00; DDRC=0xFF; PORTC.0=0; PORTC.1=0; PORTC.2=0; PORTC.3=0; while (1) { char c2; // Place your code here PORTC.1=~PORTC.1; for(c2 = 0; c2 < 10; c2++) { PORTC.0=~PORTC.0; delay_ms(10); }; } } 2. Compile dan make program anda.

    3. Buat desain proteus sebagaimana Gambar 5.3

  • Gambar 5.3 Skema Desain Proteus untuk Percobaan 5.2

    Isi dari perhitungan step 1

    4. Perhatikan tampilan osciloscop virtual. Hitung perioda dari masing-masing

    gelombang kotak.

    B. TUGAS 5.1:

    Modifikasi program pada subbab 5.2 diatas untuk menghasilkan gelombang kotak

    dengan spesifikasi sebagai berikut:

    PORTC.0 => T = 100ms; PORTC.1 => T = 300ms; PORTC.2 => T = 600ms;

    PORTC.4 => T = 1200ms.

    #include #include void main(void) { // Declare your local variables here PORTC=0x00; DDRC=0xFF; PORTC.0=0; PORTC.1=0; PORTC.2=0; PORTC.3=0; while (1) { char c2,c3,c4; // Place your code here PORTC.3=~PORTC.3;

  • for (c4=0;c4
  • 4. Edit program hasil generate sebagai berikut :

    interrupt [TIM1_OVF] void timer1_ovf_isr(void)

    { // Place your code here TCNT1H=0xYYYY >> 8; //YYYY=nilai hex hasil perhitungan TCNT1L=0xYYYY & 0xff; PORTC.0=~PORTC.0; } TCCR1B=0x05; PORTC.0=0; while (1) { // Place your code here }; } 5. Compile dan make program anda.

  • 6. Jalankan program anda pada desain Gambar 5.3

    7. Amati dan hitung periode sinyal pada Osciloscop virtual

    B. TUGAS 5.2 :

    Ulangi Tugas 5.1 dengan menggunakan timer internal.

    #include

    int loop1,loop2,loop3;

    // Timer 1 overflow interrupt service routine

    interrupt [TIM1_OVF] void timer1_ovf_isr(void)

    { // Place your code here TCNT1H=0xFBC8 >> 8; //FBC8 => 0.1 detik; D5D0 => 1 detik TCNT1L=0xFBC8 & 0xff; loop1++; PORTC.0=~PORTC.0; if (loop1>=3) { loop2++; loop1=0; PORTC.1=~PORTC.1; if (loop2>=2) { loop3++; loop2=0; PORTC.2=~PORTC.2; if (loop3>=2) { loop3=0; PORTC.3=~PORTC.3; } } } } // Declare your global variables here

  • void main(void) { // Declare your local variables here // Input/Output Ports initialization // Port A initialization // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 PORTA=0x00; DDRA=0xFF; // Port B initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTB=0x00; DDRB=0x00; // Port C initialization // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 PORTC=0x00; DDRC=0xFF; // Port D initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTD=0x00; DDRD=0x00; // Port E initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTE=0x00; DDRE=0x00; // Port F initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTF=0x00; DDRF=0x00; // Port G initialization // Func4=In Func3=In Func2=In Func1=In Func0=In // State4=T State3=T State2=T State1=T State0=T PORTG=0x00; DDRG=0x00; // Timer/Counter 0 initialization

  • // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: Normal top=FFh // OC0 output: Disconnected ASSR=0x00; TCCR0=0x00; TCNT0=0x00; OCR0=0x00; // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: 11059.200 kHz // Mode: Normal top=FFFFh // OC1A output: Discon. // OC1B output: Discon. // OC1C output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge // Timer 1 Overflow Interrupt: On // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off // Compare C Match Interrupt: Off TCCR1A=0x00; TCCR1B=0x05; // prescaler = 1024 TCNT1H=0xFB; //FBC8 => 0.1 detik; D5D0 => 1 detik TCNT1L=0xC8; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; OCR1CH=0x00; OCR1CL=0x00; // Timer/Counter 2 initialization // Clock source: System Clock // Clock value: Timer 2 Stopped // Mode: Normal top=FFh // OC2 output: Disconnected TCCR2=0x00; TCNT2=0x00; OCR2=0x00; // Timer/Counter 3 initialization // Clock source: System Clock // Clock value: Timer 3 Stopped

  • // Mode: Normal top=FFFFh // Noise Canceler: Off // Input Capture on Falling Edge // OC3A output: Discon. // OC3B output: Discon. // OC3C output: Discon. // Timer 3 Overflow Interrupt: Off // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off // Compare C Match Interrupt: Off TCCR3A=0x00; TCCR3B=0x05; //precsaler = 1024 TCNT3H=0x00; TCNT3L=0x00; ICR3H=0x00; ICR3L=0x00; OCR3AH=0x00; OCR3AL=0x00; OCR3BH=0x00; OCR3BL=0x00; OCR3CH=0x00; OCR3CL=0x00; // External Interrupt(s) initialization // INT0: Off // INT1: Off // INT2: Off // INT3: Off // INT4: Off // INT5: Off // INT6: Off // INT7: Off EICRA=0x00; EICRB=0x00; EIMSK=0x00; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x04; ETIMSK=0x00; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00; PORTC.0=0; PORTC.1=0;

  • PORTC.2=0; PORTC.3=0; loop1=0; loop2=0; loop3=0; // Global enable interrupts #asm("sei") while (1) { // Place your code here }; }

    C. TUGAS 5.3 :

    Program Jam Digital menggunakan Timer pada LCD.

    #include #include // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x1b //PORTC #endasm #include int loop1,loop2,loop3; unsigned char buffer1[16]; unsigned char buffer2[16]; // Timer 1 overflow interrupt service routine interrupt [TIM1_OVF] void timer1_ovf_isr(void) { // Place your code here TCNT1H=0xD5D0 >> 8; //FBC8 => 0.1 detik; D5D0 => 1 detik TCNT1L=0xD5D0 & 0xff; loop1++; if (loop1>=60) { loop2++; loop1=0; if (loop2>=60) { loop3++; loop2=0; if (loop3>=24) {

  • loop3=0; } } } } // Declare your global variables here void main(void) { // Declare your local variables here // Input/Output Ports initialization // Port A initialization // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 PORTA=0x00; DDRA=0xFF; // Port B initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTB=0x00; DDRB=0x00; // Port C initialization // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 PORTC=0x00; DDRC=0xFF; // Port D initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTD=0x00; DDRD=0x00; // Port E initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTE=0x00; DDRE=0x00; // Port F initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTF=0x00;

  • DDRF=0x00; // Port G initialization // Func4=In Func3=In Func2=In Func1=In Func0=In // State4=T State3=T State2=T State1=T State0=T PORTG=0x00; DDRG=0x00; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: Normal top=FFh // OC0 output: Disconnected ASSR=0x00; TCCR0=0x00; TCNT0=0x00; OCR0=0x00; // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: 11059.200 kHz // Mode: Normal top=FFFFh // OC1A output: Discon. // OC1B output: Discon. // OC1C output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge // Timer 1 Overflow Interrupt: On // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off // Compare C Match Interrupt: Off TCCR1A=0x00; TCCR1B=0x05; // prescaler = 1024 TCNT1H=0xD5; //FBC8 => 0.1 detik; D5D0 => 1 detik TCNT1L=0xD0; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; OCR1CH=0x00; OCR1CL=0x00; // Timer/Counter 2 initialization // Clock source: System Clock // Clock value: Timer 2 Stopped

  • // Mode: Normal top=FFh // OC2 output: Disconnected TCCR2=0x00; TCNT2=0x00; OCR2=0x00; // Timer/Counter 3 initialization // Clock source: System Clock // Clock value: Timer 3 Stopped // Mode: Normal top=FFFFh // Noise Canceler: Off // Input Capture on Falling Edge // OC3A output: Discon. // OC3B output: Discon. // OC3C output: Discon. // Timer 3 Overflow Interrupt: Off // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off // Compare C Match Interrupt: Off TCCR3A=0x00; TCCR3B=0x05; //precsaler = 1024 TCNT3H=0x00; TCNT3L=0x00; ICR3H=0x00; ICR3L=0x00; OCR3AH=0x00; OCR3AL=0x00; OCR3BH=0x00; OCR3BL=0x00; OCR3CH=0x00; OCR3CL=0x00; // External Interrupt(s) initialization // INT0: Off // INT1: Off // INT2: Off // INT3: Off // INT4: Off // INT5: Off // INT6: Off // INT7: Off EICRA=0x00; EICRB=0x00; EIMSK=0x00; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x04;

  • ETIMSK=0x00; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00; loop1=0; loop2=0; loop3=0; lcd_init(16); lcd_clear(); // Global enable interrupts #asm("sei") while (1) { // Place your code here sprintf(buffer1,"Jam: %2d:%2d:%2d ",loop3,loop2,loop1); sprintf(buffer2,"POLINES"); lcd_gotoxy(0,0); lcd_puts(buffer1); lcd_gotoxy(0,1); lcd_puts(buffer2); }; }

    5.4 COUNTER MENGGUNAKAN TIMER/COUNTER INTERNAL

    A. Langkah kerja

  • Gambar 5.4 Skema Desain Proteus untuk Percobaan 5.4

    1. Buat project baru dengan program sebagai berikut.

    #include #include // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x1B ;PORTA #endasm #include // Declare your global variables here unsigned char temp[6]; int data; void main(void) { // Timer/Counter 2 initialization // Clock source: T2 pin Falling Edge // Clock value: Timer 2 Stopped // Mode: Normal top=FFh // OC2 output: Disconnected TCCR2=0x06; TCNT2=0x00; OCR2=0x00; // LCD module initialization lcd_init(16); while (1) { // Place your code here data=TCNT2;//hasil counter (TCNT0) dipindah ke data if (data>=256) { lcd_clear(); } lcd_gotoxy(0,0); lcd_putsf("ElectrO-Polines"); itoa(data,temp); //menampilkan di LCD lcd_gotoxy(0,1); lcd_puts(temp); }; } 2. Jalankan program pada desain Gambar 5.4

    3. Tekan tombol berulang-ulang. Jika program anda benar maka nilai pada LCD

    bertambah 1 setiap tombol ditekan sekali.

  • 4. Buat program berikut

    #include #include // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x1B ;PORTA #endasm #include // Declare your global variables here unsigned char temp[6]; unsigned int data; void main(void) { TCCR1A=0x00; TCCR1B=0x06; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; OCR1CH=0x00; OCR1CL=0x00; // LCD module initialization lcd_init(16); while (1) { // Place your code here data=TCNT1;//hasil counter (TCNT0) dipindah ke data if (data>=0xFFFF) { lcd_clear(); } lcd_gotoxy(0,0); lcd_putsf("ElectrO-Polines"); itoa(data,temp); //menampilkan di LCD lcd_gotoxy(0,1); lcd_puts(temp); }; } 5. Jalankan program anda pada design gambar 5.4

    6. Atur parameter signal Generator sebagaimana Gambar 5.5

  • Gambar 5.5 Pengaturan signal generator

    1. Putar-putar dengan pelan tombol centre

    2. Lihat perubahan pada Osciloscop. Perhatikan perubahan pada LCD

    B. TUGAS 5.4 :

    Gabungkan kedua program pada percobaan 5.5 dalam 1 program (baris atas LCD

    menampilkan hitungan dari tombol, sdangkan baris bawah LCD untuk

    penghitungan pulsa)

    #include #include #include // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x1B ;PORTA #endasm #include // Declare your global variables here unsigned char buffer1[16],buffer2[16]; unsigned int data1,data2; void main(void) { TCCR1A=0x00; TCCR1B=0x06; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00;

  • OCR1BL=0x00; OCR1CH=0x00; OCR1CL=0x00; // Timer/Counter 2 initialization // Clock source: T2 pin Falling Edge // Clock value: Timer 2 Stopped // Mode: Normal top=FFh // OC2 output: Disconnected TCCR2=0x06; TCNT2=0x00; OCR2=0x00; // LCD module initialization lcd_init(16); while (1) { // Place your code here data1=TCNT1;//hasil counter (TCNT0) dipindah ke data data2=TCNT2; if (data1>=0xFFFF) { lcd_clear(); } if (data2>=0xFF) { lcd_clear(); } sprintf(buffer1,"Pulsa: %d ",data1); sprintf(buffer2,"Tombol: %d ",data2); lcd_gotoxy(0,0); lcd_puts(buffer1); lcd_gotoxy(0,1); lcd_puts(buffer2); }; }

    5.5 FREQUENCY COUNTER (KOMBINASI TIMER & COUNTER)

    A. Langkah kerja

  • Gambar 5.6 Skema Desain Proteus untuk Percobaan 5.5

    1. Persiapkan program dan project baru pada CVAVR dengan konfigurasi sebagai

    berikut:

    Chip

    Chip: ATMega

    128

    Clock: 11.0592

    MHz

    LCD

    LCD Port: Port

    A

    Chars./line: 16

    Timer 1

    Clock Source:

    T1 pin Falling Edge

    Interrupt: Non

    Active

  • Timer 3

    Clock Source:

    system Clock

    Clock Value:

    10.800 kHz

    Interrupt: Active

    2. Edit program hasil generate CVAVRWizard pada beberapa bagian sehingga

    dihasilkan program sebagai berikut.

    #include // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x1B ;PORTA #endasm #include #include // OC3C output: Discon. // Timer 3 Overflow Interrupt: On // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off // Compare C Match Interrupt: Off TCCR3A=0x00; TCCR3B=0x05; TCNT3H=0xD5; //D5D0 TCNT3L=0xD0; ICR3H=0x00; ICR3L=0x00; OCR3AH=0x00; OCR3AL=0x00; OCR3BH=0x00; OCR3BL=0x00; OCR3CH=0x00; OCR3CL=0x00; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x00;

  • ETIMSK=0x04; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00; // LCD module initialization lcd_init(16); // Global enable interrupts #asm("sei") while (1) { // Place your code here // Place your code here //data=TCNT1;//hasil counter (TCNT0) dipindah ke data if (data>=0xFFFF) { lcd_clear(); } lcd_gotoxy(0,0); sprintf(buffer,"frek.:%5d Hz",data); lcd_puts(buffer); // display data on LCD }; } 3. Jalankan program anda pada design gambar 5.6

    4. Atur parameter signal Generator sebagaimana Gambar 5.7

    Gambar 5.5 Pengaturan signal generator

    5. Putar-putar dengan pelan tombol centre.

    6. Lihat perubahan tampilan pada LCD, bandingkan dengan nilai pada VSM Generator.

    B. TUGAS 5.5 :

    Modifikasi program pada contoh dimana baris kedua LCD menampilkan

    frekuensi dalam KHz.

  • #include // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x1B ;PORTA #endasm #include #include #include // Declare your global variables here unsigned char buffer[16]; float data; // Timer 3 overflow interrupt service routine interrupt [TIM3_OVF] void timer3_ovf_isr(void) { // Place your code here TCNT3H=0xD5D0 >> 8; //FBC8 => 0.1 detik; D5D0 => 1 detik TCNT3L=0xD5D0 & 0xff; data=TCNT1; TCNT1H=0x00; TCNT1L=0x00; } void main(void) { // Timer/Counter 1 initialization // Clock source: T1 pin Falling Edge // Mode: Normal top=FFFFh // OC1A output: Discon. // OC1B output: Discon. // OC1C output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge // Timer 1 Overflow Interrupt: Off // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off // Compare C Match Interrupt: Off TCCR1A=0x00; TCCR1B=0x06; TCNT1H=0x00; //D5D0 TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; OCR1CH=0x00; OCR1CL=0x00;

  • // Timer/Counter 3 initialization // Clock source: System Clock // Clock value: 10.800 kHz // Mode: Normal top=FFFFh // Noise Canceler: Off // Input Capture on Falling Edge // OC3A output: Discon. // OC3B output: Discon. // OC3C output: Discon. // Timer 3 Overflow Interrupt: On // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off // Compare C Match Interrupt: Off TCCR3A=0x00; TCCR3B=0x05; TCNT3H=0xD5; //D5D0 TCNT3L=0xD0; ICR3H=0x00; ICR3L=0x00; OCR3AH=0x00; OCR3AL=0x00; OCR3BH=0x00; OCR3BL=0x00; OCR3CH=0x00; OCR3CL=0x00; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x00; ETIMSK=0x04; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00; // LCD module initialization lcd_init(16); // Global enable interrupts #asm("sei") while (1) { // Place your code here // Place your code here //data=TCNT1;//hasil counter (TCNT0) dipindah ke data if (data>=0xFFFF) { lcd_clear(); }

  • lcd_gotoxy(0,0); sprintf(buffer,"frek.:%.2f Hz",data); lcd_puts(buffer); // display data on LCD lcd_gotoxy(0,1); sprintf(buffer,"frek.:%.2f kHz",data/1000); lcd_puts(buffer); // display data on LCD }; }

    B. TUGAS 5.6 :

    Buat program simulasi TACHO-METER (RPM Meter).

    II.Hasil Percobaan

    Percobaan 5.1

    Tugas 5.1

  • Percobaan 5.2

    Tugas 5.3

  • Tugas 5.4

    Percobaan 5.5

  • Tugas 5.5

  • III. Analisa

    Untuk menghitung waktu / timer pada praktikum diatas konsepnya adalah dalam waktu

    10 ms menghasilkan jumlah pulsa tiap satuan waktu, dengan cara mengaktifkan timer

    yang sudah disediakan AVR

    Timer 0:8 bit

    Timer 1:16 bit misal kita akan memilih sebagai counter

    Timer 2 :8 bit

    Timer 3: 16bit misal kita akan memilih sebagai timer

    Untuk menghitung pulsa frequensi yang dihasilkan tiap satuan waktu dengan

    menggunakan konsep overflow yaitu ketika perhitungan waktu timer sampai dengan FF

    maka akan menghitung mulai dari 0 lagisetelah itu data akan ditampilkan misal dalam

    LCD ,oschiloscope untuk melihat bentuk sinyalnya atau output yang lainnya.

    Untuk pengambilan datanya jika digunakan metode internal terlebih dahulu harus di

    hitung TCNT dengan rumus :

    Ttimer = Tosc*(256-TCNT0)*N (8 bit = 256)

    Ttimer = Tosc*(65536-TCNT1)*N (16 bit = 65536)

    Disini misalnya menghitung dari data TCNT 3 hasilnya dinyatakan dalam Hexa adalah

    D5D0 maka untuk overflow ,namun tidak dapat mengerjakan interrupt jika nilai TCNTx

    belum tentu FF,clock sourcnya untuk internal menggunakan system clock sumbernya

    internal dari system timer ,jika falling edge sumbernyadari luar counter ,misal

    perhitungannya yang dihasilkan:

    TCNT3=D5D0

    Data=TCNT1

    TCNT1=00

  • Maksudnya diatas untuk dapat mengambil data maka data di sama dengankan TCNT1

    dan TCNT1 disamadengankan 00 untuk overflow sebelum di nolkan ,selain untuk

    menghitung frequensi dapat diaplikasikan juga untuk menghitung putaran per menit (rpm)

    pada sensor octocoupler untuk menghitung tegangan dari arus yang dilewatkan .