Child pages
  • Thermocouple Pmod Controller (VHDL)

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Code Downloads

Thermocouple Pmod Controller (top level file):  pmod_thermocouple.vhd

SPI Master (must be included in the project):  spi_master.vhd

Features

  • VHDL source code of a streamlined interface to Digilent’s Thermocouple Pmod (PmodTC1)
  • Continually outputs the latest thermocouple data, reference junction temperature data, and fault bits on parallel interfaces
  • Handles SPI communication and all data retrieval from the Thermocouple Pmod
  • Configurable system clock rate

Introduction

This details a VHDL component that handles interfacing to the Digilent’s Thermocouple Pmod, shown in Figure 1.  Figure 2 illustrates a typical example of this Thermocouple Pmod Controller integrated into a system.  As shown, the Thermocouple Pmod Controller connects to the Pmod ports and executes transactions to secure thermocouple temperature data, internal junction temperature data, and fault bits.  The data is then presented on simple parallel interfaces which can be connected to user logic or to output ports on the FPGA.


Figure 1.  Digilent Thermocouple Pmod TC1


Figure 2.  Example Implementation

Background

The Thermocouple Pmod uses Maxim Integrated's MAX31855 to digitize the signal from a K-type thermocouple and provide a reference junction temperature for compensation.  The measured thermocouple temperature is 14 bits, with a 0.25ºC resolution.  The reference junction temperature is 12 bits, with 0.0625ºC resolution.

Theory of Operation

The Thermocouple Pmod Controller consists primarily of a state machine and an SPI Master component.

State Machine

The design uses the simple 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 300ms to ensure the Pmod has ample time to power-up and complete the first temperature conversion.  It then proceeds to the get_datastate, where it initiates an SPI transaction with the Pmod to retrieve the conversion results.  Once the transaction begins, the component enters the pause state.  Here, it outputs the received information on the tc_temp_data, junction_temp_data, and ­fault_bits ports when it becomes available.  Once the 100ms conversion period has elapsed, the component returns to the get_data state to initiate the next data retrieval transaction.  Although not shown in the state diagram, resetting the component at any time returns it to the start state.

Figure 3.  State Diagram

SPI Master

The state machine controls an SPI Master component to communicate with the MAX31855 converter on the Pmod.  The SPI Master is configured with CPOL = 0 and CPHA = 0, to meet the requirements of the MAX31855.  Complete documentation for the SPI Master component is available here.

Configuring the Clock

The clocking of this Thermocouple Pmod Controller is configured by assigning values to the GENERIC parameters clk_freq and spi_clk_div, defined in the ENTITY.  The parameter clk_freq must be set to the frequency (in MHz) of the provided system clock clk.  Equation 1 defines how spi_clk_div is calculated.

where fclk is the frequency of the provided system clock in MHz.  The system clock is provided on the clk input port.

Equation 2 defines the SPI clock frequency fsclk that results.

This calculation keeps the SPI clock at or near the MAX31855’s maximum specified serial communication frequency of 5 MHz (without exceeding it).

Port Descriptions

Table 1 describes the Thermocouple Pmod Controller’s ports.  Data formats and detailed descriptions of the outputs are described below.

Table 1.  Port Descriptions

Port

Width

Mode

Data Type

Interface

Description

clock

1

in

standard logic

user logic

System clock

reset_n

1

in

standard logic

user logic

Asynchronous active low reset

miso

1

in

standard logic

Thermocouple Pmod

Master in, slave out data line

sclk

1

buffer

standard logic

Thermocouple Pmod

Serial clock

ss_n

1

buffer

standard logic vector

Thermocouple Pmod

Slave select signal

tc_temp_data

14

out

standard logic vector

user logic

Thermocouple temperature data

junction_temp_data

12

out

standard logic vector

user logic

Reference junction temperature data

fault_bits

4

out

standard logic vector

user logic

Fault detection indicators

Thermocouple Temperature Data

The tc_temp_data port outputs the 14-bit thermocouple temperature data.  The data is formatted in 2’s compliment with a resolution of 0.25ºC per bit.

Junction Temperature Data

The junction_temp_data port outputs the 12-bit reference junction temperature data.  The data is formatted in 2’s compliment with a resolution of 0.0625ºC per bit.

Fault Bits

Table 2 defines the outputs on the fault_bits bus.

Table 2.  Fault Bits

Bit

Name

Description

fault_bits(3)

Fault

0: No detected fault; 1: detected fault on any of SCV, SCG, or OC

fault_bits(2)

SCV Fault

0: No detected fault; 1: thermocouple is short-circuited to Vcc

fault_bits(1)

SCG Fault

0: No detected fault; 1: thermocouple is short-circuited to GND

fault_bits(0)

OC Fault

0: No detected fault; 1: thermocouple is open (no connections)

Connections

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

Table 3.  TC1 Pmod Pinout and Connections to Thermocouple Pmod Controller

Pmod Pin Number

TC1 Pmod Port

Thermocouple Pmod Controller Port

1

chip select (CS)

ss_n

2

no connect (NC)

-

3

master in, slave out (MISO)

miso

4

serial clock (SCLK)

sclk

5

GND

-

6

VCC

-

Reset

The reset_n input port must have a logic high for the Thermocouple 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 Thermocouple Pmod and clears the tc_temp_data, junction_temp_data, and fault_bits outputs.  Once released from reset, the Thermocouple Pmod Controller resumes operation.

Conclusion

This Thermocouple Pmod Controller is a programmable logic component that interfaces to Digilent’s Thermocouple (TC1) Pmod.  It handles all communication with the TC1 Pmod to provide a continual stream of updated thermocouple temperature data, reference junction temperature data, and fault signals on parallel output ports.

Related Topics

Serial Peripheral Interface (SPI) Master (VHDL)

Contact

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