Humidity and Temperature Sensor Pmod Controller (VHDL)

Logic Home

Code Downloads

Humidity and Temperature Sensor Pmod Controller (top level file): pmod_hygrometer.vhd (15.1 KB)

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

Features

  • VHDL source code of a streamlined interface to Digilent’s Pmod HYGRO (Pmod for Texas Instruments’ HDC1080 hygrometer)
  • Continually outputs latest relative humidity and temperature data on parallel interfaces
  • Handles I2C communication and all data retrieval from the Hygrometer Pmod
  • Handles configuration of the hygrometer’s acquisition mode, humidity resolution, and temperature resolution
  • User selectable relative humidity resolution and temperature resolution
  • Configurable system clock rate

Introduction

This details a VHDL component that handles interfacing an FPGA to Digilent’s Digital Humidity and Temperature Sensor (Hygrometer) Pmod, shown in Figure 1. Figure 2 illustrates a typical example of this Hygrometer Pmod Controller integrated into a system. As shown, the Hygrometer Pmod Controller connects to the Pmod ports and executes transactions to configure the Pmod and gather data. The relative humidity data and temperature data are continually updated and presented on simple parallel interfaces.

hygrometer_pmod

Figure 1. Digilent Hygrometer Pmod

Figure 2. Example Implementation

Theory of Operation

The Hygrometer 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 configure state, where it sets the hygrometer’s acquisition mode to measure both humidity and temperature and sets the resolution of hygrometer’s relative humidity and temperature measurements. In the initiate state, it triggers a measurement by executing a pointer write transaction, setting the hygrometer’s address pointer to 0x00. The pause state implements a pause equal to the time necessary for the hygrometer to complete both the temperature and humidity measurements in sequence. In the following read_data state, the controller retrieves the measurement results from the Pmod. Finally, it outputs the data in the output_result state. It then continuously cycles between the initiate, pause, read_data and output_result states to keep the humidity and temperature data updated. Although not shown in the state diagram, resetting the component at any time returns it to the start state.

state_diagram

Figure 3. State Diagram

I2C Master

During the configure, initiate, and read_data states, the state machine controls an I2C Master component to communicate with the HDC1080 hygrometer on the Pmod. Documentation for the I2C Master is available here.

Configuring the Hygrometer Pmod Controller

The Hygrometer 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 Hygrometer Pmod Controller on its clk port.

Humidity Resolution

The generic parameter humidity_resolution sets the resolution of the relative humidity measurements and the data width of the relative_humidity output. Valid options are 8, 11, and 14 bits. The default is 14 bits. Setting humidity_resolution to any invalid value also results in a resolution of 14 bits.

The duration for the humidity measurement depends upon the resolution, so this value also affects the frequency at which the output data updates. The measurement times for each resolution are provided in Table 1.

Table 1. Humidity Measurement Times

humidity_measurement_times

Temperature Resolution

The generic parameter temperature_resolution sets the resolution of the temperature measurements and the data width of the temperature output. Valid options are 11 and 14 bits. The default is 14 bits. Setting temperature_resolution to any invalid value also results in a resolution of 14 bits.

The duration for the temperature measurement depends upon the resolution, so this value also affects the frequency at which the output data updates. The measurement times for each resolution are provided in Table 2.

Table 2. Temperature Measurement Times

temperature_measurement_times

Port Descriptions

Table 3 describes the Hygrometer Pmod Controller’s ports.

Table 3. Port Descriptions

Connections

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

Table 4. Hygrometer Pmod Pinout and Connections to the Hygrometer Pmod Controller

The Pmod also has two jumpers. These must be enabled (i.e. connected) to connect the required I2C pull-up resisters for SCL and SDA.

Reset

The reset_n input port must have a logic high for the Hygrometer 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 relative_humidity and temperature data outputs and the i2c_ack_err output. Once released from reset, the Hygrometer Pmod Controller restarts its operation. It reconfigures the Pmod and resumes collecting and outputting relative humidity and temperature data.

Conclusion

This Hygrometer Pmod Controller is a programmable logic component that interfaces to Digilent’s Pmod HYGRO (Digital Humidity and Temperature Sensor Pmod). It handles all communication with this Pmod to configure the Pmod’s acquisition mode and data resolutions and to provide a continual stream of updated relative humidity data and temperature data on parallel outputs.

Related Topics

I2C Master (VHDL)