Copyright 2017 by McGraw-Hill Education. All rights reserved. Except as permitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher.
ISBN: 978-1-25-964377-4
MHID: 1-25-964377-8.
The material in this eBook also appears in the print version of this title: ISBN: 978-1-25-964376-7, MHID: 1-25-964376-X.
eBook conversion by codeMantra
Version 1.0
All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark. Where such designations appear in this book, they have been printed with initial caps.
McGraw-Hill Education eBooks are available at special quantity discounts to use as premiums and sales promotions or for use in corporate training programs. To contact a representative, please visit the Contact Us page at www.mhprofessional.com .
TERMS OF USE
This is a copyrighted work and McGraw-Hill Education and its licensors reserve all rights in and to the work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill Educations prior consent. You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right to use the work may be terminated if you fail to comply with these terms.
THE WORK IS PROVIDED AS IS. McGRAW-HILL EDUCATION AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill Education and its licensors do not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free. Neither McGraw-Hill Education nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom. McGraw-Hill Education has no responsibility for the content of any information accessed through the work. Under no circumstances shall McGraw-Hill Education and/or its licensors be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possibility of such damages. This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise.
To my wife, Linda
About the Author
Dr. Simon Monk has a bachelors degree in cybernetics and computer science and a Ph.D. in software engineering. He is now a full-time writer and has authored numerous books, including Programming Arduino, Programming Raspberry Pi , Hacking Electronics , and is co-author of Practical Electronics for Inventors . Dr. Monk also runs the website .
CONTENTS
PREFACE
Wouldnt it be great to be able to have your own chips made that do exactly what you want them to? Well, field-programmable gate arrays (FPGAs) let you get pretty close to this ideal. Rather than being a chip specifically designed for you, an FPGA is a general-purpose chip that can be configured to act any way you want.
What is more, the way you configure your FPGA is either by drawing schematics or using a hardware-definition language that could (if your design is successful) also be used to manufacture chips that are actually custom chips to your design. The language in question is called Verilog , and although this book shows you how to make designs using a schematic editor, the main focus is on learning the Verilog language.
The FPGA configuration can be changed as many times as you like, making it a great tool for prototyping your designs. If a problem rears its head, you can just reprogram the device until you get all the bugs out. The ultimate mind-bending flexibility comes when you realize that you could actually configure your FPGA to include a processor capable of running programs.
In this book you will learn both the general principals of using FPGAs and how to get the examples described in this book up and running on three of the most popular FPGA evaluation boards: the Mojo, the Papilio One, and the Elbert 2.
Although, logically, a microcontroller can do pretty much anything that a FPGA can, a FPGA generally will run faster, and some people find it easier to write a description of logic gates and hardware than they do a complex algorithm. You can use a FPGA to implement a microcontroller or other processor (and people do).
Perhaps the most compelling reasons to try out programming some Verilog on one of the many low-cost FPGA boards is simply to learn something new and have some fun!
ACKNOWLEDGMENTS
As always, I thank Linda for her patience and support.
At TAB/McGraw-Hill and MPS Limited, my thanks go out to Michael McCabe, Patty Wallenburg, and their colleagues. As always, it was a pleasure working with such a great team.
Thanks also to Duncan Amos for his helpful and thorough technical review.
1
Logic
Field-programmable gate arrays (FPGAs) are digital devices that rely on digital logic. Computer hardware uses digital logic. Every calculation, every pixel rendered onto a screen, and every note of a music track is created using the building blocks of digital logic.
Although digital logic at times looks more like an abstract mathematical concept rather than physical electronics, the logic gates and other components of digital logic are constructed from transistors etched onto integrated circuits (ICs). In the case of FPGAs, a circuit can be designed by drawing logic gates that are then mapped onto general-purpose gates on the FPGA that are connected together so as to implement your logic design. Alternatively, the logic can be described using the Verilog (or another) hardware description language.
You can still buy chips that contain a small number of logic gates, such as the 7400, which has four two-input NAND gates. However, these are really only to maintain aged systems that use the chips or for educational use.
Logic Gates
Logic gates have inputs and outputs. These digital inputs and outputs can be either high or low . A low digital input or output is indicated by a voltage close to 0 V (ground). A high digital input is usually something over half the supply voltage of the logic, and a high digital output is at the positive supply voltage. The supply voltage for a FPGA is usually one of 1.8, 3.3, or 5 V, and most FPGAs can operate over a range of voltages. Some allow multiple logic voltages to be used on one device.