Fads to Obsessions and Beyond...




Free domain for life, exceptional technical support, website transfer

TCS3471 Light To Digital Converter

Basic controller firmware code for the TCS3471 was developed (using C code, CCS compiler, on a PIC18F248) to enable control of a TCS3471 via I2C interface to PIC microcontroller. A Visual Basic application was developed to enable PC interface (via RS232/serial port) to the TCS3471/PIC to facilitate TCS3471 register setting and capture of digital output.

The DIY spectrophotometer project requires a detector for the monochromatic light adsorption for chemical analysis of hydroponic nutrient solutions. In the first instance, a photoresistor was trialled which showed the 'proof of concept' was valid. A possible alternative is the TCS3471 color light to digital converter, which has the advantage of containing a 4 × 4 photodiode array (red-filtered, green-filtered, blue-filtered, and clear photodiodes — four of each type), integrating amplifiers, ADCs, accumulators, clocks, buffers, comparators, a state machine, and an I2C interface all on a single chip.

The cost of the TCS3471 (~$5/item) is much greater than a 'discrete' photoresistor/photodiode, but as previously mentioned, with 'onboard' integrating amplifiers, ADCs, etc and with output produced as a digital value (16 bit resolution) available via I2C, the resultant overall circuit of the potential 'DIY' spectrophotometer (and required firmware) would be simplified, and hence the extra expense of the TCS3471 warranted. However, the expected incident light levels of interest (produced by the DVD 'diffraction grating' in the 'DIY' spectrophotometer) will be low, and hence the sensitivity of the TCS3471 will need to be sufficient to realise the other benefits mentioned.

Basic controlling firmware for the TCS3471 was developed (using CCS C code on a PIC18F248) to enable control of a TCS3471 via I2C interface to PIC microcontroller. A Visual Basic application was developed to enable PC interface (via RS232/serial port) to the TCS3471/PIC to facilitate TCS3471 register setting and capture of digital output. This was to enable testing of the TCS3471 under various incident light levels of interest produced by a DVD 'diffraction grating'/1W white LED light source to ascertain if this sensor would have applicability to the DIY spectrophotometer project.

The TCS3471 datasheet shows this component requires a supply voltage of 3V (3.3V max), and that the I2C voltage has two alternatives (Vdd, i.e. 3.3V max, or 1.8V) depending upon the exact device designation (the TCS34715 has I2C Vbus=Vdd and was used during this testing). Other features of the TCS3471 from the datasheet:

    • Programmable Analog Gain, Integration Time, and Interrupt Function with Upper and Lower Thresholds
    • Resolution Up to 16 Bits − With Very High Sensitivity
    • On Board Wait Timer is Programmable from 2.4 ms to > 7 Seconds
    • Dedicated Interrupt Pin
    • Small 2 mm x 2.4 mm Dual Flat No-Lead Package (this is actually a disadvantage for the DIY'er - the FN package is difficult to handle/solder)

The schematic for the TCS3471 with connections to the PIC18F248 is given in the Schematics Section below. The ancillary circuitry for the PIC18F248 also includes connection via RS232 to a PC (enables PC control of the TCS3471 and downloading of data).

Power Supply

A typical "wall-wart" power-supply is used (a surplus laptop charger in this case) in conjunction with a voltage regulator (LM317T) to provide the regulated 5V required by the PIC microcontroller.

The TCS3471 requires 3.3V supply which is provided by U3 (TL431 programmable shunt voltage reference) with resistors R3 and R4.

R5 and R6 are pull-up resistors required by the I2C interface, and capacitor C10 is a decoupling capacitor for U4 as per the datasheet.

Firmware/Software

The basic controlling firmware for the TCS3471 is based upon the code provided by TAOS/AMS (1), however, this has been 'refactored' to compile with the CCS compiler, and interface to a PC via RS232.

The TCS3471 datasheet details the internal operation and I2C communication protocol requirements in great detail. Interface and control are accomplished through an I2C serial compatible interface (standard or fast mode) to a set of registers that provide access to device control functions and output data. The I2C standard provides for three types of bus transaction: read, write, and a combined protocol (Figure 10 in the datasheet).

During a write operation, the first byte written is a command byte followed by data. In a combined protocol, the first byte written is the command byte followed by reading a series of bytes. If a read command is issued, the register address from the previous command will be used for data access. Likewise, if the MSB of the command is not set, the device will write a series of bytes at the address stored in the last valid command with a register address. The command byte contains either control information or a 5-bit register address. The control commands can also be used to clear interrupts. The firmware implements this protocol for the various defined register set (table 1 of the datasheet) - see the Testing/Experimental Results Section for code.

The TCS3471 itself contains a 4 × 4 photodiode array, integrating amplifiers, ADCs, accumulators, clocks, buffers and comparators all controlled by an internal 'state machine' with communications via the previously discussed I2C interface. The basic operation of the TCS3471 state machine starts with the device in sleep mode upon power-up. As soon as the PON bit is set, the device will move to the start state. It will then continue through the Wait and RGBC (read photodiodes) states. If these states are enabled, the device will execute each function. If the PON bit is set to 0, the state machine will continue until all conversions are completed (i.e all photodiodes have been read and data stored ready for output) and then go into a low power sleep mode.

The firmware implements the necessary functions to interact with the TCS3471 state machine, via the I2C protocol and the defined register set, to enable the various functions that the TCS3471 is capable of performing - see the Testing/Experimental Results Section for code.


Note: Image loading can be slow depending on server load.

  • TCS3471 Basic SchematicTCS3471 Basic Schematic

    Silver Membership registration gives access to full resolution schematic diagrams.

    TCS3471 Basic Schematic

This project did not require a PCB.

The construction was done using prototyping board for testing and developing the TCS3471 firmware. See the photographs and schematic diagram sections.

Since the TCS3471 is supplied as a dual flat no-lead (FN) package, a DIY breakout board was made to facilitate use on standard breadboard (2.54mm pitch).

DIY breakout board

See the Photographs Section for more details.

Qty Schematic Part-Reference Value Notes/Datasheet
Resistors
1R1,R410K1/4W, 10% 
1R2100 ohm1/4W, 10% 
1R32.2K1/4W, 10% 
1R5,R64.7K1/4W, 10% 
Capacitors
2C1,C222pFcermaic
2C30.33uFcermaic
2C40.1uFcermaic
2C5-C101uFelectrolytic
Diodes
2D11N4002small signal
Integrated Circuits
1U1PIC18F248PIC microcontroller   datasheet
1U2LM7805Linear Voltage Regulator  datasheet
1U3TL431Programmable Shunt Voltage Ref.  datasheet
1U4TCS3471Color Light-to-Digial Converter  datasheet
1U5MAX232RS232 line driver/receiver   datasheet
Miscellaneous
1J1CONN-H55-pin connector for ICSP
1P1CONN9-pin connector for RS232
1SW1SW-SPDT 
1X110MHzCrystal Oscillator
Description Downloads
TCS3471 - Bill of Materials Text File Download

The testing of the TCS3471 predominantly involved coding the various routines to interact with the TCS3471 state machine via the defined register set/commands. On power-up the various registers of the TCS3471 are mostly 0x00 (as per table 1 of the datasheet) except for register 0x01 and 0x03 (which are 0xFF) and register 0x12 which has the device ID (0x14 for the TCS34715 being used in this case). The default power-up register values give a convenient test, upon being read/downloaded from the TCS3471, showing if the I2C interface/PIC routines are operating correctly.

For example, the TCS3471_Connected() routine reads the contents of the TCS3471 register 0x12 (the 'ID Register') and if the returned value is equal to 0x14, returns TRUE. The other C code routines for the PIC microcontroller, and how to interact/control the TCS3471, are discussed below.

PIC Microcontroller Interface Code

The PIC micrcontroller code is based upon the code provided by TAOS/AMS (1). The code has been modified to compile with the CCS C compiler, targeting specifically the TCS34715 part, and enabling interaction with PIC via RS232.

The header file contains various #define's used to specify the TCS3471 command set, control constants and the following functions:


void TCS3471_Write(int regAddr, int dataByte);  
     // write data to a TCS3471 command register.               
int TCS3471_Read(int regAddr);
	// read data from a TCS3471 register
int16 TCS3471_Read_ColorReg(int regAddr);
	// returns a 16bit value from one of the registers containing data
    // corresponding to a particular color channel (R,G,B or C).                   
void TCS3471_clearInterrupt()
	// clears the RGBC interrupt
int TCS3471_Connected();
	// returns TRUE if value 0x14 found in TCS3471 ID Register
void TCS3471_Init();
	// sets a 'default' TCS3471 integration time 700ms, wait time 1.2 sec   
int checkCommand();
	// RS232 communication with PIC to receive commands from PC for TCS3471
void TCS3471_Read_Photodiodes();
	// read the current value of each TCS3471 photodiodes (C,R,G,B) and
    // output to PC via RS232     
void main();
	// continously polls for following commands from PC via RS232:
    // cmd '1' - check comms, TCS3471 connected
    // cmd '2' - write received data to TCS3471 register
    // cmd '3' - read TCS3471 register, send to PC via RS232
    // cmd '4' - 'single' read of photodiode values, send to PC
    // cmd '5' - start continous readings of photodiode values, send to PC
    // cmd '6' - stop continous readings of photodiode values.    
	// note a VB coded PC application enables the RS232 comms
			

Visual Basic/PC Interface

A Visual Basic application was developed to facilitate communication/control of the TCS3471 via a PC connected to the PIC/TCS3471 by RS232. The following screen-shots of the interface show the functionality possible.

  • Screen Shot 1: TCS3471 Configure

    Screen Shot 1: TCS3471 ConfigureScreen Shot 1: TCS3471 Configure

    Silver Membership registration gives access to full resolution diagrams.

    Screen Shot 1: TCS3471 Configure

  • Screen Shot 2: RS232 communications setup

    Screen Shot 2: RS232 communications setupScreen Shot 2: RS232 communications setup

    Silver Membership registration gives access to full resolution diagrams.

    Screen Shot 2: RS232 communications setup

  • Screen Shot 3: TCS3471/Stepper Motor Control

    Screen Shot 3: TCS3471/Stepper Motor ControlScreen Shot 3: TCS3471/Stepper Motor Control

    Silver Membership registration gives access to full resolution diagrams.

    Screen Shot 3: TCS3471/Stepper Motor Control

    The left-hand panel "Manual Reading" enables direct control of the TCS3471 to download photodiode values and or start continous readings which can be logged to a text datafile. Additionally, a scrolling graph is displayed of the recorded values.

    The right-hand panel provides additional functionality to control a stepper motor, which was being used inconjunction with the TCS3471 for a DIY spectrophotometer project.

I don't have the facility to test the TCS3471 with known intensity of light at various wavelengths. However, illuminating the TCS3471 with the output from a WS2812 RGB LED, using various color combinations and intensities, resulted in the TCS3471 reporting the correct color channel, and recorded channel counts increased and or decreased as expected.

The DIY spectrophotometer project provides some additional data for the TCS3471, in which a "DVD diffraction grating" is used with a 1W white LED light source (and stepper motor for angle control) to produce a colour spectrum, of which the intensity was measured with the TCS3471.

Downloads

Description Downloads
TCS3471 header file: CCS C Source Code Download
Example PIC code with PIC18F248/VB PC program control/interface: CCS C Source Code Download
Hex Code Download

The actual circuit to connect the TCS3471 is straight forward (see Schematics Section) - note that a 3V supply is required for the TCS3471.

The major difficulty in the DIY situation is the small size of the FN package. For initial testing purposes, it is possible to hand solder on leads to enable connection to breadboard for prototyping (see Photographs Section).

Since the TCS3471 is supplied as a dual flat no-lead (FN) package, a DIY breakout board was made to facilitate use on standard breadboard (2.54mm pitch).

DIY breakout board

PCB Manufacture

Standard copper clad board was polished to remove surface oxidation/tarnish and then coated with negative photo-resist ("blue paint"). The negative photo-resist paint was diluted 1:1 with amyl acetate, spread evenly across the copper clad board, dried initially with a hair-dryer, and then allowed to dry over-night in the dark.

The PCB artwork was printed onto a transparency film using a dot matrix printer. The printed side of the transparency is placed against the photo-resist covered copper clad board.

The copper clad board with mask was then exposed to UV light for 2 minutes. See DIY UV light-box.

After UV exposure, the board was "developed" in a solution of sodium bicarbonate (1gm / 100mls). The portions of the photo-resist that were NOT exposed to the UV-light wash away, leaving the copper clad that is to be removed during the etching step.

Cupric chloride (formed in a "bath" of hydrochloric acid solution and copper sulphate with some peroxide) is used to etch the copper that is to be removed from the PCB.

After the etching step, the photo-resist ("blue mask") is removed by soaking in sodium hydroxide solution (10gm "draino" in 100ml water).

The PCB is now ready for use. While not definitely required, I then "tin" the PCB using stannous chloride solution. This "tinning" prevents the copper PCB traces from oxidation and makes soldering easier.

See the Photographs Section which show pictorial record of these steps.

Note: Image loading can be slow depending on server load.

Album 1: Breadboard testing.

Album 2: DIY Breakout board manufacture

Comments/Questions

No comments yet.

Add Comment/Question

Only Logged-In Members can add comments

"If we could sell our experiences for what they cost us, we'd all be millionaires".

Please donate any amount to help with hosting this web site.

If you subscribe (only $2/annum) you can view the site without advertisements and get emails abouts updates etc.

X

Sorry!

Only logged-in users with correct Membership Level can download.


Membership starts at only $2, so join now!