Analog Interfacing to Embedded Microprocessors Real World Design Analog Interfacing to Embedded Microprocessors Real World Design Stuart Ball Boston Oxford Auckland Johannesburg Melbourne New Delhi Newnes is an imprint of Butterworth–Heinemann. Copyright © 2001 by Butterworth–Heinemann A member of the Reed Elsevier group 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, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Recognizing the importance of preserving what has been written, Butterworth–Heinemann prints its books on acid-free paper whenever possible. Library of Congress Cataloging-in-Publication Data Ball, Stuart R., 1956– Analog interfacing to embedded microprocessors : real world design / Stuart Ball. p. cm. ISBN 0-7506-7339-7 (pbk. : alk. paper) 1. Embedded computer systems—Design and construction. 2. Microprocessors. I. Title. TK7895.E42 .B33 2001 004.16—dc21 00-051961 British Library Cataloguing-in-Publication Data A catalogue record for this book is available from the British Library. The publisher offers special discounts on bulk orders of this book. For information, please contact: Manager of Special Sales Butterworth-Heinemann 225 Wildwood Avenue Woburn, MA 01801-2041 Tel: 781-904-2500 Fax: 781-904-2620 For information on all Newnes publications available, contact our World Wide Web home page at: http://www.newnespress.com 10987654321 Printed in the United States of America Preface ix Introduction xi 1 System Design 1 Dynamic Range 1 Calibration 2 Bandwidth 5 Processor Throughput 6 Avoiding Excess Speed 7 Other System Considerations 8 Sample Rate and Aliasing 11 2 Digital-to-Analog Converters 13 Analog-to-Digital Converters 15 Types of ADCs 17 Sample and Hold 26 Real Parts 29 Microprocessor Interfacing 30 Serial Interfaces 36 Multichannel ADCs 41 Internal Microcontroller ADCs 41 Codecs 42 Interrupt Rate 43 Dual-Function Pins on Microcontrollers 43 Design Checklist 45 v Contents 3 Sensors 47 Temperature Sensors 47 Optical Sensors 59 CCDs 72 Magnetic Sensors 82 Motion/Acceleration Sensors 86 Strain Gauge 90 4 Time-Based Measurements 93 Measuring Period versus Frequency 95 Mixing 97 Voltage-to-Frequency Converters 99 Clock Resolution 102 5 Output Control Methods 103 Open-Loop Control 103 Negative Feedback and Control 103 Microprocessor-Based Systems 104 On-Off Control 105 Proportional Control 108 PID Control 110 Motor Control 123 Measuring and Analyzing Control Loops 130 6 Solenoids, Relays, and Other Analog Outputs 137 Solenoids 137 Heaters 143 Coolers 148 Fans 149 LEDs 151 7 Motors 161 Stepper Motors 161 DC Motors 180 Brushless DC Motors 184 Tradeoffs between Motors 198 Motor Torque 201 vi Contents 8 EMI 203 Ground Loops 203 ESD 208 9 High-Precision Applications 213 Input Offset Voltage 215 Input Resistance 216 Frequency Characteristics 217 Temperature Effects in Resistors 218 Voltage References 219 Temperature Effects in General 221 Noise and Grounding 222 Supply-Based References 227 10 Standard Interfaces 229 IEEE 1451.2 229 4-20 ma Current Loop 231 Appendix A: Opamp Basics 233 Four Opamp Configurations 233 General Opamp Design Equations 237 Reversing the Inputs 238 Comparators 239 Instrumentation Amplifiers 243 Appendix B: PWM 245 Why PWM? 245 Real Parts 250 Audio Applications 252 Appendix C: Some Useful URLs 255 Glossary 257 Index 261 Contents vii There often seems to be a division between the analog and digital worlds. Digital designers usually do not like to delve into analog, and analog design- ers tend to avoid the digital realm. The two groups often do not even use the same buzzwords. Even though microprocessors have become increasingly faster and more capable, the real world remains analog in nature. The digital designers who attempt to control or measure the real world must somehow connect this analog environment to their digital machines. There are books about analog design and books about microprocessor design. This book attempts to get at the problems encountered in connecting the two together. This book came about because of a comment made by someone about my first book (Embedded Microprocessor Systems: Real World Design): “it needs more analog interfacing information.” I felt that adding this material to that book would cause the book to lose focus. However, the more I thought about it, the more I thought that a book aimed at interfacing the real world to micro- processors could prove valuable. This book is the result. I hope it proves useful. ix Preface . Contents vii There often seems to be a division between the analog and digital worlds. Digital designers usually do not like to delve into analog, and analog. Analog Interfacing to Embedded Microprocessors Real World Design Analog Interfacing to Embedded Microprocessors