Beginning FPGA Programming - Partie57
Beginning FPGA Programming - Partie57
The most important thing is that it provides an I2C slave interface and it is connected to the FPGA pins with
two pull-up resistors. The I2C interfaces for external control and sends out the temperature data. That is all we
need to get the temperature data and control the sensor. Figure 13-13 shows the sensor registers. We are going to
use registers 0x00, 0x01, 0x03, 0x08, and 0x2F. Figure 13-14 shows the binary data mapping to temperature.
277
Chapter 13 ■ Temperature Sensors: Is It Hot in Here, or Is It Just Me?
We will use the quick guide from the ADT7420 datasheet to get the data through I2C and send it back to
the PC.
The following steps are based on the quick guide for reading temperatures from the ADT7420:
1.
After powering up the ADT7420, verify the setup by reading the device ID from
the address 0x0B. It should be 0xCB.
2.
Write to configuration register address 0x03 with value 0x80. This will set up the
ADC and provide 13-bit data.
3.
Read the temperature value MSB register from address 0x00 and read the
LSB register from address 0x01. This should provide us with the temperature
measurement. If the data read-back is 0x190, then the temperature is 25°C.
These three steps will be translated to a UART command and sent from the PC to the BeMicro Max 10
board. Since the ADT7420 temperature sensor works as an I2C slave/receiver device, we will use the I2C
master to send the commands to the sensor. In the next section we will download another IP which is also
an I2C slave from another web site. It is only used for simulation. We need the I2C slave IP to simulate the
temperature sensor.
13.3.4 I2C Slave
For simulation, we need to have an I2C Slave to work and look like the ADC I2C interface. We found an
easy-to-use one from GitHub. It is really surprising to us that GitHub hosted VHDL (VHSIC (very high
speed integrated circuit) Hardware Description Language) code hosted on it! The following note shows the
download link. We need to use a specific revision from GitHub. Don’t download the master version.
We only need one file—I2C_slave.vhd—from GitHub. Figure 13-15 shows the web site screenshot and
the port list of the I2C slave module.
278
Chapter 13 ■ Temperature Sensors: Is It Hot in Here, or Is It Just Me?
The port list in Figure 13-16 has scl and sda. They form the I2C interface and the user interface as a
simple read/write register interface. Figure 13-16 shows the port list of the I2C slave module. We will set the
SLAVE_ADDR to 0x48 in the simulation which is the exact address used by ADT7420. The user interface section
shows the read or write operation from the master with the data in or out.
279
Chapter 13 ■ Temperature Sensors: Is It Hot in Here, or Is It Just Me?
Give the PLL the name pll_29p5M (see Figure 13-18) and select VHDL. In the MegaWizard of the PLL
(Figure 13-19), execute the following steps
1.
In the first tab (General/Mode), set the inclk0 equal to 50 MHz (Figure 13-19).
2.
In the first tab (Inputs/Lock), uncheck the Create an "areset" input to
asynchronously reset the PLL (Figure 13-20).
3.
In the third tab (clk c0), enter the output clock frequency request to 29.5 MHz
(Figure 13-21).
4.
Click Finish two times; then you should have your PLL IP.
280
Chapter 13 ■ Temperature Sensors: Is It Hot in Here, or Is It Just Me?
Figure 13-20. Uncheck the Create an "areset" input to asynchronously reset the PLL
281