Digital and System Design
Total Page:16
File Type:pdf, Size:1020Kb
Digital System Design — Use of Microcontroller RIVER PUBLISHERS SERIES IN SIGNAL, IMAGE & SPEECH PROCESSING Volume 2 Consulting Series Editors Prof. Shinsuke Hara Osaka City University Japan The Field of Interest are the theory and application of filtering, coding, trans- mitting, estimating, detecting, analyzing, recognizing, synthesizing, record- ing, and reproducing signals by digital or analog devices or techniques. The term “signal” includes audio, video, speech, image, communication, geophys- ical, sonar, radar, medical, musical, and other signals. • Signal Processing • Image Processing • Speech Processing For a list of other books in this series, see final page. Digital System Design — Use of Microcontroller Dawoud Shenouda Dawoud R. Peplow University of Kwa-Zulu Natal Aalborg Published, sold and distributed by: River Publishers PO box 1657 Algade 42 9000 Aalborg Denmark Tel.: +4536953197 EISBN: 978-87-93102-29-3 ISBN:978-87-92329-40-0 © 2010 River Publishers All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, mechanical, photocopying, recording or otherwise, without prior written permission of the publishers. Dedication To Nadia, Dalia, Dina and Peter D.S.D To Eleanor and Caitlin R.P. v This page intentionally left blank Preface Electronic circuit design is not a new activity; there have always been good designers who create good electronic circuits. For a long time, designers used discrete components to build first analogue and then digital systems. The main components for many years were: resistors, capacitors, inductors, transistors and so on. The primary concern of the designer was functionality however, once functionality has been met, the designer’s goal is then to enhance per- formance. Embedded system design is not just a new label for an old activity; embed- ded system designers today face new challenges. They are asked to produce increasingly complex systems using the latest technologies, but these technolo- gies are changing faster than ever. They are asked to produce better quality designs with a shorter time-to-market. They are asked to implement func- tionality but more importantly to satisfy numerous other constraints. It is not enough, for example, to have a mobile phone that you can communicate with; it must also be small, light weight, have a reasonable cost, consume minimal power and secure the contents of the messages while communicating etc. To communicate is the functionality, while the size, weight, power consumption and the use of encryption for secure data exchange are constraints that must be achieved for an acceptable mobile handset. To achieve the current goals of design, the designer must be aware with such design constraints and more importantly, the factors that have a direct effect on them. This book consists of three parts. The first part comprises Chapters 1–3. Chapters 1 and 2, cover the important concepts of designing under constraints. In Chapter 1, we introduce the reader to a good amount of needed knowledge about design constraints and design metrics while in Chapter 2, we give the reader a complete idea of the design flow process and the challenges he will vii viii Preface face. More importantly, how he is to select one of the many options available to him. In Chapter 3, we introduce the reader to the rest of the book; the other two parts. We use it to familiarize the reader with terminologies such as; microprocessor, microcontroller, microprocessor-based and microcontroller- based systems, the organization and the building blocks of the microprocessor and microcontroller, etc. We briefly introduce the reader to the main build- ing blocks of the microcontroller that will be the subject of the rest of the book; timers, counters, the watchdog timer, ADC, DAC, serial communica- tion, memory, need of programming, etc. Part 2 comprises Chapters 4 and 5 which cover the programming part of microcontrollers. The two chapters give the reader a very clear idea of instruc- tions and the instruction set, instruction cycles, addressing modes, assembly language, how to write a program, etc. We use for demonstration the instruc- tion sets of the Atmel AVR series and Intel 8051 family. The remaining Chapters 6–9 together form Part 3 of the book. Each chapter deals with one subsystem that can be considered, from the embedded system design point of view as a single purpose processor. For example, timers and counters if implemented as an IC chip, then, they are single-purpose proces- sor, or subsystem. Similarly for: ADC, DAC, UART, CAN, I2C, etc. To make our book useful for a wider class of readers, we introduce each item as if it was a discrete subsystem and then we discuss its implementation as part of the resources of a microcontroller. The use of a microcontroller to implement the functionality of each subsystem and how to use it in many possible appli- cations is then given. This explains the main reason behind calling our book “Digital System Design” and not “Embedded System Design”; the use of the microcontroller as the processor in the system. In Chapter 6, we discuss the memory system; Chapter 7 considers timer/counters, while Chapter 8 treats the main components of any Data Acquisition System. Finally Chapter 9 con- siders the communication between microcontrollers and the outside world. Each chapter in this part can be considered as a complete unit that covers a topic. The reader can read them in any order he prefers. Contents List of Abbreviations xvii 1 Processor Design Metrics 1 1.1 Introduction 1 1.2 Common Design Metrics 4 1.3 Performance Design Metrics 8 1.3.1 Characteristics of a Good Performance Metric 10 1.3.2 Some Popular Performance Metrics 12 1.3.3 Analysing Algorithms 25 1.4 Economic Design Metrics 32 1.4.1 Time-to-Market 32 1.4.2 Design Economics 34 1.5 Power Design Metrics 41 1.5.1 Reducing Power Consumption 42 1.6 System Effectiveness Metrics 45 1.6.1 Reliability, Maintainability and Availability Metrics 46 1.7 Summary of the Chapter 51 1.8 Review Questions 52 2 A System Approach to Digital System Design 55 2.1 Introduction 55 2.2 System Design Flow 57 2.2.1 Requirement Analysis 57 2.2.2 Specifications 59 2.2.3 Functional Design: System Architecture 59 2.2.4 Hardware Overview 60 ix x Contents 2.2.5 Software Overview 65 2.2.6 Target System and Solution 69 2.3 Technologies Involved in the Design Process 71 2.4 Design Technology 72 2.4.1 Design Partitioning 73 2.4.2 Use of Multiple Views (Multiple Description Domains): The Y-Chart 74 2.4.3 Use of Structured Design: Functional Block-Structured Top-Down Design (Structural Hierarchy) 77 2.4.4 Design Procedure Based on Top-Down Approach 85 2.4.5 Programmable Digital Systems Design Using Block Structured Design 87 2.5 IC-Technology; Implementation Technology 95 2.5.1 Programmable Logic Device (PLD) 98 2.6 Processor Technology 103 2.6.1 Use of General-Purpose Processor (GPP) 106 2.6.2 Single-Purpose Processor 108 2.6.3 Application Specific Processor (e.g. Use of Microcon- troller and DSP) 109 2.6.4 Summary of IC Technology and Processor Technology 110 2.7 Summary of the Chapter 111 2.8 Review Questions 112 3 Introduction to Microprocessors and Microcontrollers 113 3.1 Introduction 113 3.1.1 Processor Architecture and Microarchitecture 115 3.2 The Microprocessor 117 3.2.1 General-Purpose Registers 117 3.2.2 Arithmetic and Logic Unit (ALU) 127 3.2.3 Control Unit 129 3.2.4 I/O Control Section (Bus Interface Unit) 130 3.2.5 Internal Buses 130 3.2.6 System Clocks 130 3.2.7 Basic Microprocessor Organization 131 Contents xi 3.3 Microcontrollers 134 3.3.1 Microcontroller Internal Structure 137 3.4 Microprocessor-Based and Microcontroller-Based Systems 142 3.4.1 Microprocessor-based and Microcontroller-based Digital Systems Design Using Top-Down Technique 145 3.5 Practical Microcontrollers 146 3.5.1 AVR ATmega8515 Microcontroller 147 3.5.2 Intel 8051 Microcontroller 151 3.6 Summary of the Chapter 158 3.7 Review Questions 159 4 Instructions And Instruction Set 161 4.1 Introduction 161 4.2 Instruction Format 163 4.2.1 Expressing Numbers 166 4.2.2 Basic Instruction Cycle; Execution Path of an Instruction 166 4.2.3 Clock Cycle and Instruction Cycle 168 4.2.4 Labels 168 4.3 Describing the Instruction Cycle: Use of Register Transfer Language (RTL) 168 4.3.1 Register Transfer Language (RTL) 168 4.3.2 Use of RTL to Describe the Instruction Cycle 171 4.4 Instruction Classifications According to Number of Operands 175 4.5 Addressing Modes 183 4.6 Immediate Addressing Mode 185 4.6.1 Advantages of Immediate Addressing 187 4.6.2 AVR Instructions with Immediate Addressing 187 4.7 Direct (Absolute) Addressing Mode 188 4.7.1 Register Direct Addressing 188 4.7.2 Memory Direct Addressing 190 4.8 Indirect Addressing Mode 192 4.8.1 AVR Indirect Addressing 194 4.8.2 Variation on the Theme 195 xii Contents 4.9 Displacement Addressing 199 4.9.1 Address Register Indirect with Displacement (also called “Base-Register Addressing”) 199 4.9.2 Data Indirect with Displacement 200 4.10 Relative Addressing Mode 201 4.11 Programme Memory Addressing 201 4.12 Stack Addressing 203 4.13 Programme Control Instructions 204 4.13.1 Jumps, Branch and Call in AVR Architecture 207 4.14 I/O and Interrupts 209 4.15 Summary of Addressing Modes 213 4.16 Review Questions 214 5 Machine Language and Assembly Language 217 5.1 Introduction 217 5.2 Directives: Pseudo-Instructions 219 5.2.1 Macros 221 5.2.2 ATMEL AVR Studio 222 5.3 Design of an Assembly Language Programme 223 5.3.1 The Basic Programming