merhabalar pıc 16f877a mikrodenetleyici kullanıyorum. tc3200 sensörünü CCS C ile nasıl kullancağımı bilmiyorum. yardımcı olabilcek olan var mı?
Merhaba.
Sensörün çalışma mandığı renk seçme girişlerine ilgili lojik seviyeler uygulanarak çıkıştan frekans okumaktır. Datasheetten aldığım tablo aşağıdadır. Sizin yapmanız gereken ilgili renk girişine lojik seviyeyi uyguladıktan sonra çıkıştaki frekansı ölçmektir. Diğer renkler içinde aynısı geçerlidir. Tek bir rengi tam manasıyla algılamak için aynı renk için diğer iki rengin frekansınıda ölçmeniz gerekiyor. Bu yazılımsal olarak rengi ayrıştırmada çok önemlidir.
S0 ve S1 girişleri yanlış hatırlamıyorsam çıkış frekansının belli bir oranda arttırıyordu. Yani %2 iken ilgili renk için 100Hz alıyorsanız, %100 iken 1kHz alıyorsunuz. Bu da kaliteli ve hassas ölçüm yapmanızı sağlıyor. Oranları salladım, hatırlamıyorum.
Eğer sensörü osiloskop ile inceleme şansınız varsa devre kurmadan renklere göre çıkışı osiloskopta inceleyin. Skalayı %2, %20, %100 yapıp çıkışı gözlemleyin. İyice kavradıktan sonra kodlamaya geçersiniz.
https://www.mouser.com/catalog/specsheets/TCS3200-E11.pdf (https://www.mouser.com/catalog/specsheets/TCS3200-E11.pdf)
(https://i.ibb.co/GPSpH4f/fdfsd.png)
PIC16F876A ile yaptığım bir uygulama var. PCB dosyasıda mevcuttur. Pratikte test edilmiştir.
Yalnız ilgili sensörden güzel sonuçlar almanız için gün ışının minimum etki edeceği ortamlarda ölçüm yapmanız gerekiyor. Sabit beyaz ışığın bulunduğu bir ortamda çok güzel sonuçlar veriyor. Ek olarak belirtmek istedim.
Uygulama web sitemde yer almaktadır. Aşağıdaki bağlantıya tıklayarak ilgili sayfadan indirebilirsiniz. İlgili sayfada video da yer almaktadır.
https://www.elektrocavus.com/PIC16F876A-ile-renk-sensoru-uygulamasi (https://www.elektrocavus.com/PIC16F876A-ile-renk-sensoru-uygulamasi)
Ya da kodu inceleyebilirsiniz.
//elektrocavus.com tarafından yazılmıştır.
#include <16f876a.h>
#fuses HS, NOWDT
#use delay(clock=20M)
#define LCD_DATA_PORT getenv("SFR:PORTB") //portd
#include <C:\Users\Sys\Desktop\RENK_SENSORU\lcd.c>
#use fast_io(c)
#define menu_buton input(pin_a0)
#define sag_buton !input(pin_a1)
#define sol_buton !input(pin_a2)
#define renk_sensoru_sinyal !input(pin_a4) // pull
#define renk_sensoru_led pin_c3
#define renk_sensoru_s0 pin_c7
#define renk_sensoru_s1 pin_c6
#define renk_sensoru_s2 pin_c5
#define renk_sensoru_s3 pin_c4
#define R_cikis pin_c0
#define G_cikis pin_c1
#define B_cikis pin_c2
#define buzzer pin_a5
#define lcd_led pin_b3
unsigned int16 sinyal[3]={0};
unsigned int16 on_bellek[10]={0};
unsigned int8 oran[3]={0};
unsigned int16 buton_sayac=0, ab=0;
unsigned int8 ornek=0, i=0, l=0, menu=0;
int1 menu_onay=0, tazele_onay=0, baslik_onay=0, led_onay=0, onay_flash=0, hesapla_onay=0, filtre_onay=0;
//elektrocavus.com tarafından yazılmıştır.
Void cek()
{
for(i=1;i<10;i++)
{
on_bellek[i-1] = (unsigned int16)read_eeprom(i);
}
}
Void menu_tazele()
{
switch(menu)
{
case 0:
printf(lcd_putc,"\f KIRMIZI TESPiT"); //10
break;
case 1:
printf(lcd_putc,"\f YESiL TESPiT"); //7
break;
case 2:
printf(lcd_putc,"\f MAVi TESPiT");
break;
case 3:
printf(lcd_putc,"\f FiLTRE");
lcd_gotoxy(7,2);
printf(lcd_putc,"-%02u+",(unsigned int8)on_bellek[9]);
break;
case 4:
printf(lcd_putc,"\f RGB LED");
if(read_eeprom(11))
{
lcd_gotoxy(5,2);
printf(lcd_putc," +ACIK ");
}
else
{
lcd_gotoxy(5,2);
printf(lcd_putc,"-KAPALI");
}
break;
case 5:
printf(lcd_putc,"\f LCD LED");
if(read_eeprom(12))
{
lcd_gotoxy(5,2);
printf(lcd_putc," +ACIK ");
}
else
{
lcd_gotoxy(5,2);
printf(lcd_putc,"-KAPALI");
}
break;
}
if(led_onay==1)
{
LCD_GOTOXY(4,1);
printf(lcd_putc,">");
}
if(filtre_onay==1)
{
LCD_GOTOXY(5,1);
printf(lcd_putc,">");
}
}
//elektrocavus.com tarafından yazılmıştır.
Void alt_prog()
{
if(read_eeprom(menu+8)==0)
{
LCD_GOTOXY(5,2);
write_eeprom(menu+8,1);
printf(lcd_putc," +ACIK ");
}
else
{
LCD_GOTOXY(5,2);
write_eeprom(menu+8,0);
printf(lcd_putc,"-KAPALI");
}
if(menu==4)
{
if(read_eeprom(menu+8))
output_low(renk_sensoru_led);
else
output_high(renk_sensoru_led);
}
if(menu==5)
{
if(read_eeprom(menu+8))
output_high(lcd_led);
else
output_low(lcd_led);
}
}
Void kontrol()
{
ab= sinyal[0]+sinyal[1]+sinyal[2];
oran[0] = (unsigned int8)(sinyal[0]*10.0/ab);
oran[1] = (unsigned int8)(sinyal[1]*10.0/ab);
oran[2] = (unsigned int8)(sinyal[2]*10.0/ab);
if(
on_bellek[0]==oran[0] &&
on_bellek[1]==oran[1] &&
on_bellek[2]==oran[2]
)
{
output_high(R_cikis);
output_low(G_CIKIS);
output_low(B_CIKIS);
}
else if(
on_bellek[3]==oran[0] &&
on_bellek[4]==oran[1] &&
on_bellek[5]==oran[2]
)
{
output_high(G_cikis);
output_low(R_CIKIS);
output_low(B_CIKIS);
}
else if(
on_bellek[6]==oran[0] &&
on_bellek[7]==oran[1] &&
on_bellek[8]==oran[2]
)
{
output_high(B_cikis);
output_low(R_CIKIS);
output_low(G_CIKIS);
}
else
{
output_low(R_CIKIS);
output_low(G_CIKIS);
output_low(B_CIKIS);
}
}
Void filtre_ekran()
{
lcd_gotoxy(6,2);
printf(lcd_putc," -%02u+ ",(unsigned int8)on_bellek[9]);
}
Void ana_ekran()
{
printf(lcd_putc,"\fR G B");
}
Void sinyal_goster()
{
if(hesapla_onay==1)
{
ab= sinyal[0]+sinyal[1]+sinyal[2];
for(l=0;l<3;l++)
{
if(sinyal[l]<on_bellek[9])
sinyal[l]=0;
LCD_GOTOXY(2+(l*6),1);
printf(lcd_putc,"%03Lu",sinyal[l]);
LCD_GOTOXY(2+(l*6),2);
printf(lcd_putc,"%02u",(unsigned int8)(sinyal[l]*10.0/ab));
}
kontrol();
set_timer1(15535);
set_timer0(0);
hesapla_onay=0;
}
}
//elektrocavus.com tarafından yazılmıştır.
Void m_sinyal_goster()
{
if(hesapla_onay==1)
{
ab= sinyal[0]+sinyal[1]+sinyal[2];
for(l=0;l<3;l++)
{
if(sinyal[l]<on_bellek[9])
sinyal[l]=0;
LCD_GOTOXY(1+(l*6),2);
printf(lcd_putc,"%03u",(unsigned int8)(sinyal[l]*10.0/ab));
}
set_timer1(15535);
set_timer0(0);
hesapla_onay=0;
}
}
#int_timer1
Void ms_kesmesi()
{
set_timer1(15535); // 1ms kesme referansı
if(hesapla_onay==0)
{
sinyal[ornek] = get_timer0();
ornek++;
switch(ornek)
{
case 0: output_low(renk_sensoru_s2); output_low(renk_sensoru_s3); break; // R
case 1: output_high(renk_sensoru_s2); output_high(renk_sensoru_s3); break;// G
case 2: output_low(renk_sensoru_s2); output_high(renk_sensoru_s3); break; // B
}
}
if(!menu_buton)
{
buton_sayac++;
if(buton_sayac>600)
buton_sayac=0;
}
//elektrocavus.com tarafından yazılmıştır.
if(buton_sayac>=200)
{
buton_sayac=0;
if(menu_onay!=1)
{
menu_onay=1;
tazele_onay=1;
}
else
{
menu_onay=0;
baslik_onay=1;
}
}
else if(buton_sayac>=50 && menu_onay && menu_buton)
{
if(menu>3)
{
if(led_onay==0)
led_onay=1;
else
led_onay=0;
tazele_onay=1;
}
else if(menu<3)
{
ONAY_FLASH=1;
}
if(menu==3)
{
if(filtre_onay==0)
filtre_onay=1;
else
filtre_onay=0;
tazele_onay=1;
}
buton_sayac=0;
}
else if(menu_buton)
buton_sayac=0;
if(ornek==3)
{
ornek=0;
output_low(renk_sensoru_s2); output_low(renk_sensoru_s3); // R
hesapla_onay=1;
}
set_timer0(0);
}
//elektrocavus.com tarafından yazılmıştır.
Void main()
{
output_high(renk_sensoru_led);
lcd_init();
printf(lcd_putc,"\f");
set_tris_c(0);
setup_timer_0(RTCC_EXT_H_TO_L | RTCC_DIV_1);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1 );
set_timer1(15535); // 1ms kesme referansı
output_high(renk_sensoru_s0);
output_high(renk_sensoru_s1);
enable_interrupts(int_timer1);
enable_interrupts(global);
output_low(renk_sensoru_led);
output_high(lcd_led);
if(read_eeprom(0)!=255)
{
on_bellek[9] = read_eeprom(10);
if(read_eeprom(11))
output_low(renk_sensoru_led);
else
output_high(renk_sensoru_led);
if(read_eeprom(12))
output_high(lcd_led);
else
output_low(lcd_led);
cek();
}
ana_ekran();
for(;;)
{
if(baslik_onay && menu_onay==0)
{
write_eeprom(0,0);
ana_ekran();
cek();
baslik_onay=0;
write_eeprom(10,on_bellek[9]);
output_high(buzzer);
delay_ms(200);
output_low(buzzer);
}
else if(menu_onay==0)
{
sinyal_goster();
}
else
{
output_high(buzzer);
delay_ms(50);
output_low(buzzer);
while(menu_onay)
{
while(sol_buton && sag_buton && menu_onay && !onay_flash && !tazele_onay && !LED_ONAY && !filtre_onay);
if(sol_buton && !sag_buton)
{
while(sol_buton && !sag_buton);
delay_ms(20);
if(led_onay==0 && filtre_onay==0)
{
if(menu!=0)
menu--;
tazele_onay=1;
}
else if(led_onay)
{
ALT_PROG();
}
else if(filtre_onay)
{
if(on_bellek[9]!=0)
on_bellek[9]--;
filtre_ekran();
}
}
else if(sag_buton && !sol_buton)
{
while(!sol_buton && sag_buton);
delay_ms(20);
if(led_onay==0 && filtre_onay==0)
{
if(menu!=5)
menu++;
tazele_onay=1;
}
else if(led_onay)
{
ALT_PROG();
}
else if(filtre_onay)
{
if(on_bellek[9]!=100)
on_bellek[9]++;
filtre_ekran();
}
}
if(onay_flash)
{
ab= sinyal[0]+sinyal[1]+sinyal[2];
on_bellek[(menu*3)] = (unsigned int8)(sinyal[0]*10.0/ab);
on_bellek[(menu*3)+1] = (unsigned int8)(sinyal[1]*10.0/ab);
on_bellek[(menu*3)+2] = (unsigned int8)(sinyal[2]*10.0/ab);
write_eeprom((menu*3)+1,on_bellek[(menu*3)]);
write_eeprom((menu*3)+2,on_bellek[(menu*3)+1]);
write_eeprom((menu*3)+3,on_bellek[(menu*3)+2]);
output_high(buzzer);
delay_ms(100);
output_low(buzzer);
delay_ms(50);
output_high(buzzer);
delay_ms(100);
output_low(buzzer);
onay_flash=0;
}
if(tazele_onay)
{
MENU_TAZELE();
tazele_onay=0;
}
if(menu<3)
{
m_sinyal_goster();
}
}
}
}
}
İyi çalışmalar.
teşekkür ederim yardımınız için. ama sitedeki linkten maalesef dosyalar açılmıyor. ben sadece tc3200 sensöründen değeri okuyup çevirmek istiyorum. butonlar falan işin ekstra tarafı tabiki. (dilaver_128@hotmail.com)
@dilaver1998 ben herhangi bir sorun yaşamıyorum dosyaları indirirken.
Tarayıcınızla alakalı bir problem olabilir. Pop-up(açılır pencere) uyarısına dikkat edin indirirken.