0% found this document useful (0 votes)
19 views

Contents_FPGA_Programming_and_Hardware_Essentials

Uploaded by

latif.dengiz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Contents_FPGA_Programming_and_Hardware_Essentials

Uploaded by

latif.dengiz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

books

books books
books

FPGA Programming and


Hardware Essentials FPGA Programming and

FPGA Programming and Hardware Essentials • Dogan Ibrahim


Kick off with the MAX1000 and VHDPlus

Ready to Master FPGA Programming? In this guide, we’re diving into


the world of Field-Programmable Gate Arrays (FPGAs)—a configurable
Hardware Essentials
integrated circuit that can be programmed after manufacturing. Imagine
bringing your ideas to life, from simple projects to complete microcon- Kick off with the MAX1000 and VHDPlus
troller systems!
Prof. Dr. Dogan Ibrahim holds a
BSc in Electronic Engineering,
Meet the MAX1000: a compact and budget-friendly FPGA development

(m mod 10);
an MSc in Automatic Control
g
if(rising_ed
board packed with features like memory, user LEDs, push-buttons, and
Segment <= N
Engineering, and a PhD in Digital
flexible I/O ports. It’s the ideal starting point for anyone wanting to learn Signal Processing. He has worked
about FPGAs and Hardware Description Languages (HDLs). in various industrial organizations {
before returning to academic life. } (3) = ‚1‘) i <= i +
elsif(digits
In this book, you’ll get hands-on with the VHDPlus programming
language—a simpler version of VHDL. We’ll work on practical projects Prof. Ibrahim is the author of over 70
if(i = 36
);
(m/10 mod 10
technical books and has published
using the MAX1000, helping you gain the skills and confidence to unleash { {
Segment <= N
more than 200 technical articles on
your creativity. microcontrollers, microprocessors, i <=
and related fields. He is a Chartered
} digi
(2) = ‚1‘)
elsif(digits
Get ready for an exciting journey! You’ll explore a variety of projects Electrical Engineer and a Fellow of
that highlight the true power of FPGAs. Let’s turn your ideas into reality the Institution of Engineering and Digi
;
{ /100 mod 10)
Technology. Additionally, he is a
and embark on your FPGA adventure—your journey starts now!
n t < = N ( m }
certified Arduino professional.
Seg m e
}
Exciting Projects You’ll Find in This Book
} (1) = ‚1‘) }
> Arduino-Driven BCD to > Ultrasonic Distance
elsif(digits
00 mod 10);
7-Segment Display Decoder Measurement
> Use an Arduino Uno R4 > Measure distances using an { < = N ( m / 1 0
to supply BCD data to the ultrasonic sensor, display- Segmen t
decoder, counting from 0 to 9 ing the results on a 4-digit }
with a one-second delay. 7-segment LED.
ge(CLK))
if(rising_ed
> Multiplexed 4-Digit Event > Electronic Lock
Counter > Build a simple electronic lock
{
i <= i + 1; )
> Create an event counter that using combinational logic

if(i = 36000
displays the total count on a gates with push buttons and
4-digit display, incrementing an LED output.
> Temperature Sensor {
& digits(3);
with each button press.
> PWM Waveform with Fixed > Monitor ambient tempera- i <= 0; gits(2 d o w n t o 0 )
digits <= di its;
Duty Cycle ture with a TMP36 sensor Elektor International Media

Digit <= dig


> Generate a PWM waveform at and display the readings on a www.elektor.com
1 kHz with a fixed duty cycle 7-segment LED.
of 50%. }

Dogan Ibrahim

SKU21054_FPGA Programming and Hardware Essentials.indd All Pages 30/10/2024 15:36


FPGA Programming and
Hardware Essentials
Kick off with the MAX1000
and VHDPlus

Dogan Ibrahim

FPGA Programming and Hardware Essentials.indd 3 28-10-2024 13:39


● This is an Elektor Publication. Elektor is the media brand of
Elektor International Media B.V.
PO Box 11, NL-6114-ZG Susteren, The Netherlands
Phone: +31 46 4389444

● All rights reserved. No part of this book may be reproduced in any material form, including photocopying, or
storing in any medium by electronic means and whether or not transiently or incidentally to some other use of this
publication, without the written permission of the copyright holder except in accordance with the provisions of the
Copyright Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licencing Agency
Ltd., 90 Tottenham Court Road, London, England W1P 9HE. Applications for the copyright holder's permission to
reproduce any part of the publication should be addressed to the publishers.

● Declaration
The author and publisher have made every effort to ensure the accuracy of the information contained in this book.
They do not assume, or hereby disclaim, any liability to any party for any loss or damage caused by errors or
omissions in this book, whether such errors or omissions result from negligence, accident, or any other cause.
The author expresses his sincere gratitude to Arrow Electronics and Trenz Electronic for granting permission to
include various tables, figures, and program codes in this book.

● ISBN ​978-3-89576-644-2 Print


ISBN 978-3-89576-645-9 eBook

● © Copyright 2024 Elektor International Media


www.elektor.com
Editor: Glaucileine Vieira
Prepress Production: D-Vision, Julian van den Berg
Printers: Ipskamp, Enschede, The Netherlands

Elektor is the world's leading source of essential technical information and electronics products for pro engineers,
electronics designers, and the companies seeking to engage them. Each day, our international team develops and delivers
high-quality content - via a variety of media channels (including magazines, video, digital media, and social media) in
several languages - relating to electronics design and DIY electronics. www.elektormagazine.com

●4

FPGA Programming and Hardware Essentials.indd 4 28-10-2024 13:39


Contents

Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Chapter 1 • Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

1.1 What is a Field Programmable Gate Array (FPGA)? . . . . . . . . . . . . . . . . . . . . . . . 11

1.2 Some popular FPGA development boards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

Chapter 2 • The MAX1000 FPGA Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

2.2 The MAX1000 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

2.2.1 Board Indicator LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

2.2.2 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

2.2.3 Clock Circuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

2.2.4 User LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

2.2.5 Push Buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

2.2.6 Accelerometer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

2.2.7 Arduino Connectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

2.2.8 Pmod Connector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

2.2.9 UART Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

2.2.10 Power supply circuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

Chapter 3 • Software Installation – VHDPlus IDE . . . . . . . . . . . . . . . . . . . . . . . . . 29

3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

3.2 Installing the VHDPlus IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

3.3 Your first program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

3.3.1 Downloading the compiled code to your FPGA . . . . . . . . . . . . . . . . . . . . . . . . . 35

3.3.2 Installing packages and library files to VHDPlus . . . . . . . . . . . . . . . . . . . . . . . . 35

3.3.3 Simulating the program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Chapter 4 • The VHDPlus Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

4.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

4.2 Data types and operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

4.2.1 Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

4.2.2 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

4.3 Binary logical operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

●5

FPGA Programming and Hardware Essentials.indd 5 28-10-2024 13:39


FPGA Programming and Hardware Essentials

4.3.1 Relational operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

4.3.2 Arithmetic operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

4.3.3 Concatenation operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

4.3.4 Shift operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

4.3.5 Type conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

4.4 Declarations, assignments, and constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

4.4.1 Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

4.4.2 Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

4.4.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

4.5 VHDPlus program flow statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

4.5.1 If..Else..Elsif . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

4.5.2 Case and When . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

4.5.3 For . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

4.5.4 While . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

4.5.5 Wait . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

4.5.6 Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

4.6 VHDPlus program template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

4.6.1Main . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

4.6.2 Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

4.6.3 Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

4.6.4 Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

Chapter 5 • Example VHDPlus Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

5.2 Project 1 – Flashing LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

5.3 Project 2 – Two alternately flashing LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

5.4 Project 3 – Using an external LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

5.5 Project 4 – Chasing LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

5.6 Project 5 – Binary counter with LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

5.7 Project 6 - LED with button control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

5.8 Project 7 - LED with External Button Control . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

5.9 Project 8 – Event counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

●6

FPGA Programming and Hardware Essentials.indd 6 28-10-2024 13:39


Contents

5.10 Project 9 – Full adder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

5.11 Project 10 – Multiplexer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

5.12 Project 11 – BCD to seven-segment display decoder . . . . . . . . . . . . . . . . . . . . . 74

5.12.1 Connecting a 7-segment display to the FPGA . . . . . . . . . . . . . . . . . . . . . . . . . 77

5.13 Project 12 – BCD to seven-segment display decoder counter with Arduino Uno R4 79

5.14 Project 13 – 4-bit counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

5.15 Project 14 – 8-bit serial-in parallel-out shift register . . . . . . . . . . . . . . . . . . . . . 84

5.16 Project 15 – Edge triggered D-type flip-flop . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

5.17 Project 16 – Demultiplexer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

5.18 Project 17 – Multiplexed 4-digit 7-segment LED . . . . . . . . . . . . . . . . . . . . . . . . 92

5.19 Project 18 – Multiplexed 4-digit 7-segment LED event counter . . . . . . . . . . . . . . 98

5.20 Project 19 – Multiplexed 4-digit 7-segment LED seconds counter . . . . . . . . . . . 101

5.21 Project 20 – Switch contact debouncing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103

Chapter 6 • Analog-to-Digital Converter (ADC) . . . . . . . . . . . . . . . . . . . . . . . . . . 106

6.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

6.2 MAX1000 analog inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

6.3 Project 1 – Voltmeter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

6.3.1 Extending the input range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

6.4 Project 2 – Temperature sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

6.5 Project 3 – Light dependent resistor (LDR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

Chapter 7 • Serial Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

7.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

7.2 MAX1000 FPGA serial port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

7.3 Project 1 – Controlling the on-board LEDs with serial communication . . . . . . . . . 122

Chapter 8 • Pulse Width Modulation (PWM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

8.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

8.2 Basic theory of the pulse width modulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

8.3 Project 1 – PWM waveform with a fixed-duty cycle . . . . . . . . . . . . . . . . . . . . . . 126

8.4 Project 2 – Mosquito repeller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

8.5 Project 3 – Variable duty cycle – Dimming an LED . . . . . . . . . . . . . . . . . . . . . . 130

Chapter 9 • Ultrasonic Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

●7

FPGA Programming and Hardware Essentials.indd 7 28-10-2024 13:39


FPGA Programming and Hardware Essentials

9.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

9.2 Project 1 – Ultrasonic distance measurement . . . . . . . . . . . . . . . . . . . . . . . . . . 133

Chapter 10 • The I2C Bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140

10.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140

10.2 The I2C bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140

10.3 The I3C bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141

10.4 Differences between the I2C and I3C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141

10.5 Project 1 – Port expander using the I2C bus on MAX1000 FPGA . . . . . . . . . . . . 142

Chapter 11 • The SPI Bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

11.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

11.2 Project 1 – SPI Port expander . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

Chapter 12 • Using LCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

12.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

12.2 HD44780 LCD module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

12.3 Project 1 – Displaying text on LCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159

Chapter 13 • Programming in VHDL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165

13.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165

13.2 Project 1 – Flashing LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165

13.3 Project 2 – Button and LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

13.4 VHDPlus to VHDL conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

Chapter 14 • MAX1000 FPGA Python Programming . . . . . . . . . . . . . . . . . . . . . . . 170

14.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170

14.2 Python programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170

Chapter 15 • NIOS II . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

15.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

15.2 Creating a NIOS II processor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176

15.3 Project 1 – Displaying a message using the NIOS II processor as Arduino . . . . . 178

15.4 Project 2 – Alternately flashing two LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180

Chapter 16 • Accelerometer Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

16.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

16.2 The project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

16.2.1 Testing the program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184

●8

FPGA Programming and Hardware Essentials.indd 8 28-10-2024 13:39


Contents

Chapter 17 • Other Projects Provided With the VHDPlus IDE . . . . . . . . . . . . . . . . 186

Chapter 18 • Quartus Prime Lite Schematic Design . . . . . . . . . . . . . . . . . . . . . . . 188

18.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188

18.2 Project 1 – D-type flip-flop with LED output . . . . . . . . . . . . . . . . . . . . . . . . . . 188

18.3 Project 2 – Electronic lock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194

18.3.1 The truth table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194

Appendix • Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200

●9

FPGA Programming and Hardware Essentials.indd 9 28-10-2024 13:39

You might also like