ebook img

PIC32 Microcontrollers and the Digilent chipKIT Introductory to Advanced PDF

403 Pages·2015·71.36 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview PIC32 Microcontrollers and the Digilent chipKIT Introductory to Advanced

Page intentionally blank Page left intentionally blank PIC32 Microcontrollers and the Digilent chipKIT Introductory to Advanced Projects Dogan Ibrahim AMSTERDAM • BOSTON • HEIDELBERG • LONDON NEW YORK • OXFORD • PARIS • SAN DIEGO SAN FRANCISCO • SINGAPORE • SYDNEY • TOKYO Newnes is an Imprint of Elsevier Newnes is an imprint of Elsevier The Boulevard, Langford Lane, Kidlington, Oxford OX5 1GB, UK 225 Wyman Street, Waltham, MA 02451, USA First edition 2015 Copyright © 2015 Elsevier Ltd. 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 Permissions may be sought directly from Elsevier’s Science & Technology Rights Department in Oxford, UK: phone (+44) (0) 1865 843830; fax (+44) (0) 1865 853333; email: permissions@elsevier. com. Alternatively, visit the Science and Technology Books website at www.elsevierdirect.com/rights for further information Notice No responsibility is assumed by the publisher for any injury and/or damage to persons or property as a matter of products liability, negligence or otherwise, or from any use or operation of any methods, products, instructions or ideas contained in the material herein. Because of rapid advances in the medical sciences, in particular, independent verification of diagnoses and drug dosages should be made British Library Cataloguing in Publication Data A catalogue record for this book is available from the British Library Library of Congress Cataloging-in-Publication Data A catalog record for this book is available from the Library of Congress ISBN: 978-0-08-099934-0 For information on all Newnes publications visit our web site at http://store.elsevier.com/ Printed and bound in the United States of America Typeset by Thomson Digital 14 15 16 17 18 10 9 8 7 6 5 4 3 2 1 Contents Preface ��������������������������������������������������������������������������������������������������������������xv Acknowledgments ���������������������������������������������������������������������������������������������xvii Chapter 1: Microcomputer Systems�����������������������������������������������������������������������1 1.1 Introduction ...................................................................................................................2 1.2 Microcontroller Systems ...............................................................................................2 1.2.1 RAM .................................................................................................................5 1.2.2 ROM .................................................................................................................6 1.2.3 PROM ...............................................................................................................6 1.2.4 EPROM .............................................................................................................6 1.2.5 EEPROM ..........................................................................................................6 1.2.6 Flash EEPROM ................................................................................................7 1.3 Microcontroller Features ...............................................................................................7 1.3.1 Supply Voltage ..................................................................................................7 1.3.2 The Clock .........................................................................................................7 1.3.3 Timers ...............................................................................................................8 1.3.4 Watchdog ..........................................................................................................8 1.3.5 Reset Input ........................................................................................................8 1.3.6 Interrupts ...........................................................................................................8 1.3.7 Brown-Out Detector .........................................................................................9 1.3.8 Analogue-to-Digital Converter .........................................................................9 1.3.9 Serial Input–Output ..........................................................................................9 1.3.10 EEPROM Data Memory ...............................................................................10 1.3.11 LCD Drivers .................................................................................................10 1.3.12 Analogue Comparator ...................................................................................10 1.3.13 Real-Time Clock ...........................................................................................10 1.3.14 Sleep Mode ...................................................................................................10 1.3.15 Power-On Reset ............................................................................................11 1.3.16 Low-Power Operation ..................................................................................11 1.3.17 Current Sink/Source Capability ....................................................................11 1.3.18 USB Interface ...............................................................................................11 1.3.19 Motor Control Interface ................................................................................11 1.3.20 CAN Interface ...............................................................................................11 1.3.21 Ethernet Interface .........................................................................................11 1.3.22 ZigBee Interface ...........................................................................................12 1.3.23 Multiply and Divide Hardware .....................................................................12 v vi Contents 1.3.24 Operating Temperature .................................................................................12 1.3.25 Pulse Width Modulated (PWM) Outputs ......................................................12 1.3.26 JTAG Interface ..............................................................................................12 1.3.27 Package Size .................................................................................................12 1.3.28 DMA .............................................................................................................12 1.4 Microcontroller Architectures .....................................................................................12 1.4.1 RISC and CISC ...............................................................................................13 1.5 8, 16, or 32 Bits? .........................................................................................................13 1.6 Summary ....................................................................................................................14 1.7 Exercises .....................................................................................................................14 Chapter 2: PIC32 Microcontroller Series �������������������������������������������������������������15 2.1 The PIC32MX360F512L Architecture .......................................................................18 2.1.1 The Memory ...................................................................................................21 2.1.2 The Microcontroller Clock .............................................................................25 2.1.3 Resets ..............................................................................................................28 2.1.4 The Input/Output Ports ...................................................................................29 2.1.5 The Parallel Master Port (PMP) .....................................................................33 2.1.6 Timers .............................................................................................................36 2.1.7 Real-Time Clock and Calendar ......................................................................47 2.1.8 Analogue-to-Digital Converter .......................................................................48 2.1.9 Interrupts .........................................................................................................55 2.2 Summary ....................................................................................................................59 2.3 Exercises .....................................................................................................................60 Chapter 3: PIC32 Microcontroller Development Tools ������������������������������������������61 3.1 Software Development Tools ......................................................................................62 3.1.1 Text Editors .....................................................................................................62 3.1.2 Assemblers and Compilers .............................................................................63 3.1.3 Simulators .......................................................................................................63 3.1.4 High-Level Language Simulators ...................................................................63 3.1.5 Simulators With Hardware Simulation ...........................................................64 3.1.6 Integrated Development Environment (IDE) ..................................................64 3.2 Hardware Development Tools .....................................................................................64 3.2.1 Development Boards ......................................................................................65 3.2.2 Device Programmers ......................................................................................79 3.2.3 In-Circuit Debuggers ......................................................................................80 3.2.4 In-Circuit Emulators .......................................................................................80 3.2.5 Breadboard......................................................................................................81 3.3 Summary ....................................................................................................................82 3.4 Exercises .....................................................................................................................83 Contents vii Chapter 4: The Cerebot MX3cK (chipKIT MX3) Development Board ���������������������85 4.1 The chipKIT MX3 Development Board .....................................................................86 4.1.1 Power Supply ..................................................................................................86 4.1.2 LEDs ...............................................................................................................88 4.1.3 Reset ...............................................................................................................88 4.1.4 Pmod Connectors ............................................................................................90 4.1.5 CPU Clock ......................................................................................................92 4.1.6 I2C Bus Interface .............................................................................................92 4.1.7 SPI Bus Interface ............................................................................................93 4.1.8 UART Interface...............................................................................................94 4.1.9 Analogue Inputs ..............................................................................................95 4.1.10 External Interrupts ........................................................................................95 4.1.11 Board Connectors and Jumpers ....................................................................96 4.2 Pmod Peripheral Modules ...........................................................................................97 4.2.1 PmodSD – SD Card Slot ................................................................................97 4.2.2 PmodCLP – Character LCD With Parallel Interface ......................................98 4.2.3 PmodKYPD ....................................................................................................98 4.2.4 PmodSSD .......................................................................................................98 4.2.5 PmodBTN .......................................................................................................98 4.2.6 PmodSTEP ...................................................................................................100 4.2.7 PmodTMP3 ...................................................................................................100 4.2.8 PmodDA1 .....................................................................................................101 4.2.9 PmodRTCC ...................................................................................................101 4.2.10 PmodBB .....................................................................................................101 4.2.11 PmodAMP2 ................................................................................................101 4.3 Summary ..................................................................................................................104 Chapter 5: The MPIDE Programming Environment and Programming in C �����������105 5.1 Installing MPIDE ......................................................................................................106 5.2 The MPIDE ...............................................................................................................107 5.2.1 The Menu ......................................................................................................107 5.2.2 The Toolbar ...................................................................................................108 5.2.3 The Status Line .............................................................................................109 5.2.4 The Output Window......................................................................................109 5.3 The C Language ........................................................................................................110 5.3.1 Comments .....................................................................................................111 5.3.2 White Spaces ................................................................................................111 5.3.3 Terminating Program Statements .................................................................112 5.3.4 Case Sensitivity ............................................................................................112 5.3.5 Variable Names .............................................................................................112 5.3.6 Data Types ....................................................................................................112 viii Contents 5.3.7 Number Bases ...............................................................................................114 5.3.8 Constants ......................................................................................................114 5.3.9 Escape Sequences .........................................................................................115 5.3.10 const Data Types .........................................................................................115 5.3.11 Arrays..........................................................................................................115 5.3.12 Pointers .......................................................................................................118 5.3.13 Structures ....................................................................................................121 5.3.14 Creating New Data Types ...........................................................................123 5.3.15 Unions .........................................................................................................124 5.3.16 Operators in C Language ............................................................................124 5.3.17 Modifying the Flow of Control ..................................................................131 5.4 Functions ...................................................................................................................143 5.4.1 Functions in C Language ..............................................................................144 5.4.2 Passing Parameters to Functions ..................................................................151 5.4.3 Passing Variables by Reference to Functions ...............................................156 5.4.4 Static Variables in Functions ........................................................................158 5.4.5 Function Prototypes ......................................................................................159 5.5 Microcontroller-Specific Features.............................................................................161 5.5.1 Microcontroller Digital Inputs and Outputs .................................................161 5.5.2 Logical I/O Port Pin Numbers ......................................................................161 5.5.3 Controlling the I/O Ports Using MPIDE ......................................................162 5.5.4 I/O Pin Voltage Levels ..................................................................................162 5.6 Built-In Functions .....................................................................................................163 5.6.1 Data Conversion Functions ...........................................................................164 5.6.2 Digital I/O Functions ....................................................................................164 5.6.3 Analogue I/O Functions ................................................................................164 5.6.4 Other I/O Functions ......................................................................................165 5.6.5 Time Functions .............................................................................................166 5.6.6 Mathematical Functions ...............................................................................166 5.6.7 Trigonometric Functions ..............................................................................167 5.6.8 Bit and Byte Functions .................................................................................168 5.6.9 Interrupt Enable/Disable Functions ..............................................................168 5.7 Summary ..................................................................................................................168 5.8 Exercises ...................................................................................................................169 Chapter 6: Microcontroller Program Development ����������������������������������������������173 6.1 Using the Program Description Language and Flow Charts .....................................174 6.1.1 BEGIN–END ................................................................................................174 6.1.2 Sequencing....................................................................................................174 6.1.3 IF–THEN–ELSE–ENDIF .............................................................................175 6.1.4 DO–ENDDO ................................................................................................175 Contents ix 6.1.5 REPEAT–UNTIL..........................................................................................177 6.1.6 Calling Subprograms ....................................................................................178 6.1.7 Subprogram Structure ...................................................................................178 6.2 Examples ...................................................................................................................178 6.3 Representing for Loops in Flow Charts ....................................................................183 6.3.1 Method 1 .......................................................................................................183 6.3.2 Method 2 .......................................................................................................184 6.3.3 Method 3 .......................................................................................................184 6.4 Summary ..................................................................................................................184 6.5 Exercises ...................................................................................................................185 Chapter 7: Simple chipKIT MX3–Based Projects ������������������������������������������������187 7.1 Project 7.1 – Flashing LED ......................................................................................192 7.1.1 Project Description ......................................................................................192 7.1.2 Current-Sinking ...........................................................................................192 7.1.3 Current-Sourcing .........................................................................................193 7.1.4 Project Hardware .........................................................................................193 7.1.5 Project PDL .................................................................................................193 7.1.6 Project Program ...........................................................................................194 7.2 Project 7.2 – Alternately Flashing LEDs .................................................................198 7.2.1 Project Description ......................................................................................198 7.2.2 Project Hardware .........................................................................................198 7.2.3 Project PDL .................................................................................................198 7.2.4 Project Program ...........................................................................................198 7.3 Project 7.3 – Lighthouse Flashing LED ...................................................................199 7.3.1 Project Description ......................................................................................199 7.3.2 Project Hardware .........................................................................................200 7.3.3 Project PDL .................................................................................................200 7.3.4 Project Program ...........................................................................................200 7.4 Project 7.4 – LED With Push-Button Switch ...........................................................201 7.4.1 Project Description ......................................................................................201 7.4.2 Block Diagram .............................................................................................201 7.4.3 Project Hardware .........................................................................................202 7.4.4 Project PDL .................................................................................................203 7.4.5 Project Program ...........................................................................................203 7.5 Project 7.5 – Wait Before Flashing the LED ............................................................204 7.5.1 Project Description ......................................................................................204 7.5.2 Block Diagram .............................................................................................206 7.5.3 Project Hardware .........................................................................................206 7.5.4 Project PDL .................................................................................................206 7.5.5 Project Program ...........................................................................................206

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.