Color sensor output problem

Discussion in 'The Projects Forum' started by thavamaran, Apr 19, 2009.

  1. thavamaran

    Thread Starter Active Member

    Feb 21, 2008
    67
    0
    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,

    Code ( (Unknown Language)):
    1. #include <stdio.h>
    2. #include <htc.h>
    3. #include "usart.h"
    4. #include "delay.h"
    5.  
    6. __CONFIG(0x3f71);
    7. #define NUMBER_OF_PERIODS 6
    8.  
    9. unsigned int average;
    10. unsigned char isAverageReady;
    11.  
    12. int R, G, B;
    13.  
    14.  
    15.  
    16.  
    17. void delay ( void )
    18. {
    19.     DelayMs ( 100 );
    20. }
    21.  
    22. static interrupt void isr ( void )
    23.  
    24. {
    25.     static unsigned int time [ NUMBER_OF_PERIODS + 1 ];
    26.     static unsigned char timeIndex = 0;
    27.  
    28.     if ( INTF )
    29.     {
    30.         time [ timeIndex++ ] = ( TMR1H << 8 ) + TMR1L;
    31.        
    32.         if ( timeIndex == NUMBER_OF_PERIODS + 1 )// wait until period reach 5 then 5+1 and proceed
    33.         {
    34.             INTE = 0;
    35.  
    36.             timeIndex = 0;
    37.            
    38.             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
    39.  
    40.             isAverageReady = 1;
    41.         }
    42.  
    43.         INTF = 0;
    44.     }
    45. }
    46.  
    47. void getRGB ( void )
    48.  
    49. {
    50.         // Get R Value
    51.         RB2 = 0;
    52.         RB4 = 0;
    53.  
    54.         delay();
    55.         isAverageReady = 0;
    56.         INTE = 1;
    57.  
    58.         while ( !isAverageReady )
    59.             continue;
    60.  
    61.         R = average;
    62.  
    63.         // Get G Value
    64.         RB2 = 1;
    65.         RB4 = 1;
    66.  
    67.         delay();
    68.         isAverageReady = 0;
    69.         INTE = 1;
    70.  
    71.         while ( !isAverageReady )
    72.             continue;
    73.  
    74.         G = average;
    75.  
    76.         // Get B Value
    77.         RB2 = 0;
    78.         RB4 = 1;
    79.  
    80.         delay();
    81.         isAverageReady = 0;
    82.         INTE = 1;
    83.  
    84.         while ( !isAverageReady )
    85.             continue;
    86.  
    87.         B = average;
    88. }
    89.  
    90. void main ( void )
    91. {
    92.     unsigned char input;
    93.  
    94.     // Initializations
    95.     init_comms();
    96.     TRISB = 0x01;
    97.  
    98.     INTEDG = 0;
    99.     INTE = 1;
    100.     TMR1CS = 0;
    101.     GIE = 1;
    102.  
    103.     while ( 1 )
    104.     {
    105.         // Body
    106.         input = getch();
    107.  
    108.         switch ( input )
    109.         {
    110.             case 'S':
    111.                 getRGB();
    112.                 printf ( "%d,%d,%d\r\n", R, G, B );
    113.                 break;
    114.         }
    115.     }
    116. }
    117.  
    , 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?
     
  2. bertus

    Administrator

    Apr 5, 2008
    15,645
    2,344
    Hello,

    Did you see the text on output conditioning?

    How large is the distance between sensor and PIC?

    Greetings,
    Bertus
     
  3. thavamaran

    Thread Starter Active Member

    Feb 21, 2008
    67
    0
    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?
     
  4. bertus

    Administrator

    Apr 5, 2008
    15,645
    2,344
    Hello,

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

    [​IMG]


    Perhaps a line driver will help.

    Greetings,
    Bertus
     
    Last edited: Apr 19, 2009
  5. thavamaran

    Thread Starter Active Member

    Feb 21, 2008
    67
    0
    Hi bertus,

    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?
     
  6. bertus

    Administrator

    Apr 5, 2008
    15,645
    2,344
    Hello,

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

    Greetings,
    Bertus
     
  7. thavamaran

    Thread Starter Active Member

    Feb 21, 2008
    67
    0
    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?
     
  8. bertus

    Administrator

    Apr 5, 2008
    15,645
    2,344
    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
     
  9. thavamaran

    Thread Starter Active Member

    Feb 21, 2008
    67
    0
    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?
     
  10. bertus

    Administrator

    Apr 5, 2008
    15,645
    2,344
    Hello,

    Perhaps this little transistor inverter/buffer will help.

    [​IMG]

    Greetings,
    Bertus
     
  11. thavamaran

    Thread Starter Active Member

    Feb 21, 2008
    67
    0
    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!
     
Loading...