Posted by : Niam Tamami January 22, 2011

 I. Latar Belakang

  1. Ketidakmampuan manusia untuk menjangkau tempat-tempat tertentu, misal : gedung yang terbakar.
  2. Keselamatan manusia lebih terjamin dengan digantikannya tugas manusia dengan robot.

II. Pheriperal
  • Driver Motor DC 6V / L293D / L289
  • Infrared Receive Sensor tipe 538AA51 (gnd-vcc-data) / Infrared Receive 38 kHz lain
  • Remote TV SONY
  • LM35 & LDR (Pengukur Suhu dan Intensitas Ruangan)
  • Minimum System ATMega16

III. Fitur AVR yang Digunakan
  • INT External Falling Edge
  • Sleep Mode
  • Timer 8 bit

IV. Sistem Kerja
Sinyal yang dipancarkan oleh Remote TV Sony mengirimkan sinyal dengan Protokol SIRC
Kemudian Data Sinyal ditangkap oleh receiver infrared dan uControler menerima data dalam bentuk sinyal berikut dan diolah oleh INT0 uControler

Dari data yang diterima uControler di atas, maka dapat disusun algoritma saat ada interupt falling edge, timer2 menghitung berapa lama waktu yang dibutuhkan hingga interupt falling edge selanjutnya.Tanda byte start adalah memiliki panjang waktu 3000uS, logika "1" = 1800uS, logika "0" = 1200uS.Berikut hitungan timer yang digunakan
Panjang interupt max saat start bit = 3000uS
Rumus : Periode = TCNT2 / frek.timer
Dipilih : Mode timer 2, 8bit, Normal
:frekuensi timer = 43200 Hz
Maka : startbit =3000 uS = 130H
logic 1 =1800 uS = 78H
logic 0 =1200 uS = 52H

Karena sinyal remote tidak selalu presisi maka dibuat range nilai tiap data interupt, hal ini dipengaruhi oleh kondisi baterai,dll.
Untuk memberikan perintah pada robot, digunakan data remote yang telah diolah oleh interupt. Data remote merupakan data bilangan 12 bit.Gambar di bawah ini menjelaskan hubungan angka yang ditekan dengan data remote yang dihasilkan :
Tombol Power (95H) digunakan sebagai pengaktif powerdown pada AVR,dimana seluruh aktifitas uControler berhenti.bila diinginkan agar AVR kembali bekerja, maka harus menggunakan tombol reset Tombol 1 (80H) mengambil data sensor suhu dan cahaya Tombol 2 (81H) maju Tombol 4 (83H) belok kiri Tombol 5 (84H) stop Tombol 6 (85H) belok kanan Tombol 8 (87H) mundur Tombol 0 (89H) modus idle, AVR menghemat daya dengan memperkecil arus output.agar normal kembali,dapat dipicu dengan interupt external,wdr,reset eksternal




VII. Listing Program
/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.4 Standard
Automatic Program Generator
© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 1/4/2002
Author :
Company :
Comments:

Chip type : ATmega16
Program type : Application
Clock frequency : 11.059200 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega16.h>
#include <delay.h>
#include <stdio.h>
#include <sleep.h>
#define indikator PORTB
#define menu PINB.6
#define ok PINB.7
#define remka PORTC.7
#define kanan PORTC.6
#define enka PORTC.5
#define enki PORTC.4
#define kiri PORTC.3
#define remki PORTC.2
unsigned char lpwm,rpwm,xcount,periode,awal,temp1,temp2;
int data_remote;
eeprom unsigned char suhu,cahaya,vref;
eeprom float konversisuhu;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here
periode=TCNT2;
TCCR2=0x00;
awal++;
if (awal ==1) { }
else
{
if (awal ==2)
{
if ((periode >= 119) & (periode <= 139) ) {} //start bit sesuai
else // start bit tidak sesuai
{
awal = 0;
}
}
else //awal sudah >1 dan start bit sudah cocok
{
if ((periode >= 45) & (periode <= 60)) // data bit 0
{
data_remote = data_remote >> 1;
data_remote = data_remote & 0x07FF;
}
if ((periode >= 65) & (periode <= 87)) // data bit 1
{
data_remote = data_remote >> 1;
data_remote = data_remote | 0x0800;
}
}
}
if (awal == 14)
{
data_remote=data_remote >> 1;
awal=0; //jika tombol selain power dan 0, 'awal' direset kembali
}
TCNT2=0x00;
TCCR2=0x06;
}

// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Place your code here
xcount++;
if(xcount<=lpwm)enki=0;
else enki=1;
if(xcount<=rpwm)enka=0;
else enka=1;
}
#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 sukses()
{
suhu = read_adc(0);
cahaya = read_adc(1);
vref = read_adc(2);
if((cahaya ==0)||(cahaya ==255)||(suhu ==0)||(suhu ==255))
{
PORTB = 0b00001100;
delay_ms(500);
PORTB = 255;
delay_ms(500);
}
else
{
PORTB = 255;
delay_ms(500);
PORTB = 0;
delay_ms(500);
PORTB = 255;
delay_ms(500);
}
}
// Declare your global variables here
void maju(unsigned char pwm_kiri, unsigned char pwm_kanan)
{ kanan=0; kiri=0; remka=1; remki=1; lpwm=pwm_kiri; rpwm=pwm_kanan;}
void mundur(unsigned char pwm_kiri, unsigned char pwm_kanan)
{ kanan=1; kiri=1; remka=1; remki=1; lpwm=pwm_kiri; rpwm=pwm_kanan;}
void berhenti()
{remka=0; remki=0;}
/*
void belki(unsigned char pwm_kiri, unsigned char pwm_kanan)
{ kanan=0; kiri=1; remka=1; remki=1; lpwm=pwm_kiri; rpwm=pwm_kanan;}
void belka(unsigned char pwm_kiri, unsigned char pwm_kanan)
{ kanan=1; kiri=0; remki=1; remka=1; lpwm=pwm_kiri; rpwm=pwm_kanan;}
void stop()
{remka=0; remki=0;}

void parkir()
{ while(1){stop();}}
*/
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A 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
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=P State6=P State5=1 State4=1 State3=1 State2=1 State1=1 State0=1
PORTB=0xFF;
DDRB=0x3F;
// Port C initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=In Func0=In
// State7=1 State6=1 State5=1 State4=1 State3=1 State2=1 State1=T State0=T
PORTC=0xFC;
DDRC=0xFC;
// 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;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 10.800 kHz
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x01;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B 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
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: 43.200 kHz
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x06;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Falling Edge
// INT1: Off
// INT2: Off
GICR|=0x40;
MCUCR=0x02;
MCUCSR=0x00;
GIFR=0x40;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x01;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: Off
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x08;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x47;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 691.200 kHz
// ADC Voltage Reference: AREF pin
// ADC Auto Trigger Source: None
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;
sleep_enable();
// Global enable interrupts
#asm("sei")
while (1)
{
// Place your code here

switch (data_remote)
{
case 0x0095 :
powerdown();
break;
case 0x0089 :
berhenti();
idle();
break;
case 0x0080 :
sukses();
break;
case 0x0081 :
maju(255,200);
break;
case 0x0082 :
break;
case 0x0083 :
maju(50,255);
break;
case 0x0084 :
berhenti();
break;
case 0x0085 :
maju(255,50);
break;
case 0x0087 :
mundur(255,255);
break;
};
temp1 = suhu;
temp2 = cahaya;
printf("\r suhu=%d cahaya=%d ",temp1,temp2);
};
}
Download SourceCode

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Entri Populer

tweet

- Copyright © 2013 blog.nitbot.com -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -