Embedded Controller Hardware Design - İYTE Ana Sayfa

Transcription

A Volume in theEmbedded Technology SeriesEmbedded ControllerHardware Designby Ken HardwareDesign.com

iiEmbedded Control Hardware Design 2001 by LLH Technology Publishing.All rights reserved. No part of this book may be reproduced, in any form or by anymeans whatsoever, without permission in writing from the publisher. While everyprecaution has been taken in the preparation of this book, the publisher and authorassume no responsibility for errors or omissions. Neither is any liability assumedfor damages resulting from the use of the information contained herein.ISBN: 1-878707-52-3Library of Congress Control Number: 00-135391Printed in the United States of America10 9 8 7 6 5 4 3 2 1Project management and developmentalediting: Harry Helms, LLH Technology PublishingInterior design and production services: Greg Calvert, Model, COCover design: Sergio Villareal, Vista, wareDesign.com

iiiDedicationThis book is dedicated in memory of my father, Kenneth Owen Arnold,who always encouraged me to follow my dreams. When other adultsdiscouraged me from entering the engineering field, he told me, “If youreally like what you’re doing and you’re good at it, you will be successful.”Nowadays I get paid to have fun doing things I’d do for free anyway, so thatmeets my definition of success! Thanks, Dad.

ivAcknowledgmentThis book is a direct result of contributions from many of the students Ihave been fortunate enough to have in my embedded computer engineeringcourses at the University of California—San Diego extension. They haveprovided a valuable form of feedback by sharing their notes and pointingout weaknesses in the text and in-class presentations. Some sections ofthis text were also provided by David Fern and Steven Tietsworth.I would also like to thank my family for supporting me and, Mary, Nikki,Kenny, Daniel, Amy, and Annie for being patient and helping out whenI needed it!

1 Review of Electronics Fundamentals .1Objectives .Embedded Microcomputer Applications .Microcomputer and Microcontroller Architectures.Digital Hardware Concepts .2246Voltage, Current, and Resistance .Diodes .Transistors .Mechanical Switches .Transistor Switch ON .Transistor Switch OFF .The FET as a Logic Switch .NMOS Logic .CMOS Logic .Mixed MOS .Real Transistors Don t Eat Q! .7991011121213141616Logic Symbols.17Tri-State Logic.18Timing Diagrams .Multiplexed Bus .Loading and Noise Margin Analysis .The Design and Development Process.Chapter One Problems .19202121222 Microcontroller Concepts .23Organization: von Neumann vs. Harvard .Microprocessor/Microcontroller Basics .2424Microcontroller CPU, Memory, and I/O .Design Methodology .2526The 8051 Family Microcontroller Processor Architecture .27Introduction to the 8051 Architecture .Memory Organization .CPU Hardware .Oscillator and Timing Circuitry .28303241The 8051 Microcontroller Instruction Set Summary .42Direct and Register Addressing .Indirect Addressing .Immediate Addressing .Generic Address Modes and Instruction Formats.Address Modes .The Software Development Cycle .Software Development Tools .Hardware Development Tools .4346505152555556Chapter Two Problems .563 Worst- Case Timing, Loading, Analysis, and Design .57Timing Diagram Notation Conventions .58Rise and Fall Times .Propagation Delays.Setup and Hold Time .Tri-State Bus Interfacing .59596061

Pulse Width and Clock Frequency .62Fan-Out and Loading Analysis DC and AC .63Calculating Wiring Capacitance .Fan-Out When CMOS Drives LSTTL .Transmission Line Effects .Ground Bounce .66687072Logic Family IC Characteristics and Interfacing .75Interfacing TTL Compatible Signals to 5 Volt CMOS .Design Example: Noise Margin Analysis Spreadsheet .Worst-Case Timing Analysis Example .788290Chapter Three Review Problems .924 Memory Technologies and Interfacing.95Memory Taxonomy .96Secondary Memory .Volatility.Random Access Memory .Sequential Access Memory .Direct Access Memory .9798989999Read/Write Memories .Read-Only Memory .Other Memory Types .JEDEC Memory Pin-Outs .Device Programmers .Memory Organization Considerations.Parametric Considerations .Asynchronous vs. Synchronous Memory .Error Detection and Correction .100101104105106107109110111Error Sources .Confidence Checks .111111Memory Management .113Cache Memory .Virtual Memory .CPU Control Lines for Memory Interfacing .114114115Chapter Four Problems .Read and Write Operations.1151175 CPU Bus Interface and Timing .117Address, Data, and Control Buses.Address Spaces and Decoding.Address Map .Chapter Five Problems .The Central Processing Unit (CPU) .1181201221241256 A Detailed Design Example .125External Data Memory Cycles.134External Memory Data Memory Read.External Data Memory Write .134136Design Problem 1.Design Problem 2.Design Problem 3.138139140

Completing the Analysis .142Chapter Six Problems .143Memory Selection and Interfacing .126Preliminary Timing Analysis .1277 Programmable Logic Devices .145Introduction to Programmable Logic .147Technologies: Fuse-Link, EPROM, EEPROM, and RAM Storage .PROM as PLD .Programmable Logic Arrays .PAL-Style PLDs .147150151151Design Examples .153PLD Development Tools .155Simple I/O Decoding and Interfacing Using PLDs .IC Design Using PCs .Chapter Seven Problems .Direct CPU I/O Interfacing.1571571591618 Basic I/ O Interfaces .161Port I/O for the 8051 Family .Output Current Limitations .Simple Input/Output Devices.162166169Matrix Keyboard Input .Matrix Display Devices .170171Program-Controlled I/O Bus Interfacing .173Real-Time Processing.175Direct Memory Access (DMA) .175Burst vs. Single Cycle DMA .Cycle Stealing .176177Elementary I/O Devices and Applications .178Timing and Level Conversion Considerations .Level Conversion .Power Relays .180180180Chapter Eight Problems .1819 Other Interfaces and Bus Cycles .183Interrupt Cycles .Software Interrupts .Hardware Interrupts .184184184Interrupt Driven Program Elements .Critical Code Segments .Semaphores .Interrupt Processing Options .Level and Edge Triggered Interrupts .Vectored Interrupts .Non-Vectored Interrupts .Serial Interrupt Prioritization .Parallel Interrupt Prioritization .186187188189190192193194194

Construction Methods .19710 Other Useful Stuff.197Electromagnetic Compatibility .Electrostatic Discharge Effects .Fault Tolerance .Hardware Development Tools.199199200201Instrumentation Issues .202Software Development Tools .Other Specialized Design Considerations.203203Thermal Analysis and Design .Battery Powered System Design Considerations .204205Processor Performance Metrics.Device Selection Process .206207Power and Ground Planes.198Ground Problems .19811 Other Interfaces .209Analog Signal Conversion.Special Proprietary Synchronous Serial Interfaces .Unconventional Use of DRAM for Low Cost Data Storage .Digital Signal Processing / Digital Audio Recording .Detailed Checklist .210211211212215A Hardware Design Checklist .215Define Power Supply Requirements .Verify Voltage Level Compatibility .Check DC Fan-Out: Output Current Drive vs. Loading .AC (Capacitive) Output Drive vs. Capacitive Load and De- rating.Verify Worst Case Timing Conditions .Determine if Transmission Line Termination is Required .Clock Distribution .Power and Ground Distribution .Asynchronous Inputs.Guarantee Power-On Reset State .Programmable Logic Devices .Deactivate Interrupt and Other Requests on Power-Up.Electromagnetic Compatibility Issues .Manufacturing and Test Issues .Books .216217218218219219220220222222222223223223225B References, Web Links, and Other Sources .225Web and FTP Sites .Periodicals: Subscription .Periodicals: Advertiser Supported Trade Magazines .226227228Programming Microcontrollers in C, Second Edition .233

Embedded Controller Hardware Design .Controlling the World with Your PC .The Forrest Mims Engineers Notebook .The Forrest Mims Circuit Scrapbook, Volumes I and II .The Integrated Circuit Hobbyist s.HandbookSimple, Low-Cost Electronics Projects .233233233233233233

viiiPrefaceDuring the early years of microprocessors, there were few engineers witheducation and experience in the applications of microprocessor technology.Now that microprocessors and microcontrollers have become pervasive in somany devices, the ability to use them has become almost a requirement formany technical people.Today the microprocessor and the microcontroller have become two of themost powerful tools available to the scientist and engineer. Microcontrollershave been embedded in so many products that it is easy to overlook the factthat they greatly outnumber personal computers. Millions of PCs are shippedeach year, but billions of microcontrollers ship annually. While a great deal ofattention is given to personal computers, the vast majority of new designs arefor embedded applications. For every PC designer, there are thousands ofdesigners using microcontrollers in embedded applications. The number ofembedded designs is growing quickly. The purpose of this book is to give thereader the basic design and analysis skills to design reliable microcontroller ormicroprocessor based systems. The emphasis in this book is on the practicalaspects of interfacing the processor to memory and I/O devices, and the basicsof interfacing such a device to the outside world.A major goal of this book is to show how to make devices that are inherentlyreliable by design. While a lot of attention has been given to “quality improve ment,” the majority of the emphasis has been placed on the processes thatoccur after the design of a product is complete. Design deficiencies are a sig nificant problem, and can be exceedingly difficult to identify in the field.These types of quality problems can be addressed in the design phase withrelatively little effort, and with far less expense than will be incurred later inthe process. Unfortunately, there are many hardware designers and organiza tions that, for various reasons, do not understand the significance and ex pense of an unreliable design. The design methodology presented in this textis intended to address this problem.

ixPrefaceLearning to design and develop a microcontroller system without any practicalhands-on experience is a bit like trying to learn to ride a bike from readingbook. Thus, another goal is to provide a practical example of a completeworking product. What appears easy on paper may prove extremely difficultwithout some real world experience and some potentially painful crashes.In order to do it right, it’s best to examine and use a real design. On the otherhand, the current state of the technology (surface mounted packaging, etc.)can make the practical side problematic. In order to address this problem, aspecial educational System Development Kit is available to accompany thisbook (8031SDK). All the documentation to construct an SDK is availableon the companion CD-ROM. This info, along with updated informationand application examples, is also available on the web site for this book:http://www.hte.com/echdbook. All the information needed to build the SDKis available there, as well as information on how to order the SDK assembledand tested.While searching for an appropriate text for one of the courses I teach inembedded computer engineering, I was unable to locate a book that coveredthe topic adequately. An earlier version of this book was written to accom pany that course and has since evolved into what you see here. The courseis offered at the University of California, San Diego Extended Studies, andis titled “Embedded Controller Hardware Design.” The same courses mayalso be taken in an on-line format using the Internet, and can be found athttp://www.hte.com/uconline/ecd The goals of the course and the book arevery much the same: to describe the right way to design embedded systems.While no prior knowledge of microcontrollers or microprocessors is required,the reader should already be familiar with basic electronics, logic, and basiccomputer organization. Chapter one is intended as a review of those basicconcepts. Next there is a general overview of microcontroller architecture,and a specific microcontroller chip architecture, the 8051 family, is introduced

xPrefaceand detailed. The 8051 was chosen because it can be interfaced to externalmemory, has simple timing specs, is widely used and available from a numberof manufacturers. The concepts of worst-case design and analysis are described,along with techniques for hardware interfacing. A good embedded designrequires familiarity with the underlying memory technology, including ROM,SRAM, EPROM, Flash EPROM, EEPROM storage mechanisms and devices.The processor bus interface is then covered in general form, along with anintroduction to the 8051’s bus interface. Most embedded designs can alsobenefit from the use of user programmable logic devices (PLD). This subjectis too complex for in-depth coverage here, so PLD technology is covered froma relatively high level. The central theme of designing an embedded systemthat can be proven to be reliable is illustrated with a simple embedded con troller. The iterative nature of the design process is shown by example, andseveral design alternatives are evaluated. With the central part of the designcompleted, the remaining chapters cover the various types of I/O interfaces,bus operations, and a collection of information that is seldom included in theusual sources, but is often handed down from one engineer to another.I hope that you will find this book to be useful, and welcome any observationsand contributions you may have. If you should find any errors in the text, or ifyou know of some good embedded design resources, please feel free to contactme directly by e-mail: ken.arnold@ieee.org

1CHAPTER ONE1Review of ElectronicsFundamentalsWhy are microprocessors and microcontrollers designed into so many differentdevices? While there are many dry and practical reasons, I suspect one of thestrongest motivations for using a microprocessor is simply that it is a lot more fun.Over the past few decades of the so-called “computer revolution,” I have seenmany products and projects that could have been handled without resortingto a microprocessor. Yet there is always a tendency to rationalize the choice ofa micro-based solution by economic or technical arguments to support thedecision. In fact, most of the really excellent products were successful to a greatextent because they were fun to develop. Many of the best product ideas haveoccurred when someone was “playing” with something they were interestedin. In my own experience, I have found learning something new is mucheasier and more effective when I am “just playing around” rather than tryingto learn in a structured way or against a deadline. Studies of various educa tional methods also indicate “coached exploration” is more effective than thetraditional methods. These and other observations lead me to the conclusionthat the best way to learn about a microcontroller is by “playing” with one.No book—no matter how well written—can possibly motivate and educateyou as well as building and playing with a microcontroller. The best way tolearn the concepts in this book is to build a simple microcontroller. Even if itis capable of nothing more than blinking a light, it will provide a concreteexample of the microcontroller as a tool that can be fun to use. To ease thiseffort, a companion system development kit (SDK), is available to accompanythis text. It incorporates the functions of a stand-alone single board computer(SBC), and an in-circuit emulator (ICE). It also serves as a sample embeddedcontroller design. The design is included on the CD-ROM and web site forthis book, so anyone can reproduce and use it as a learning tool. By applying

2 EMBEDDED CONTROLLERHardware Designthe guidelines set forth in this book to real world hardware, you can learnto design reliable embedded hardware into other products. Information onobtaining the SDK can be found in the Preface.ObjectivesSeveral different skills are required for successful embedded hardware design.Here are some of the things you will know how to do when you finish this book: Interpret design requirements for the design of an embedded controller.Read and understand the manufacturer’s specification sheet.Select appropriate ICs for the design.Interface the CPU, memory, and I/O devices to a common bus.Design simple I/O (input/output) interfaces.Define the decoding and interconnection of the major components.Perform a worst-case analysis of the timing and loading of all signals.Understand the software development cycle for a microcontroller.Debug and test the hardware and software designs.These tasks represent the major skills required in the successful applicationof an embedded micro. In addition, other abilities—such as the design andimplementation of simple user programmable logic—will be covered asrequired to support the proficient application of the technology.Embedded Microcomputer ApplicationsThere is an incredible diversity of applications for embedded processors.Most people are aware of the highly visible applications, but there are manyless apparent uses. Many of the projects my students have chosen turned outto be of practical use in their work. However, they have covered the entirerange from the economically practical to the blatantly absurd. One practicalexample was the use of a microprocessor to monitor and control the ratio ofingredients used in mixing concrete. About a year after the student imple mented the system, he wrote to inform me that the system had saved his com pany between two and three million dollars a year by reducing the number

3 CHAPTER ONEReview of Electronics Fundamentalsof “bad batches” of concrete that had to be jack hammered out and replaced.Another example was that of a student who suspended a ball by airflow gener ated by a fan and provided closed loop control of the ball’s position with themicroprocessor. The only thing that many of the student projects really hadin common was the use of a microcontroller as a tool.Some of the actual commercial applications of embedded computer controlsthat the author has been directly involved with include: A belt measures a person’s heart rate and respiration that signals an alarmwhen safe lim

A Volume in the Embedded Technology Series Embedded Controller Hardware Design by Ken Arnold www.LLH-Publishing.com www.EmbeddedControllerHardwareDesign.com