Embedded Computing
Total Page:16
File Type:pdf, Size:1020Kb
Embedded Computing for Mechanical Engineers Rico A. R. Picone Department of Mechanical Engineering Saint Martin’s University Joseph L. Garbini Department of Mechanical Engineering University of Washington RAFT Spring 2020 D Copyright © 2020 Rico A. R. Picone and Joseph L. Garbini All Rights Reserved EVIEW R Contents Contents2 RAFT Preface5 D I Orientation9 00 Getting started 11 00.01 Introduction to embedded computing ............. 12 00.02 Embedded control of mechanical systems........... 15 00.03 Computer architectures...................... 17 00.04 Numeral systems.......................... 19 00.05 Binary and hexadecimal arithmetic............... 26 00.06 Exploring C building a sandbox................. 27 00.07 Exercises for Chapter 00...................... 29 00.08 Lab Exercise 00: Getting started................. 32 ResourceEVIEW R1 High-level embedded system.............. 36 Resource R2 Embedded computer and development environ- ment subsystem .......................... 38 ResourceR R3 User interface hardware subsystem .......... 45 Resource R4 Motor driver subsystem ................. 47 Resource R5 Motor and mechanical apparatus subsystem . 49 Resource R6 Sourcing and costs .................... 50 Resource R7 Setting up the C Development Tool for myRIO . 51 Resource R8 Suggested reading..................... 59 Contents Contents II The User Interface 61 01 Computing principles and high-level io 63 01.01 Memory............................... 64 01.02 Processing.............................. 70 01.03 A CPU programming model................... 71 01.04 Exercises for Chapter 01...................... 74 01.05 Lab Exercise 01: High-level io drivers ............. 75 02 Exploring C and mid-level io 91 02.01 A paper computer......................... 92 02.02 Exploring C operators....................... 93 02.03 Exploring C constants....................... 95 02.04 Exploring C pointers........................ 98 02.05 Exercises for Chapter 02...................... 99 02.06 Lab Exercise 02: Keypad mid-level primitives . 100 03 Digital com. and io RAFT111 03.01 Digital communication ......................112 03.02 UARTs................................114 03.03 Digital signals............................115D 03.04 Exploring C structures.......................117 03.05 Lab Exercise 03: Low-level character io . 119 III Timing, Threads, and Finite State Machines 129 04 Finite state machine control 131 04.01 Pulse-width modulation .....................132 04.02 DC motor driving .........................133 04.03 Measuring motor velocity ....................137 04.04 Finite state machines........................139 04.05 ExercisesEVIEW for Chapter 04......................144 04.06 Lab Exercise 04: FSM motor control . 147 ResourceR R9 Saving myRIO C data to a Matlab file . 159 Resource R10 Copley 412 analog amplifier setup . 162 05 Threads and interrupts 163 05.01 Processing threads.........................164 05.02 Interrupts ..............................165 05.03 Boolean algebra on digital signals . 166 3 24 April 2020, 13:48:08 00.00 3 3 Contents Contents 05.04 Debouncing switches .......................168 05.05 Lab Exercise 05: Introduction to interrupts . 169 Resource R11 Interrupt functions documentation . 178 IV Feedback Control of Mechanical Systems 183 06 Discrete dynamic systems 185 06.01 ADC and DAC...........................187 06.02 Difference equations........................189 06.03 Discrete transfer functions ....................190 06.04 The biquad cascade ........................195 Resource R12 Timer interrupts .....................196 06.05 Lab Exercise 06: Transfer function generator . 201 Resource R13 Discrete-time controllers . 207 Resource R14 Analog input and output . 208 07 Closed-loop control RAFT211 07.01 DC motor velocity control ....................212 07.02 Designing a PI controller.....................213 07.03 Exercises for Chapter 07......................214D 07.04 Lab Exercise 07: DC motor velocity control . 215 Resource R15 A table editor for the myRIO . 223 08 Path planning 227 08.01 Path planning............................228 08.02 Designing a PID controller....................229 08.03 Exercises for Chapter 08......................230 08.04 Lab Exercise 08: DC motor position control . 231 Resource R16 C function Sramps for position path planning . 239 Resource R17 Matlab function sos2header for converting con- trollersEVIEW to C.............................242 A Embedded Computing Laboratory 245 B ResourcesR 247 C Bibliography 249 4 24 April 2020, 13:48:08 00.00 3 4 Preface The instructional literature includes many excellent texts on the subject of embedded computing. Appropriately, most such texts, and the courses that use them, are aimed primarily at electrical or computerRAFT engineering students. By contrast, this text is designed specifically for mechanical engineering senior undergraduates or first year graduate students. The instruction builds on the typical background ofD an ME senior, and it focuses on applications of dynamic motion control and digital signal processing that are of particular interest to mechanical engineers. This course of study is also unique in that learning is organized around a sequence of nine hands-on experiments. Building one upon the other, the experiments proceed from basic interface concepts, through discrete control organization and timing issues, and ultimately to multi-tasked automatic control. Practical information (specific to the lab hardware), as well as, general analytical concepts (applicable to any computing environment) are introduced as necessary to support each experiment. For students, the text can best be thought of as a journey during which they learn to incorporate (embed) computers into mechanical systems as functional components.EVIEW They will comprehensively explore issues of user interaction, embedded program organization, timing control, and interface hardware.R Along the way, they will learn the process of designing and implementing embedded applications, and become acquainted with the ar- chitecture and resources of a modern real-time development environment. This book evolved during several decades of teaching embedded com- puting to mechanical engineering students as part of a senior-year curricu- lum in mechatronics. The goals of the text are first, to provide the embed- ded computing component for that mechatronics program, culminating in Contents Contents senior capstone design projects. And second, to provide students with a comprehensive foundation in modern embedded computing that can be used and extended throughout an engineering career. The vehicle for the lab experiments is the National Instruments myRIO- 1900 embedded device, programmed in C from an Eclipse development environment on the student’s laptop. This compact system features a two-core Xilinx Z-7010 processor, with an appropriate array of interfaces managed by its associated field programmable gate array, and a real-time linux operating system. Having taught this material (over the years) with at least five other microcomputers, we believe that the myRIO is an ideal platform, both for instruction and as the basis of prototypes in the senior capstone course. Why C? Of course, the myRIO is also readily programmed in LabVIEW. Why have we chosen C as the programming language for this text? While we are big fans of LabVIEW, and use it in many other courses, in this text we seek to give the student a broad exposure to the concept of an integrated development environment (IDE), useful acrossRAFT a wide array of real-time target microcomputers and applications. An engineer working in this field will eventually become familiar with a variety of languages and development environments. But, C/C++ is theD best place for a student to begin, and remains today the lingua franca of embedded computing. This text is intended for senior mechanical engineering undergraduates. We assume that students will have at least the usual first courses in differential equations, newtonian dynamics, and time/frequency domain analysis of dynamic systems. Background in the subjects of automatic control, instrumentation, and signal processing is useful and will help motivate the material, but is not essential. Knowledge of computer programming is assumed. However, no specific a priori familiarity with the C programming language is required. By degrees, the student will be introduced to C as he progresses through the lab exercises. We suggest that the student rely on a companion text on C as a reference.EVIEW Several are listed in the bibliography. The text also recommends that students use MATLAB to evaluate experimental results. AnR additional point: Although the book is presented for the classroom, there is no reason why a determined student couldn’t master the text and its experiments through individual self-study. Some ancillary hardware is necessary for the experiments: a keypad and LCD display, an oscilloscope, a brushless DC motor and inertial load with incremental encoder, an appropriate motor amplifier, and an analog signal generator. Although many forms of this equipment can be used, specific 6 24 April 2020, 13:48:08 00.00 3 6 Contents Contents suggestions are detailed in Appendix X. Before we begin, let’s briefly chart this journey into embedded comput- ing by outlining the nine core experiments. Lab Exercise 00 In this first lab, students set up their development environ- ment and insure that it works properly with the myRIO targets. They exercise debugging techniques, and become familiar with