EMBEDDED SYSTEMS: Jonathan W. Valvano REAL-TIME INTERFACING TO ARM CORTEX TM -M MICROCONTROLLERS. Volume 2 Fourth Edition, June 2014

Similar documents
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

Chapter 13. PIC Family Microcontroller

8051 MICROCONTROLLER COURSE

Instrumentação Suportada em Computadores Pessoais Instrumentation

Am186ER/Am188ER AMD Continues 16-bit Innovation

AN LPC1700 timer triggered memory to GPIO data transfer. Document information. LPC1700, GPIO, DMA, Timer0, Sleep Mode

Microcontrollers in Practice

7a. System-on-chip design and prototyping platforms

Lab Experiment 1: The LPC 2148 Education Board

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

System Design Issues in Embedded Processing

Microtronics technologies Mobile:

DKWF121 WF121-A B/G/N MODULE EVALUATION BOARD

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

Accurate Measurement of the Mains Electricity Frequency

APPLICATION. si32library. Callback CMSIS HARDWARE. Figure 1. Firmware Layer Block Diagram

Chapter 1 Lesson 3 Hardware Elements in the Embedded Systems Chapter-1L03: "Embedded Systems - ", Raj Kamal, Publs.: McGraw-Hill Education

Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II

Flexible Active Shutter Control Interface using the MC1323x

All Programmable Logic. Hans-Joachim Gelke Institute of Embedded Systems. Zürcher Fachhochschule

POCKET SCOPE 2. The idea 2. Design criteria 3

2.0 Command and Data Handling Subsystem

Eliminate Risk of Contention and Data Corruption in RS-485 Communications

A+ Guide to Managing and Maintaining Your PC, 7e. Chapter 1 Introducing Hardware

GPS & GSM BASED REAL-TIME VEHICLE TRACKING SYSTEM.

How to design and implement firmware for embedded systems

PAC52XX Clock Control Firmware Design

DESIGN AND IMPLEMENTATION OF ONLINE PATIENT MONITORING SYSTEM

Computer Automation Techniques. Arthur Carroll

Computer Performance. Topic 3. Contents. Prerequisite knowledge Before studying this topic you should be able to:

Embedded Systems on ARM Cortex-M3 (4weeks/45hrs)

Access Control Using Smartcard And Passcode

Chapter 2 Logic Gates and Introduction to Computer Architecture

UG103.8 APPLICATION DEVELOPMENT FUNDAMENTALS: TOOLS

PC Base Adapter Daughter Card UART GPIO. Figure 1. ToolStick Development Platform Block Diagram

Lecture N -1- PHYS Microcontrollers

Computer Systems Structure Input/Output

GTS-4E Hardware User Manual. Version: V1.1.0 Date:

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

How To Use A Watt Saver On A Microcontroller (Watt Saver) On A Cell Phone Or Mp3 Player

Computer Organization and Components

Application Note: AN00141 xcore-xa - Application Development

Conversion Between Analog and Digital Signals

The Programming Interface

Measuring Resistance Using Digital I/O

TEST CHAPTERS 1 & 2 OPERATING SYSTEMS

Embedded Component Based Programming with DAVE 3

Network connectivity controllers

C8051F020 Utilization in an Embedded Digital Design Project Course. Daren R. Wilcox Southern Polytechnic State University Marietta, Georgia

EVAL-UFDC-1/UFDC-1M-16

Digital Electronics Detailed Outline

THREE YEAR DEGREE (HONS.) COURSE BACHELOR OF COMPUTER APPLICATION (BCA) First Year Paper I Computer Fundamentals

3.2 inch QVGA TFT Color LCD User s Guide Version 1 & 2

Programmable Logic Controller PLC

Designing VM2 Application Boards

Tire pressure monitoring

Secure My-d TM and Mifare TM RFID reader system by using a security access module Erich Englbrecht (info@eonline.de) V0.1draft

CAN bus board. EB018

Serial Communications

Home Security System Using Gsm Modem

MICROPROCESSOR AND MICROCOMPUTER BASICS

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

Android Application Development and Bluetooth Technology

STEPPER MOTOR SPEED AND POSITION CONTROL

Lecture 2: Computer Hardware and Ports.

Lesson 10:DESIGN PROCESS EXAMPLES Automatic Chocolate vending machine, smart card and digital camera

Freescale Semiconductor, I

Lesson 16 Analog-to-Digital Converter (ADC)

Soft processors for microcontroller programming education

Open Architecture Design for GPS Applications Yves Théroux, BAE Systems Canada

ONLINE HEALTH MONITORING SYSTEM USING ZIGBEE

Note monitors controlled by analog signals CRT monitors are controlled by analog voltage. i. e. the level of analog signal delivered through the

Simplifying System Design Using the CS4350 PLL DAC

DAC Digital To Analog Converter

Substation Automation Systems. Nicholas Honeth

AND8336. Design Examples of On Board Dual Supply Voltage Logic Translators. Prepared by: Jim Lepkowski ON Semiconductor.

Final Design Report 19 April Project Name: utouch

Fingerprint Based Biometric Attendance System

COMPUTER HARDWARE. Input- Output and Communication Memory Systems

PROJECT PRESENTATION ON CELLPHONE OPERATED ROBOTIC ASSISTANT

A 5 Degree Feedback Control Robotic Arm (Haptic Arm)

Freescale Semiconductor, Inc. Product Brief Integrated Portable System Processor DragonBall ΤΜ

ARM Ltd 110 Fulbourn Road, Cambridge, CB1 9NJ, UK.

AN10866 LPC1700 secondary USB bootloader

ARM Cortex STM series

USB 3.0 Connectivity using the Cypress EZ-USB FX3 Controller

Von der Hardware zur Software in FPGAs mit Embedded Prozessoren. Alexander Hahn Senior Field Application Engineer Lattice Semiconductor

Single Phase Two-Channel Interleaved PFC Operating in CrM

Embedded Software development Process and Tools:

Microcontroller Based Low Cost Portable PC Mouse and Keyboard Tester

INDUSTRIAL CONTROL TECHNOLOGY. A Handbook for Engineers and Researchers. Peng Zhang. Beijing Normal University, People's Republic of China

Theory and Practice of Tangible User Interfaces. Thursday Week 2: Digital Input and Output. week. Digital Input and Output. RGB LEDs fade with PWM

Using Xbee in Serial Communication

Serial port interface for microcontroller embedded into integrated power meter

MECE 102 Mechatronics Engineering Orientation

Vision Engravers and Routers PRE-Installation Guide Vision Engraving & Routing Systems

Motor Control using NXP s LPC2900

Lesson 7: SYSTEM-ON. SoC) AND USE OF VLSI CIRCUIT DESIGN TECHNOLOGY. Chapter-1L07: "Embedded Systems - ", Raj Kamal, Publs.: McGraw-Hill Education

Switch board datasheet EB

Transcription:

EMBEDDED SYSTEMS: REAL-TIME INTERFACING TO ARM CORTEX TM -M MICROCONTROLLERS Volume 2 Fourth Edition, June 2014 Jonathan W. Valvano

ii Jonathan Valvano Fourth edition June 2014 ARM and uvision are registered trademarks of ARM Limited. Cortex and Keil are trademarks of ARM Limited. Stellaris and Tiva are registered trademarks Texas Instruments. Code Composer Studio is a trademark of Texas Instruments. All other product or service names mentioned herein are the trademarks of their respective owners. In order to reduce costs, this college textbook has been self-published. For more information about my classes, my research, and my books, see http://users.ece.utexas.edu/~valvano/ For corrections and comments, please contact me at: valvano@mail.utexas.edu. Please cite this book as: J. W. Valvano, Embedded Systems: Real-Time Interfacing to ARM Cortex TM -M Microcontrollers, http://users.ece.utexas.edu/~valvano/, ISBN: 978-1463590154, 2014. Copyright 2014 Jonathan W. Valvano All rights reserved. No part of this work covered by the copyright herein may be reproduced, transmitted, stored, or used in any form or by any means graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, web distribution, information networks, or information storage and retrieval, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the publisher. ISBN-13: 978-1463590154 ISBN-10: 1463590156

Jonathan Valvano iii Table of Contents Preface to Third Edition... vii Preface to Fourth Edition... vii Preface... viii Acknowledgements... ix 1. Introduction to Embedded Systems... 1 1.1. Computer Architecture... 2 1.2. Embedded Systems... 10 1.3. The Design Process... 16 1.4. Digital Logic and Open Collector... 29 1.5. Digital Representation of Numbers... 40 1.6. Ethics... 56 1.7. Exercises... 58 1.8. Lab Assignments... 62 2. ARM Cortex-M Processor... 63 2.1. Cortex TM -M Architecture... 64 2.2. Texas Instruments LM3S and TM4C I/O pins... 71 2.3. ARM Cortex TM -M Assembly Language... 87 2.4. Parallel I/O ports... 109 2.5. Phase-Lock-Loop... 122 2.6. SysTick Timer... 125 2.7. Choosing a Microcontroller... 126 2.8. Exercises... 128 2.9. Lab Assignments... 129 3. Software Design... 131 3.1. Attitude... 132 3.2. Quality Programming... 134 3.3. Software Style Guidelines... 135

iv Jonathan Valvano 3.4. Modular Software... 150 3.5. Finite State Machines... 163 3.6. Threads... 174 3.7. First In First Out Queue... 177 3.8. Memory Management and the Heap... 185 3.9. Introduction to Debugging... 188 3.10. Exercises... 200 3.11. Lab Assignments... 202 4. Hardware-Software Synchronization... 203 4.1. Introduction... 204 4.2. Timing... 209 4.3. Petri Nets... 214 4.4. Kahn Process Networks... 217 4.5. Edge-triggered Interfacing... 219 4.6. Configuring Digital Output Pins... 222 4.7. Blind-cycle Interfacing... 223 4.8. Busy-Wait Synchronization... 235 4.9. UART Interface... 240 4.10. Keyboard Interface... 249 4.11. Exercises... 254 4.12. Lab Assignments... 256 5. Interrupt Synchronization... 259 5.1. Multithreading... 260 5.2. Interthread Communication and Synchronization... 263 5.3. Critical Sections... 271 5.4. NVIC on the ARM Cortex-M Processor... 275 5.5. Edge-triggered Interrupts... 280 5.6. Interrupt-Driven UART... 283 5.7. Periodic Interrupts using SysTick... 287 5.8. Low-Power Design... 291 5.9. Debugging Profile... 292

Jonathan Valvano v 5.10. Exercises... 292 5.11. Lab Assignments... 297 6. Time Interfacing... 299 6.1. Input Capture or Input Edge Time Mode... 299 6.2. Output Compare or Periodic Timer... 313 6.3. Pulse Width Modulation... 317 6.4. Frequency Measurement... 320 6.5. Binary Actuators... 326 6.6. Integral Control of a DC Motor... 339 6.7. Exercises... 341 6.8. Lab Assignments... 343 7. Serial Interfacing... 345 7.1. Introduction to Serial Communication... 346 7.2. RS232 Interfacing... 352 7.3. RS422/USB/RS423/RS485 Balanced Differential Lines... 357 7.4. Logic Level Conversion... 362 7.5. Synchronous Transmission and Receiving using the SSI... 363 7.6. Inter-Integrated Circuit (I 2 C) Interface... 374 7.7. Introduction to Universal Serial Bus (USB)... 387 7.8. Exercises... 394 7.9. Lab Assignments... 397 8. Analog Interfacing... 399 8.1. Resistors and Capacitors... 399 8.2. Op Amps... 402 8.3. Analog Filters... 418 8.4. Digital to Analog Converters... 421 8.5. Analog to Digital Converters... 433 8.6. Exercises... 446 8.7. Lab Assignments... 448 9. System-Level Design... 449 9.1. Design for Manufacturability... 449

vi Jonathan Valvano 9.2. Power... 451 9.3 Tolerance... 458 9.4. Design for Testability... 460 9.5. Printed Circuit Board Layout and Enclosures... 461 9.6. Exercises... 464 9.7. Lab Assignments... 464 10. Data Acquisition Systems... 465 10.1. Introduction... 465 10.2. Transducers... 470 10.3. Discrete Calculus... 482 10.4. Data Acquisition System Design... 484 10.5. Analysis of Noise... 490 10.6. Data Acquisition Case Studies... 499 10.7. Exercises... 511 10.8. Lab Assignments... 515 11. Introduction to Communication Systems... 517 11.1. Fundamentals... 517 11.2. Communication Systems Based on the UARTs... 521 11.3. Wireless Communication... 525 11.4. Internet of Things... 530 11.5. Exercises... 544 11.6. Lab Assignments... 545 Appendix 1. Glossary... 546 Appendix 2. Solutions to Checkpoints... 563 Index... 571 Reference Material... 583

Jonathan Valvano vii Preface to Third Edition There are a new features added to this third edition. The new development platform based on the TM4C123 is called Tiva LaunchPad. Material in this book on the TM4C also applies to the LM4F because Texas Instruments rebranded the LM4F series as TM4C (same chips new name), and rebranded StellarisWare as TivaWare. These new microcontrollers run at 80 MHz, include single-precision floating point, have two 12-bit ADCs, and support DMA and USB. A wonderful feature of these new boards is their low cost. As of December 2013, the boards are available on TI.com as part number EK-TM4C123GXL for $12.99. They are also available from $13 to $24 at regular electronics retailers like arrow.com, newark.com, mouser.com, and digikey.com. The book can be used with either a LM3S or TM4C microcontroller. Although this edition now focuses on the M4, the concepts still apply to the M3, and the web site associated with this book has example projects based on the LM3S811, LM3S1968, and LM3S8962. Preface to Fourth Edition This fourth edition includes the new TM4C1294-based LaunchPad. Most of the code in the book is specific for the TM4C123-based LaunchPad. However, the book website includes corresponding example projects for the LM3S811, LM3S1968, LM4F120, and TM4C1294, which are ARM Cortex -M microcontrollers from Texas Instruments. There are now two lost-cost development platforms called Tiva LaunchPad. The EK-TM4C123GXL LaunchPad retails for $12.99, and the EK-TM4C1294XL Connected LaunchPad retails for $19.99. The various LM3S, LM4F and TM4C microcontrollers are quite similar, so this book along with the example code on the web can be used for any of these microcontrollers. Compared to the TM4C123, the new TM4C1294 microcontroller runs faster, has more RAM, has more ROM, includes Ethernet, and has more I/O pins. This fourth edition switches the syntax from C to the industry-standard C99, adds a line-tracking robot, designs an integral controller for a DC motor, and includes an expanded section on wireless communication and Internet of Things.