Reader small image

You're reading from  FPGA Programming for Beginners

Product typeBook
Published inMar 2021
Reading LevelIntermediate
PublisherPackt
ISBN-139781789805413
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Frank Bruno
Frank Bruno
author image
Frank Bruno

Frank Bruno is an experienced high-performance design engineer specializing in FPGAs with some ASIC experience. He has experience working for companies like SpaceX, GM Cruise, Belvedere Trading, Allston Trading, and Number Nine. He is currently working as an FPGA engineer for Belvedere Trading.
Read more about Frank Bruno

Right arrow

Chapter 5: FPGA Resources and How to Use Them

In this chapter, we are going to take a look at some of the underlying FPGA resources in more detail. You've been introduced to some of these in brief, such as Random Access Memories (RAMs) and DSP blocks, while others have been glossed over, such as PLLs, where we used one to fix a timing problem in our calculator design. We'll build upon our previous experience by incorporating these new resources.

By the completion of this chapter, you'll have a good idea of how to interface with external components. You'll be introduced to a few different data formats, pulse width modulation, and pulse data modulation. You'll see a simple serial bus in action, i2c, as well as how to implement storage in the form of a FIFO.

In this chapter, we are going to cover the following main topics:

  • What is a PDM microphone?
  • Simulating the microphone
  • Introducing storage
  • Handling i2c temperature sensor data
  • ...

Technical requirements

The technical requirements for this chapter are the same as those for Chapter 1, Introduction to FPGA Architectures and Xilinx Vivado.

To follow along with the examples and the project, you can find the code files for this chapter at the following repository on GitHub: https://github.com/PacktPublishing/Learn-FPGA-Programming/tree/master/CH5.

Project 5 – Listening and learning

This project requires the microphone on the Nexys A7 board. To run this on the Basys 3 board, an additional pmod microphone needs to be installed, interfaced, and the XDC file modified accordingly.

The Nexys A7 board has a digital microphone on board that we can use to capture the ambient noise, speech, and suchlike from the environment the board is in. We'll be utilizing this microphone to capture sound. In order to do that, we'll need to explore the format of the data and how to sample it.

It's also possible to play it back.

What is a PDM microphone?

A digital microphone needs to take analog audio data and convert it to digital data usable by electronics. A Pulse Density Modulation (PDM) signal is captured by a 1-bit DAC that encodes its output as a string of pulses. When the pulses are denser over a period of time, they represent larger values. In Figure 5.1, we see a signal from the testbench as a sine wave. The...

Project 6 – Using the temperature sensor

The Nexys A7 board has an Analog Device ADT7420 temperature sensor. This chip uses an industry-standard I2C interface to communicate with. This two-wire interface is used primarily for slower speed devices. It has the advantage of allowing multiple chips to be connected through the same interface and be addressed individually. In our case, we will be using it to simply read the current temperature from the device and display the value on the 7-segment display.

Our first step will be to design an I2C interface. In Chapter 7, Introduction to AXI, we'll be looking at designing a general-purpose I2C interface, but for now, we'll use the fact that the ADT7420 comes up in a mode where we can get temperature data by reading two locations. First, let's take a look at the timing diagram for the I2C bus and the read cycle we'll be using:

Figure 5.10 – I2C timing

We can see from the timing...

Summary

In this chapter, we've explored how to do some simple communication with the outside world. We've gathered microphone data, stored it, and played it back. We've also explored the I2C bus, a common way of communicating with slower speed devices. We captured temperature data and showed how we could display a fixed-point number on the 7-segment display. We introduced FIFOs and discussed how we can filter the data to remove the noisiness of the temperature data varying.

I2C interfaces are used to communicate with many low speed devices such as A/Ds and D/As and are very important for a lot of FPGA designs. You should feel comfortable that you can do it at this point, and we will explore making a more generic version of the interface in a later chapter. If you are interested in audio data, you should have some confidence in capturing, manipulating, and generating audio.

In the next chapter, we are going to look at some mathematical operations. We'll explore...

Questions

  1. What are the advantages of an I2C bus?

    a) We can move large amounts of data quickly.

    b) We only need two wires to communicate.

    c) Multiple devices can be connected using only two wires.

    d) All of the above.

    e) Only (b) and (c).

  2. What would be the preferred order of preference when you require a memory?

    a) Use the IP catalog, infer, use xpm_memory

    b) Use xpm_memory, use the IP catalog, infer

    c) Infer, use xpm_memory, use the IP catalog

    d) Use the IP catalog, use xpm_memory, infer

  3. assign data = (data_en) ? 'z : '0;

    a) Infers a multiplier

    b) Infers a register

    c) Infers a tristate IO

  4. Gray coding is used in FIFOs.

    a) Always

    b) To pass counter information across clock domains in an asynchronous FIFO

    c) Only in synchronous FIFOs

The following code creates what kind of memory?

always @(posedge clk) begin
  if (wren) store[addr] <= din;
  dout <= store[addr];
end

a) Simple dual port

b) True dual port

c) Single port

d) ROM

...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
FPGA Programming for Beginners
Published in: Mar 2021Publisher: PacktISBN-13: 9781789805413
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Frank Bruno

Frank Bruno is an experienced high-performance design engineer specializing in FPGAs with some ASIC experience. He has experience working for companies like SpaceX, GM Cruise, Belvedere Trading, Allston Trading, and Number Nine. He is currently working as an FPGA engineer for Belvedere Trading.
Read more about Frank Bruno