Вы находитесь на странице: 1из 12

COLOUR SENSOR

Description:

The TCS3200 and TCS3210 programmable color light-to-frequency converters that combine
configurable silicon photodiodes and a current-to-frequency converter on a single monolithic
CMOS integrated circuit. The output is a square wave (50% duty cycle) with frequency directly
proportional to light intensity (irradiance). The full-scale output frequency can be scaled by one
of three preset values via two control input pins. Digital inputs and digital output allow direct
interface to a microcontroller or other logic circuitry. Output enable (OE) places the output in the
high-impedance state for multiple-unit sharing of a microcontroller input line. In the TCS3200,
the light-to-frequency converter reads an 8 x 8 array of photodiodes. Sixteen photodiodes have
blue filters, 16 photodiodes have green filters, 16 photodiodes have red filters, and 16
photodiodes are clear with no filters. In the TCS3210, the light-to-frequency converter reads a 4
x 6 array of photodiodes. Six photodiodes have blue filters, 6 photodiodes have green filters, 6
photodiodes have red filters, and 6 photodiodes are clear with no filters. The four types (colors)
of photodiodes are interdigitated to minimize the effect of non-uniformity of incident irradiance.
All photodiodes of the same color are connected in parallel. Pins S2 and S3 are used to select
which group of photodiodes (red, green, blue, clear) are active. Photodiodes are 110 μm x 110
μm in size and are on 134-μm centers.
Functional Block Diagram:

APPLICATION INFORMATION:

Power supply considerations:

Power-supply lines must be decoupled by a 0.01-μF to 0.1-μF capacitor with short leads mounted
close to the device package.

Input interface:

A low-impedance electrical connection between the device OE pin and the device GND pin is
required for improved noise immunity. All input pins must be either driven by a logic signal or
connected to VDD or GND —they should not be left unconnected (floating).

Output interface:

The output of the device is designed to drive a standard TTL or CMOS logic input over short
distances. If lines greater than 12 inches are used on the output, a buffer or line driver is
recommended. A high state on Output Enable (OE) places the output in a high-impedance state
for multiple-unit sharing of a microcontroller input line.

Power down

Powering down the sensor using S0/S1 (L/L) will cause the output to be held in a high-
impedance state. This is similar to the behavior of the output enable pin, however powering
down the sensor saves significantly more power than disabling the sensor with the output enable
pin. Photodiode type (color) selection The type of photodiode (blue, green, red, or clear) used by
the device is controlled by two logic inputs, S2 and S3

Output frequency scaling:

Output-frequency scaling is controlled by two logic inputs, S0 and S1. The internal light-to-
frequency converter generates a fixed-pulse width pulse train. Scaling is accomplished by
internally connecting the pulse-train output of the converter to a series of frequency dividers.
Divided outputs are 50%-duty cycle square waves with relative frequency values of 100%, 20%,
and 2%. Because division of the output frequency is accomplished by counting pulses of the
principal internal frequency, the final-output period represents an average of the multiple periods
of the principle frequency. The output-scaling counter registers are cleared upon the next pulse of
the principal frequency after any transition of the S0, S1, S2, S3, and OE lines. The output goes
high upon the next subsequent pulse of the principal frequency, beginning a new valid period.
This minimizes the time delay between a change on the input lines and the resulting new output
period. The response time to an input programming change or to an irradiance step change is one
period of new frequency plus 1 μs. The scaled output changes both the full-scale frequency and
the dark frequency by the selected scale factor. The frequency-scaling function allows the output
range to be optimized for a variety of measurement techniques. The scaled-down outputs may be
used where only a slower frequency counter is available, such as low-cost microcontroller, or
where period measurement techniques are used.

Measuring the frequency:

The choice of interface and measurement technique depends on the desired resolution and data
acquisition rate. For maximum data-acquisition rate, period-measurement techniques are used.
Output data can be collected at a rate of twice the output frequency or one data point every
microsecond for full-scale output. Period measurement requires the use of a fast reference clock
with available resolution directly related to reference clock rate. Output scaling can be used to
increase the resolution for a given clock rate or to maximize resolution as the light input changes.
Period measurement is used to measure rapidly varying light levels or to make a very fast
measurement of a constant light source. Maximum resolution and accuracy may be obtained
using frequency-measurement, pulse-accumulation, or integration techniques. Frequency
measurements provide the added benefit of averaging out random- or high-
frequehttp://researchdesignlab.com/?attachment_id=672ncy variations (jitter) resulting from
noise in the light signal. Resolution is limited mainly by available counter registers and
allowable measurement time. Frequency measurement is well suited for slowly varying or
constant light levels and for reading average light levels over short periods of time. Integration
(the accumulation of pulses over a very long period of time) can be used to measure exposure,
the amount of light present in an area over a given time period.

Detecting color of an object can be an interesting and useful electronic application. It can be
realized using a color sensor like TCS3200 and a general purpose microcontroller like
8051/PIC/ARM

TCS3200 chip is designed to detect the color of light incident on it. It has an array of photodiode
(a matrix of 8×8, so a total 64 sensors). These photodiodes are covered with three type of filters.
Sixteen sensor have RED filter over them thus can measure only the component of red in the
incident light. Like wise other sixteen have GREEN filter and sixteen have BLUE filter. As you
should know that any visible color can be broken into three primary colors. So these three type of
filtered sensors helps measure the weight age of each of primary color in incident light. The rest
16 sensors have clear filter.
TCS3200 converts the intensity of incident radiation into frequency. The output waveform is a
50% duty cycle square wave. You can use the timer of a MCU to measure period of pulse and
thus get the frequency.
The output of TCS3200 is available in single line. So you would ask how we get the intensity of
RED,GREEN, BLUE and CLEAR channels? Well it has two inputs S2 and S3 that is used to
select the sensor whose output need to be made available on the out line.
S2 S3
RED L L
GREEN H H
BLUE L H
CLEAR H L

SOURCE CODE:

1 /*
* Project name:
2
COLOUR SENSOR
3 * Copyright
4 (c) Researchdesignlab.com
5 * Description:
6
7 * Test configuration:
MCU: AT89S52
8 Dev.Board: 8051
9 Oscillator: 11.0592 MHz
10 Software: Keil uVision3
11
12 */
13
14
15
16 #include <reg51.h>
#include"string.h"
17 #define LCD_PORT P2
18 // LCD 8 DATA LINE ARE CONNECTED TO P2
19 sbit rs=P3^6; // LCD RS=P3.5
20 sbit en=P3^7; // LCD EN=P3.7
21
sbit S2=P1^0;
22
sbit S3=P1^1;
23 sbit S0=P1^3;
24 sbit S1=P1^4;
25
26
27 unsigned char count=0;
28
29 sbit mybit=P3^5; //color sensor O/P pin
30
void DELAY();
31 void busy();
32 void CMD_WRT(unsigned char);
33 void DATA_WRT(unsigned char);
34 void CONVERT_DISPLAY(unsigned int );
35 void LCD_WRT(unsigned char *);
void DELAY();
36
37 void delaytimer()
38 {
39 unsigned char n;
40 for(n=0;n<14;n++)
{
41 TR0=1;
while(TF0==0);
42
TF0=0;
43 TL0=0x00;
44 TH0=0x00;
45 }
46 }
47
48
49
50
51
52
53
//***************************************************************//
54
55
56 void main()
57 {
58
59 unsigned char CMD[]={0X38,0X01,0X0F,0X06,0X80},i,TEMP,temp;
60 DELAY();
61 for(i=0;i<=4;i++)
{
62 TEMP=CMD[i];
63 CMD_WRT(TEMP);
64 }
65 DELAY();
66 count=0;
TMOD=0x51;
67 DELAY();
68 S0=1;
69 S1=1;
70 S2=0;
S3=0;
71
72 while(1)
73 {
74
75 TL0=0x00;
76 TH0=0x00;
77 TL1=0X00;
TH1=0X00;
78 TR1=1;
79
80
81 while(mybit==1);
82
83 for(i=0;i<3;i++)
84 delaytimer();
85
86 TR1=0;
TR0=0;
87
88 temp=TL1;
89 CMD_WRT(0X01);
CMD_WRT(0X80);
90 LCD_WRT("COLOR SENSOR");
91
92 CONVERT_DISPLAY(temp);
93
94 DELAY();
95 DELAY();
96
97
98
}
99
10
0
10
1
10
2
}
10
3
10
4
10
5
10
6
10
7 void
{
DELAY()
10 unsigned int X=6000;
8 while(X--);
10 }
9
11
0
111
11
2 //***************************************************//
11
3
11
4
11 void CONVERT_DISPLAY(unsigned int d)
{
5
11 unsigned char dig1,dig2,dig3,dig[3];
6 unsigned char x;
11 unsigned char temp;
temp=d;
7
temp=temp/10;
11 dig1=d%10;
8 dig2=temp%10;
11 dig3=temp/10;
9
12
0 dig[0]=dig3;
dig[1]=dig2;
12 dig[2]=dig1;
1
12 CMD_WRT(0xC2);
2
12 for(x=0;x<3;x++)
3 {
12 temp=dig[x]|0x30;
DATA_WRT(temp);
4
12
DELAY();
5
12
6 }
12
7
12 }
8
12
9
13
0
13
1 void CMD_WRT(unsigned char val) // COMMAND WRITE FUNCTION
13 {
2
13 LCD_PORT=val; //write cmd to P2
rs=0; //cmd mode
3
13
en=1; //high to low latch
4 DELAY();
13 en=0;
5 }
13
6 void DATA_WRT(unsigned char ch) // DATA WRITE FUNCTION
{
13
7
LCD_PORT = ch; //write data to P2
13 rs=1; //data mode
8
13 en=1;
9 DELAY(); //high to low latch
en=0;
14 }
0
14 void LCD_WRT(unsigned char *string)
{
1 while(*string)
14 DATA_WRT(*string++);
2 }
14
3
14
4
14
5
14
6
14
7
14
8
14
9
15
0
15
1
15
2
15
3
15
4
15
5
15
6
15
7
15
8
15
9
16
0
16
1
16
2
16
3
16
4
16
5
16
6
16
7
16
8
16
9
17
0
17
1
17
2
17
3
17
4
17
5
17
6
17
7
17
8
17
9
18
0
18
1
18
2
18
3
18
4
18
5
18 /*
* Project name:
6
COLOUR Sensor
18 * Copyright
7 (c) Researchdesignlab.com
18 * Test configuration:
8 MCU: PIC16F877A
Dev.Board: PIC
18 Oscillator: 20.0 MHz
9 Software: mikroC PRO for PIC v 4.6
19
0 */
19
1
19
2 // LCD module connections
19 sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
3 sbit LCD_D4 at RB0_bit;
19 sbit LCD_D5 at RB1_bit;
4 sbit LCD_D6 at RB2_bit;
19 sbit LCD_D7 at RB3_bit;
5
sbit LCD_RS_Direction at TRISB4_bit;
19 sbit LCD_EN_Direction at TRISB5_bit;
6 sbit LCD_D4_Direction at TRISB0_bit;
19 sbit LCD_D5_Direction at TRISB1_bit;
7 sbit LCD_D6_Direction at TRISB2_bit;
19 sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
8
19
9 sbit S2 at RD7_bit;
20 sbit S3 at RD6_bit;
0 sbit S0 at RD5_bit;
20 sbit S1 at RD4_bit;
1
20
2 unsigned int VAL;
char TXT[6];
20
3 void main() {
20
4
20 Lcd_Init(); // Initialize LCD
5
20 Lcd_Cmd(_LCD_CLEAR); // Clear display
6 Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
20
TRISC0_bit=1;
7 OPTION_REG.F5=1;
20 TRISD=0X00;
8 S0=1;
S1=1;
S2=0;
S3=0;
Delay_ms(1000);

while(1)
{
Lcd_Cmd(_LCD_CLEAR);
20
Lcd_Out(1, 1, " COLOR SENSOR");
9 TMR0=0;
21 Delay_ms(1000);
0 VAL=TMR0;
21 WordToStr(VAL,TXT);
1 Lcd_Out(2, 3,TXT);
Delay_ms(2000);

Вам также может понравиться