Translate

Mengakses Modul Sensor Warna TCS3200 Menggunakan Code Vision AVR ( CV AVR )

Mengakses Modul Sensor Warna TCS3200 Menggunakan Code Vision AVR ( CV AVR )


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara mengakses sensor warna TCS3200 menggunakan code vision AVR. Alat ini fungsi utamanya yaitu untuk mendeteksi warna, baik itu warna primer maupun sekunder berdasarkan pantulan. mikrokontroller yang digunakan adalah ATMega16 dan port yang digunakan adalah PORTA. untuk lebih jelasnya berikut adalah skema dan programnya.



a. Minimum System ATMega





b. Sensor Warna TCS3200





c. Program Code Vision AVR

/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.0 Evaluation
Automatic Program Generator
© Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : anak jalanan mencari cinta sejati
Version :
Date    : 5/1/2016
Author  : Freeware, for evaluation and non-commercial use only
Company :
Comments:


Chip type               : ATmega32
Program type            : Application
AVR Core Clock frequency: 12.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 512

S0 dan S1 5 volt

PORTA.3 = S0
PORTA.4 = S1
PORTA.5 = S2
PORTA.6 = S3
PORTA.7 = OE
PORTB.1 = OUT

S2=0 ; S3=0 -> filter merah
S2=0 ; S3=1 -> filter biru
S2=1 ; S3=0 -> filter clear
S2=1 ; S3=1 -> filter hijau
*****************************************************/
   
#include <mega8535.h>
#include <stdio.h>
#include <delay.h>
#define redref (27795/255)
#define greenref (33066.7/255)
#define blueref (34720/255)
   
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
   
// Declare your global variables here
   
unsigned char lcd_buffer[33];
unsigned int count, red, green, blue,a=0,b=0,c=0;
float periode, frekuensi;
   
void red_filter()
{
PORTA.5=0;
PORTA.6=0;
for(a=0; a<=5; a++)
{
while(PINB.1 == 0){}
while(PINB.1 == 1){}
}
   
while(PINB.1 == 0)
{
count++;
}

while(PINB.1 == 1)
{
count++;
}
   
periode = ((float)count*0.0000014400921658986175115207373271889);
frekuensi = ((float)1/periode);
red = (frekuensi/redref);
   
count=0;
   
}
   
void green_filter()
{
PORTA.5=1;
PORTA.6=1;
for(b=0; b<=5; b++)
{
while(PINB.1 == 0){}
while(PINB.1 == 1){}
}
   
while(PINB.1 == 0)
{
count++;
}
   
while(PINB.1 == 1)
{
count++;
}
   
periode = ((float)count*0.0000014400921658986175115207373271889);
frekuensi = ((float)1/periode);
green = (frekuensi/greenref);
   
count=0;
   
}
   
void blue_filter()
{
PORTA.5=0;
PORTA.6=1;
for(c=0; c<=5; c++)
{
while(PINB.1 == 0){}
while(PINB.1 == 1){}
}
   
while(PINB.1 == 0)
{
count++;
}
   
while(PINB.1 == 1)
{
count++;
}
   
periode = ((float)count*0.0000014400921658986175115207373271889);
frekuensi = ((float)1/periode);
blue = (frekuensi/blueref);
   
count=0;
   
}
   
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=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=0x02;
DDRB=0x00;
   
// Port C 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
PORTC=0x00;
DDRC=0x00;
   
// 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: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
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: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
   
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
   
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x23;
   
// Timer(s)/Counter(s) Interrupt(s) initialization
    TIMSK=0x00;
    
// 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);
   
count=0;
PORTA=0b10011000;
   
while (1)
{
// Place your code here
red_filter();
delay_ms(100);
green_filter();
delay_ms(100);
blue_filter();
delay_ms(100);
lcd_gotoxy(0,0);
lcd_clear();
sprintf(lcd_buffer,"R:%d G:%d B:%d",red,green,blue);
lcd_puts(lcd_buffer);
a=0; b=0; c=0;
    };
}





d. Cara Menggunakan Alat

        Hubungkan PORT S0, S1 ke vcc 5v dan S2, S3 ke port A5 dan A6 kemudian pin OUT dihubungkan ke PORTB.1. jangan lupa hubungkan juga power supply ke minimum system, jika berhasil maka alat akan menyala dan akan siap menampilkan nilai RGB. lakukan kalibrasi sensor dengan cara membuat batas atas dan bawah nilai sensor pada tiap-tiap warna. 
 



e. VIDEO HASILNYA











No comments:

Post a Comment