Designing Digital Circuits a Modern Approach
Total Page:16
File Type:pdf, Size:1020Kb
Designing Digital Circuits a modern approach Jonathan Turner 2 Contents I First Half 5 1 Introduction to Designing Digital Circuits 7 1.1 Getting Started . .7 1.2 Gates and Flip Flops . .9 1.3 How are Digital Circuits Designed? . 10 1.4 Programmable Processors . 12 1.5 Prototyping Digital Circuits . 15 2 First Steps 17 2.1 A Simple Binary Calculator . 17 2.2 Representing Numbers in Digital Circuits . 21 2.3 Logic Equations and Circuits . 24 3 Designing Combinational Circuits With VHDL 33 3.1 The entity and architecture . 34 3.2 Signal Assignments . 39 3.3 Processes and if-then-else . 43 4 Computer-Aided Design 51 4.1 Overview of CAD Design Flow . 51 4.2 Starting a New Project . 54 4.3 Simulating a Circuit Module . 61 4.4 Preparing to Test on a Prototype Board . 66 4.5 Simulating the Prototype Circuit . 69 3 4 CONTENTS 4.6 Testing the Prototype Circuit . 70 5 More VHDL Language Features 77 5.1 Symbolic constants . 78 5.2 For and case statements . 81 5.3 Synchronous and Asynchronous Assignments . 86 5.4 Structural VHDL . 89 6 Building Blocks of Digital Circuits 93 6.1 Logic Gates as Electronic Components . 93 6.2 Storage Elements . 98 6.3 Larger Building Blocks . 100 6.4 Lookup Tables and FPGAs . 105 7 Sequential Circuits 109 7.1 A Fair Arbiter Circuit . 110 7.2 Garage Door Opener . 118 8 State Machines with Data 127 8.1 Pulse Counter . 127 8.2 Debouncer . 134 8.3 Knob Interface . 137 8.4 Two Speed Garage Door Opener . 141 II Second Half 147 9 Still More VHDL 149 9.1 Making Circuit Specifications More Generic . 149 9.2 Arrays and Records . 152 9.3 Using Assertions to Detect Bugs . 155 9.4 VHDL Variables . 156 9.5 Functions and Procedures . 159 CONTENTS 5 10 Design Studies 163 10.1 Four-way Max Finder . 163 10.2 Binary Input Module . 168 10.3 LCD Display Module . 172 10.4 Binary Output Module . 175 11 Verifying Circuit Operation 179 11.1 Assertion Checking in Circuit Specifications . 180 11.2 Testing Combinational Circuits . 181 11.3 Testing State Machines . 187 11.4 Testing Larger Circuits . 195 12 Continuing Design Studies 197 12.1 Simple Data Queue . 197 12.2 Packet FIFO . 202 12.3 Priority Queue . 212 13 Small Scale Circuit Optimization 219 13.1 Algebraic Methods . 220 13.2 Algorithmic Methods . 224 14 Still More Design Studies 235 14.1 VGA Display Circuit . 235 14.2 Mine Sweeper Game . 245 15 Implementing Digital Circuit Elements 265 15.1 Gates and Transistors . 265 15.2 Delays in Circuits . 272 15.3 Latches and Flip Flops . 275 16 Timing Issues in Digital Circuits 281 16.1 Flip Flop Timing Parameters . 281 16.2 Metastability and Synchronizers . 290 6 CONTENTS III Third Half 295 17 Introduction to Programmable Processors 297 17.1 Overview of the WASHU-2 Processor . 297 17.2 Machine Language Programming . 302 17.3 Prototyping the washu-2 .................... 309 17.4 Using Subprograms . 312 18 Implementing a Programmable Processor 321 18.1 Overview of the Implementation . 321 18.2 Signal Timing . 323 18.3 VHDL Implementation . 326 19 Supporting Components 337 19.1 Overview of the Complete System . 337 19.2 Implementing the Console . 341 20 Memory Components 353 20.1 SRAM Organization and Operation . 353 20.2 Alternate Memory Organizations . 360 20.3 Dynamic RAMs . 362 21 Improving Processor Performance 365 21.1 A Brief Look Back at Processor Design . 365 21.2 Alternate Instruction Set Architectures . 367 21.3 Implementing the WASHU-16 . 372 22 Improving Processor Performance Even More 387 22.1 Cache Basics . 388 22.2 A Cache for the WASHU-2................... 391 22.3 Beyond Direct-Mapped Caches . 394 22.4 Other Ways to Boost Performance . 397 CONTENTS 7 23 Making Circuits Faster 399 23.1 Faster Increment Circuits . 399 23.2 Faster Adder Circuits . 403 23.3 Other Linear Circuits . 405 23.4 Multiplication Circuits . 408 24 Producing Better Circuits Using VHDL 413 24.1 Some Motivating Examples . 414 24.2 Estimating Resource Usage . 418 24.3 Estimating and Reducing Resource Usage . 421 8 CONTENTS Part I First Half 9 Chapter 1 Introduction to Designing Digital Circuits 1.1 Getting Started This book is all about the design of digital circuits. So what exactly are digi- tal circuits and why should we care about them? Let's start with the second part of that question. Simply put, digital circuits have become a ubiqui- tous and indispensable part of modern life. They are in our computers, our cell phones, our cars, our televisions, our wrist watches. Almost everywhere you look, you can find digital circuits, and new applications are being de- veloped all the time. Surprisingly, this is a fairly recent phenomenon. In 1960, digital circuits were just beginning to find commercial application and very few people would ever encounter one in their daily lives. By the mid 1970s, hand-held calculators were starting to become popular with scientists, engineers and students, and by the mid 1980s personal computers started to get widespread use. Since then, the growth in the use of digital circuits has been explosive, and today it's hard to imagine living without them. So how is it that digital circuits have become such a big deal in such a short time? There are two key inventions that have driven the digital revolution. The first was the invention of the transistor in the late 1940s, and the second was the invention of the integrated circuit in the late 1950s. 11 12 Designing Digital Circuits © Jonathan Turner Now, transistors are the essential building block used to construct digital circuits, and integrated circuit technology is a manufacturing process that allows many transistors to be fabricated at once and wired together to create complex circuits. While early integrated circuits contained just a handful of transistors, advances in the fabrication processes now allow us to produce circuits with billions of transistors on a silicon chip the size of a fingernail. Now there is another big reason that digital circuits have become so successful, and that brings us to that word \digital". The defining property of a digital circuit is that it uses voltages and currents to represent logical values, commonly denoted as `0' and `1'. Now what's important about this is that because digital circuits represent logical values, it's possible to combine the basic building blocks of a digital circuit using just the rules of logic, and the rules of logic are a whole lot simpler than the laws of physics that ultimately determine how circuits behave. This gives digital circuits a kind of modularity that more general analog circuits lack. It is that modularity that allows us to create circuits of mind-boggling complexity that do what we expect them to do, reliably and consistently. Now this is not to say that we can escape the laws of physics entirely. Physical properties do place some constraints on how digital circuit components can be combined and the speed with which they operate. Nonetheless, when designing digital circuits we can largely ignore the underlying physics and focus most of our attention on how to combine components in a way that produces a desired logical behavior. There is still another big reason that digital circuits have become so suc- cessful and that is the programmable processor, arguably the most important digital circuit of all. What makes it so important is its remarkable flexibil- ity, and the key to that flexibility is programmability. While a processor is just a single circuit, it can be programmed to implement a remakable diver- sity of functions. This programmability means that one device can do many different things. So the same processor can be used in a wrist watch or a calculator, and at different times it can do different things, as the plethora of cell phone apps amply demonstrates. Perhaps the most amazing thing about the progammable processor is that it can be a relatively simple cir- cuit. Programmability does not require a lot of complexity and while modern processors are pretty complex, we'll see that most of that complexity is there 1. Introduction 13 for the sole purpose of improving performance. The essential feature of pro- grammability does not require it. As you progress through the book, you will learn about the building blocks of digital circuits and how they can be put together to build complex systems. You will learn about how circuits can be constructed efficiently using the rules of logic, and how modern hardware description languages can be used to simplify the specification of larger circuits. You will learn how circuit designs are debugged using a circuit simulator and how programmable logic devices can be used to implement the circuits you design. You will see lots of different examples of digital circuits and have the opportunity to develop your own digital design skills. As you move on to the later chapters, you will learn how to implement a programmable processor and how it can be programmed using a simple assembly language. You wil also learn about the factors that limit processor performance, and how processor designers overcome these limitations using a variety of different techniques. 1.2 Gates and Flip Flops Figure ?? shows the three fundamental components of a digital circuit, the and gate, the or gate and the inverter. As its name suggests, the output AND gate OR gate inverter A A A·B A+B A A’ B B of an and gate is the logical and of its two inputs.