Lewin A.R.W. Edwards
Copyright
Newnes is an imprint of Elsevier
30 Corporate Drive, Suite 400, Burlington, MA 01803, USA
Linacre House, Jordan Hill, Oxford OX2 8DP, UK
Copyright 2005, Elsevier Inc. 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.
), by selecting Customer Support and then Obtaining Permissions.
Recognizing the importance of preserving what has been written, Elsevier prints its books on acid-free paper whenever possible.
Library of Congress Cataloging-in-Publication Data
(Application submitted.)
British Library Cataloguing-in-Publication Data
A catalogue record for this book is available from the British Library.
ISBN: 0-7506-7778-3
For information on all Newnes publications, visit our Web site at www.books.elsevier.com
04 05 06 07 08 09 10 9 8 7 6 5 4 3 2 1
Printed in the United States of America.
Dedication
This book is dedicated to my wife Cristen, in recognition of her uncomplaining acceptance of yards of PVC conduit in hallways, pounds of gel-cells in the living room, and never-ending snarls of wire and motors throughout the house.
About the Author
Lewin A.R.W. Edwards was born in Adelaide, Australia. He worked for five years in Melbourne, Australia on government-approved encryption, desktop protection and data security products for DOS, Windows and OS/2. For the next five years, he worked in Port Chester, New York for Digi-Frame, Inc., where he designed both the hardware and firmware of a range of multimedia digital picture frame appliances. These devices ranged in complexity from small pocket-size still-image viewers up to fully networked wall-mounted devices with audio and full-motion video support. He currently lives in New York City and works as a short-range radio digital design engineer for a well-known manufacturer of wireless security and fire safety products. His earlier works include Embedded Systems Design on a Shoestring, (a book about low-cost embedded systems development, principally targeted at ARM7 platforms), as well as articles on specialized design considerations for the microcontrollers used in electronic toys, commentary on Universal PlugNPlay, reverse-engineering Internet appliances, and other topics of interest.
Whats on the CD-ROM?
Included on the accompanying CD-ROM:
A free version of the schematic capture and PCB CAD software used to prepare this book. (Refer to the license agreement included with the software for usage restrictions and limitations.)
Atmel AVR Studio 4.08.
Full schematics and sourcecode for the projects described in this book.
Ready-made disk images for the miniature Linux distribution used as a basis for the books PC-side software.
Distribution archives of the sourcecode for all GNU software used, along with application-specific patches, where appropriate.
CHAPTER 1
Introduction
1.1 History of this Book and What Youll Get From Reading It
Over the course of roughly a year, after completing my first book, I resurrected an old pet project of building an autonomous submarine (referred to as the E-2 project) with certain fairly challenging functionality requirements. In the course of developing this idea, I spent many hours on the Internet and elsewhere, researching techniques for rapid development of various electromechanical control systems and platforms to run fairly complex signal-processing algorithms. Although there are, of course, thousands of useful projects and snippets of information to be obtained from the Internet and books on hobbyist robotics, I found that nobody else seemed to have my exact priorities. In particular, there is apparently no single reference that gathers together at least introductory solutions to all the embedded design issues that affected my project: a need to use low-cost (open-source) tools and operating systems, a requirement for several features with fairly hard real-time requirements, and a desire to use cheap, off-the-shelf consumer grade components wherever possible. Available resources on many topics concentrate either on very expensive off-the-shelf industrial components, or on tightly constrained systems built around a single microcontroller, with delicately optimized, nonportable code to control peripheralsand a very limited range of peripheral support, at that. These latter system design restrictions are unavoidable when youre working to tight power requirements, space constraints, or a rock-bottom bill of material (BOM) cost, but its an inordinate amount of effort to build and tune such systems for a one-off project or a prototype. Furthermore, learning all the details required to assemble such a system is an enormous task; its easy to get lost in fine-tuning details without ever managing to field a complete, working system. Irritatingly, many of the tweaks and most of the careful planning you do to get that system operational will have to be thrown away if you move into actual production, or if you need to build some more units with slightly different components.
What I was searching for while developing the E-2 project was a way to build various hard real-time modules (sensors and actuators) that could easily and cheaply be interfaced to a general-purpose computer running Linux. The Linux box served as a testbed for algorithms which would later be ported down into a smaller, cooler, more power-efficient processing module of some kind. I needed a solid basis of known-good code and techniques so that I could strike out from that point and build my own customized system. I also wanted a simple up-and-running guide to building embedded Linux distributions. For the initial, nonfieldable prototype of my submarine, I didnt have an exact idea of how much CPU horsepower I would need in the final versionso I didnt want to get tied to a specific microcontroller architecture, nor did I want to get bogged down in trying to tweak and tune many real-time tasks on a single microcontroller. I also wanted to use a few peripheralssuch as cameraswhich are easiest interfaced through a general-purpose operating system.
These requirements may sound a chord with your own working life. Chances are youve encountered situations where it would be useful to automate some long-term data-gathering experiment or create a simple automated controller for a programming, manufacturing or other task. In this vein, three other instances where I have applied the techniques in this book are: