# Temperature Sensor TCN75A Pmod Controller (VHDL)

**URL:** <https://forum.digikey.com/t/temperature-sensor-tcn75a-pmod-controller-vhdl/13178>\
**Category:** Logic Design\
**Tags:** development-boards-kits-programmers, evaluation-boards, digilent-inc, tech-tips\
**Created:** [March 30, 2021, 7:05pm UTC](https://forum.digikey.com/t/temperature-sensor-tcn75a-pmod-controller-vhdl/13178 "2021-03-30T19:05:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott\_1767](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@Scott\_1767](https://forum.digikey.com/u/Scott_1767)\
**Post date:** [March 30, 2021, 7:05pm UTC](https://forum.digikey.com/t/temperature-sensor-tcn75a-pmod-controller-vhdl/13178/1 "2021-03-30T19:05:59Z")

</div>

[Logic Home](https://forum.digikey.com/t/logic-home-table-of-contents/12507)

 

# Code Downloads

Temperature Sensor Pmod Controller (top-level file): [pmod\_temp\_sensor\_tcn75a.vhd](https://forum.digikey.com/uploads/short-url/gI54IxvE02eBYBoPHyKs2Ko4PzT.vhd) (11.7 KB)

I2C Master (must also be included in the project): [i2c\_master.vhd](https://forum.digikey.com/uploads/short-url/eTzT1qKMVrvoZN2gh0DFKWRg0kQ.vhd) (14.1 KB)

# Features

- VHDL source code of a streamlined interface to [Digilent’s PmodTMP3](https://www.digikey.com/products/en?keywords=1286-1136-ND%20) (Pmod for Microchip’s [TCN75A](https://www.digikey.com/products/en/sensors-transducers/temperature-sensors-analog-and-digital-output/518?k=TCN75A) Temperature Sensor)
- Continually outputs latest temperature data on a parallel interface
- Handles I2C communication and all data retrieval from the Temperature Sensor Pmod
- Handles configuration of the temperature sensor’s resolution
- Configurable system clock rate

# Introduction

This details a VHDL component that handles interfacing to Digilent’s Temperature Sensor TCN75A Pmod, shown in Figure 1. Figure 2 illustrates a typical example of this Temperature Sensor Pmod Controller integrated into a system. As shown, the Temp Sensor Pmod Controller connects to the Pmod ports and executes transactions to configure the temperature sensor and gather data. The data is continually updated and presented on a simple parallel interface which can be connected to user logic or to output ports on the FPGA.

 ![temp_sensor_pmod](https://global.discourse-cdn.com/digikey/original/2X/1/1d38077661c9cd324e32c8e1a2246878f05cc6fa.jpeg)

**Figure 1.** Digilent Temperature Sensor TCN75A Pmod

 ![block_diagram](https://global.discourse-cdn.com/digikey/original/2X/f/f16b65a3c8fd2691b4d0b56c889fb616699d09b6.png)

**Figure 2.** Example Implementation

# Theory of Operation

The Temperature 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\_resolution_ state, where it configures the temperature sensor’s resolution. Once complete, it enters the _set\_reg\_pointer_ state to set up the temperature sensor for data readings. In the following _read\_data_ state, it gathers the most recent temperature data from the Pmod’s temperature sensor. Finally, it outputs the temperature in the _output\_result_ state. It then continuously cycles between the _read\_data_ and _output\_result_ states to keep the temperature data constantly updated. Resetting the component at any time returns it to the _start_ state.

 ![state_diagram](https://global.discourse-cdn.com/digikey/original/2X/b/bb8eae1c2f40aa6bdd3b0b0f1de5940f9bdb5c4e.jpeg)

**Figure 3.** State Diagram

## I2C Master

During the _set\_resolution_, _set\_reg\_pointer_, and _read\_data_ states, the state machine controls an I2C Master component to communicate with the temperature sensor on the Pmod. Documentation for the I2C Master is available [here](https://www.digikey.com/eewiki/pages/viewpage.action?pageId=10125324).

# Configuring the Temp Sensor Pmod Controller

The Temp 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 Temp Sensor Pmod Controller on its _clk_ port.

## Resolution

The generic parameter _resolution_ defines the resolution (in bits) with which the TCN75A temperature sensor is then configured. Table 1 describes the options and tradeoffs. The default value is 9 bits of resolution. Any invalid resolution setting reverts to 9 bits.

**Table 1.** Resolution Options

 ![resolution_options](https://global.discourse-cdn.com/digikey/original/2X/a/a08051e963b26c2d3d8007f7789b07163a437a9e.jpeg)

## Pmod I2C Address

The Temp Sensor Pmod Controller must have the Pmod’s 7-bit I2C address to communicate. The 4 most significant bits are “1001” and the following 3 bits are set by the Pmod’s jumper blocks JP3, JP2, and JP1, respectively.

The generic parameter _temp\_sensor\_addr_ must be set to this address. The default value “1001000” corresponds to all 3 jumpers connected to GND.

# Port Descriptions

Table 2 describes the Temp Sensor Pmod Controller’s ports.

**Table 2.** Port Descriptions

 ![port_descriptions](https://global.discourse-cdn.com/digikey/original/2X/d/d5cd714d7df131b375d744438e8557ae440536fe.jpeg)

# Connections

This Pmod has an 8-pin connector. Table 3 provides the pinout for this connector. The Temp Sensor Pmod Controller’s ports need to be assigned to the FPGA pins that are routed to this connector as listed. The two rows of the J1 connector are tied together on the Pmod board, so only one side needs to be connected to the FPGA.

**Table 3.** Temp Sensor Pmod Pinout and Connections to the Temp Sensor Pmod Controller

 ![connections](https://global.discourse-cdn.com/digikey/original/2X/c/c7f2cf0ec992011c852f809b9b16f3984370421b.jpeg)

The Pmod also has several jumpers. JP4 and JP5 must be enabled (i.e. connected) to connect the required I2C pull-up resisters for SCL and SDA. JP6 is not used. JP1, JP2, and JP3 set the I2C address of the Pmod. See the Pmod I2C Address section above for details.

# Reset

The _reset\_n_ input port must have a logic high for the Temperature 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 _temperature_ data output and the _i2c\_ack\_err_ output. Once released from reset, the Temperature Sensor Pmod Controller restarts its operation. It reconfigures the temperature sensor and resumes collecting and outputting temperature data.

# Conclusion

This Temperature Sensor Pmod Controller is a programmable logic component that interfaces to Digilent’s PmodTMP3 (Temperature Sensor TCN75A Pmod). It handles all communication with this Pmod to configure the Pmod’s temperature sensor and provide a continual stream of updated temperature data on a parallel output.

# Additional Information

[Microchip TCN75A datasheet](https://forum.digikey.com/uploads/short-url/vReRlhiZgCbUJvLrVDmedw8HFB7.pdf) (498.7 KB)

# Related Topics

[I2C Master (VHDL)](https://www.digikey.com/eewiki/pages/viewpage.action?pageId=10125324)
