Child pages
  • Color Sensor Pmod Controller (VHDL)
Skip to end of metadata
Go to start of metadata

Code Download

Color Sensor Pmod Controller (top level file):  pmod_color_sensor.vhd

I2C Master (must be included in project):  i2c_master.vhd

Features

  • VHDL source code of a streamlined interface to Digilent’s PmodCOLOR (Pmod for AMS’s TCS3472 Color Light-to-Digital Converter)
  • Continually outputs latest light and color data on 4 parallel interfaces
  • Handles I2C communication and all data retrieval from the Color Sensor Pmod
  • Handles configuration of the color light-to-digital converter’s gain and atime parameters
  • User definable gain and atime
  • Configurable system clock rate

Introduction

This details a VHDL component that handles interfacing an FPGA to Digilent’s Color Sensor Pmod, shown in Figure 1.  Figure 2 illustrates a typical example of this Color Sensor Pmod Controller integrated into a system.  As shown, the Color Sensor Pmod Controller connects to the Pmod ports and executes transactions to configure the Pmod and gather data.  The data is continually updated and presented on 4 simple parallel interfaces, corresponding to the clear, red, green, and blue data values.

Figure 1.  Digilent Color Sensor Pmod


Figure 2.  Example Implementation

Theory of Operation

The Color Sensor Pmod Controller consists primarily of a state machine and an I2C Master component.

State Machine

The design uses the state machine depicted in Figure 3 to implement its operation.  Upon start-up the component immediately enters the start state.  It remains in this state for 100ms to ensure the Pmod has ample time to power-up.  It then proceeds to the set_gain state, where it configures the gain of the ADCs within the TCS3472 color light-to-digital converter.  Once complete, it enters the set_atime state to configure the integration time of these ADCs.  It finishes the initialization sequence in the set_pon_aen state.  Here, it sets the Power ON bit (PON) to activate the internal oscillator and also sets the ADC Enable bit (AEN) to activate the ADCs.  The pause state implements a 2.4ms pause to give the Pmod time to gather data and update the data registers.  In the following read_data state, the controller gathers the most recent light and color data from the Pmod.  Finally, it outputs the data in the output_result state.  It then continuously cycles between the pause, read_data and output_result states to keep the light and color data updated.  Although not shown in the state diagram, resetting the component at any time returns it to the start state.

Figure 3.  State Diagram

I2C Master

During the set_gain, set_atime, set_pon_aen, and read_data states, the state machine controls an I2C Master component to communicate with the TCS3472 color light-to-digital converter on the Pmod.  Documentation for the I2C Master is available here.

Configuring the Color Sensor Pmod Controller

The Color Sensor Pmod Controller is configured by setting the generic parameters in the entity.

System Clock Frequency

The generic parameter sys_clk_freq must be set to the frequency of the system clock provided to the Color Sensor Pmod Controller on its clk port.

Gain

The generic parameter gain sets the analog gain of the four ADCs that read the photodiodes in the TCS3472 color light-to-digital converter.  This value can be adjusted to improve the accuracy of the color and light measurements for various lighting conditions.  Valid gain values are 1, 4, 16, and 60.  If any other value is assigned, the color sensor is configured with a default gain value of 1.

Integration Time

The generic parameter atime sets the integration time of the four ADCs that read the photodiodes in the TCS3472 color light-to-digital converter.  The integration time affects both the resolution and sensitivity of the reading and can range from 2.4ms to 614ms.  The parameter atime is a 2’s compliment value and is calculated from the desired integration time as shown in Equation 1.

See the top of page 15 in the TCS3472 datasheet for more details.

Port Descriptions

Table 1 describes the Color Sensor Pmod Controller’s ports.

Table 1.  Port Descriptions

Port

Width

Mode

Data Type

Interface

Description

clk

1

in

standard logic

user logic

System clock

reset_n

1

in

standard logic

user logic

Asynchronous active low reset

scl

1

inout

standard logic

Color Sensor Pmod

Serial clock of I2C bus

sda

1

inout

standard logic

Color Sensor Pmod

Serial data of I2C bus

i2c_ack_err

1

out

standard logic

user logic

I2C communication error flag: '0' = no communication error, '1' = the Color Sensor Pmod did not properly acknowledge a transaction

clear

16

out

standard logic vector

user logic

Clear color data

red

16

out

standard logic vector

user logic

Red color data

green

16

out

standard logic vector

user logic

Green color data

blue

16

out

standard logic vector

user logic

Blue color data

Connections

This Pmod has a 6-pin connector.  Table 2 provides the pinout for this connector.  The Color Sensor Pmod Controller’s ports need to be assigned to the FPGA pins that are routed to this connector as listed.

Table 2.  Color Sensor Pmod Pinout and Connections to Color Sensor Pmod Controller

Pmod Pin Number

Color Sensor Pmod Port

Color Sensor Pmod Controller Port

1

IO1/INT

-

2

IO2/LED_EN

-

3

SCL

scl

4

SDA

sda

5

GND

-

6

VCC

-

The Pmod also has several jumpers.  JP1 and JP2 must be enabled (i.e. connected) to connect the required I2C pull-up resisters for SCL and SDA.  JP3 and JP4 do not affect the Color Sensor Pmod Controller’s operation.

Reset

The reset_n input port must have a logic high for the Color Sensor Pmod Controller component to operate.  A low logic level on this port asynchronously resets the component.  During reset, the component aborts the current transaction with the Pmod and clears the clear, red, green, and blue data outputs and the i2c_ack_err output.  Once released from reset, the Color Sensor Pmod Controller restarts its operation.  It reconfigures the Pmod and resumes collecting and outputting light and color data.

Conclusion

This Color Sensor Pmod Controller is a programmable logic component that interfaces to Digilent’s PmodCOLOR (Color Sensor Pmod).  It handles all communication with this Pmod to configure the Pmod’s color light-to-digital converter and provide a continual stream of updated light and color data on parallel outputs.

Related Topics

I2C Master (VHDL)

Contact

Comments, feedback, and questions can be sent to eewiki@digikey.com.

  • No labels