Color sensor output problem

Thread Starter

thavamaran

Joined Feb 21, 2008
67
Hi guys, i have recently programmed my PIC 16f877a, im using TCS230 as my color sensor, so i have used interrupt function to read the output of TCS230 and send it to PC via rs232, below is the program i did,

Rich (BB code):
#include <stdio.h>
#include <htc.h>
#include "usart.h"
#include "delay.h"

__CONFIG(0x3f71);
#define NUMBER_OF_PERIODS 6

unsigned int average;
unsigned char isAverageReady;

int R, G, B;




void delay ( void )
{
	DelayMs ( 100 );
}

static interrupt void isr ( void )

{
	static unsigned int time [ NUMBER_OF_PERIODS + 1 ];
	static unsigned char timeIndex = 0;

	if ( INTF )
	{
		time [ timeIndex++ ] = ( TMR1H << 8 ) + TMR1L;
		
		if ( timeIndex == NUMBER_OF_PERIODS + 1 )// wait until period reach 5 then 5+1 and proceed
		{
			INTE = 0;

			timeIndex = 0;
			
			average = ( time [ NUMBER_OF_PERIODS ] - time [ 0 ] ) / NUMBER_OF_PERIODS; //time is a memory location, time  [0] is start and number of period is end, end -start /end

            isAverageReady = 1;
		}

		INTF = 0;
	}
}

void getRGB ( void )

{
		// Get R Value
		RB2 = 0;
		RB4 = 0;

		delay();
		isAverageReady = 0;
		INTE = 1;

		while ( !isAverageReady )
			continue;

		R = average;

		// Get G Value
		RB2 = 1;
		RB4 = 1;

		delay();
		isAverageReady = 0;
		INTE = 1;

		while ( !isAverageReady )
			continue;

		G = average;

		// Get B Value
		RB2 = 0;
		RB4 = 1;

		delay();
		isAverageReady = 0;
		INTE = 1;

		while ( !isAverageReady )
			continue;

		B = average;
}

void main ( void )
{
	unsigned char input;

    // Initializations
    init_comms();
	TRISB = 0x01;

	INTEDG = 0;
	INTE = 1;
	TMR1CS = 0;
	GIE = 1;

	while ( 1 )
	{
		// Body
		input = getch();

		switch ( input )
		{
			case 'S':
				getRGB();
				printf ( "%d,%d,%d\r\n", R, G, B );
				break;
		}
	}
}
, so if you look at the code, i have type 'S' from my pc to get the output from PIC, but what im getting is only (0,0,0) whereby when i measure the output of sensor directly to oscilloscope and there it output and kip changing when the filter changed by the PIC according to the software above, but when i measure the amplitude of the output, its 2.5 to 2.6V in output line of the sensor, is it the reason that PIC couldnt read it? do i need to amplify the signal for PIC? Here i attach the datasheet of TCS230. if i need to amplify, what it the best way? Op-Amp or Transistor?
 

Attachments

bertus

Joined Apr 5, 2008
22,277
Hello,

Did you see the text on output conditioning?

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.
How large is the distance between sensor and PIC?

Greetings,
Bertus
 

Thread Starter

thavamaran

Joined Feb 21, 2008
67
Hey bertus, thanks for the quick reply, my output wire is like approximately 6 inches. thats why i wondering why the output voltage is low. what can i do to overcome this?
 

bertus

Joined Apr 5, 2008
22,277
Hello,

What is the powersupply voltage?
What are you driving?
The output can deliver 4 mA.




Perhaps a line driver will help.

Greetings,
Bertus
 

Attachments

Last edited:

Thread Starter

thavamaran

Joined Feb 21, 2008
67
Hi bertus,

What is the powersupply voltage?
What are you driving?
The output can deliver 4 mA.
The supply for PIC and TCS230 is approximately 5.1V, what you mean by what i am driving?

But perhaps line drivers amplification is kind of high right?
 

bertus

Joined Apr 5, 2008
22,277
Hello,

By driving I mean , what is connected to the sensor.
As driver you could use a hef40244.

Greetings,
Bertus
 

Thread Starter

thavamaran

Joined Feb 21, 2008
67
Hi Bertus,

PIC 16f877A is connected to the sensor, nothing else is connected. is there any example schematics that you have probably i could use?
 

bertus

Joined Apr 5, 2008
22,277
Hello,

I am not so familair with pics, but is the pic reacting on the signals from the sensor?
Is the pin declared as input? (if it is as output, the pic will not react and the voltage on the pin may be not correct).

Greetings,
Bertus
 

Thread Starter

thavamaran

Joined Feb 21, 2008
67
Oh ok, yes i have declared in the c programming, if you refer to the line somewhere towards the end, there is this code TRISB=0x01, which declares RB0 pin as input pin and RB0 pin is the interrupt function pin of PIC. the pin is not reacting cause im not receiving signals in pc except for (0,0,0), because the amplitude is 2.6V only for the output of the sensor. TTL logic needs at least 3.5V to receive signal, correct me if im wrong, and its using Schmitt Trigger configuration for that particular pin cause its interrupt function, but its fully transistor logic.

Can i use a buffer circuit with OP-amp configuration?
 

Thread Starter

thavamaran

Joined Feb 21, 2008
67
Hey bertus, Thanks man, i will simulate it and will try to feed it into my circuit, will let you know the result soon. thank you. thanks for your time!
 
Top