Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

PIC32 Microcontrollers and the Digilent Chipkit: Introductory to Advanced Projects
PIC32 Microcontrollers and the Digilent Chipkit: Introductory to Advanced Projects
PIC32 Microcontrollers and the Digilent Chipkit: Introductory to Advanced Projects
Ebook701 pages3 hours

PIC32 Microcontrollers and the Digilent Chipkit: Introductory to Advanced Projects

Rating: 5 out of 5 stars

5/5

()

Read preview

About this ebook

PIC32 Microcontrollers and the Digilent chipKIT: Introductory to Advanced Projects will teach you about the architecture of 32-bit processors and the hardware details of the chipKIT development boards, with a focus on the chipKIT MX3 microcontroller development board. Once the basics are covered, the book then moves on to describe the MPLAB and MPIDE packages using the C language for program development. The final part of the book is based on project development, with techniques learned in earlier chapters, using projects as examples.

Each projectwill have a practical approach, with in-depth descriptions and program flow-charts with block diagrams, circuit diagrams, a full program listing and a follow up on testing and further development.

With this book you will learn:

  • State-of-the-art PIC32 32-bit microcontroller architecture
  • How to program 32-bit PIC microcontrollers using MPIDE, MPLAB, and C language
  • Core features of the chipKIT series development boards
  • How to develop simple projects using the chipKIT MX3 development board and Pmod interface cards
  • how to develop advanced projects using the chipKIT MX3 development boards
  • Demonstrates how to use the PIC32 series of microcontrollers in real, practical applications, and make the connection between hardware and software programming
  • Usage of the PIC32MX320F128H microcontroller, which has many features of the PIC32 device and is included on the chipKIT MX3 development board
  • Uses the highly popular chipKIT development boards, and the PIC32 for real world applications, making this book one of a kind
LanguageEnglish
Release dateJan 9, 2015
ISBN9780080999357
PIC32 Microcontrollers and the Digilent Chipkit: Introductory to Advanced Projects
Author

Dogan Ibrahim

Dogan Ibrahim graduated from the University of Salford with First Class Honours in Electronic Engineering. He then completed an MSc course in Automatic Control Engineering at the University of Manchester, and PhD in Digital Signal Processing at the City University in London. Prof Ibrahim worked at several companies and gained industrial experience before returning to the academic life. Prof Ibrahim is currently a Fellow of the IET, and a Chartered Electrical Engineer. His interests are in the fields of microcontroller based automatic control, digital signal processing, and computer aided design. Dogan Ibrahim has been a lecturer at South Bank University, London, and Principal Research Engineer at GEC Hirst Research Centre. Prof Ibrahim is the author of over 70 technical books in the fields of microcontrollers and electronic engineering. He is currently a systems consultant, carrying out consultancy work to various firms in London.

Read more from Dogan Ibrahim

Related to PIC32 Microcontrollers and the Digilent Chipkit

Related ebooks

Industrial Design For You

View More

Related articles

Reviews for PIC32 Microcontrollers and the Digilent Chipkit

Rating: 5 out of 5 stars
5/5

1 rating0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    PIC32 Microcontrollers and the Digilent Chipkit - Dogan Ibrahim

    PIC32 Microcontrollers and the Digilent chipKIT

    Introductory to Advanced Projects

    Dogan Ibrahim

    Table of Contents

    Cover

    Title page

    Copyright

    Preface

    Acknowledgments

    Chapter 1: Microcomputer Systems

    Abstract

    1.1. Introduction

    1.2. Microcontroller Systems

    1.3. Microcontroller Features

    1.4. Microcontroller Architectures

    1.5. 8, 16, or 32 Bits?

    1.6. Summary

    1.7. Exercises

    Chapter 2: PIC32 Microcontroller Series

    Abstract

    2.1. The PIC32MX360F512L Architecture

    2.2. Summary

    2.3. Exercises

    Chapter 3: PIC32 Microcontroller Development Tools

    Abstract

    3.1. Software Development Tools

    3.2. Hardware Development Tools

    3.3. Summary

    3.4. Exercises

    Chapter 4: The Cerebot MX3cK (chipKIT MX3) Development Board

    Abstract

    4.1. The chipKIT MX3 Development Board

    4.2. Pmod Peripheral Modules

    4.3. Summary

    Chapter 5: The MPIDE Programming Environment and Programming in C

    Abstract

    5.1. Installing MPIDE

    5.2. The MPIDE

    5.3. The C LANGUAGE

    5.4. Functions

    5.5. Microcontroller-Specific Features

    5.6. Built-In Functions

    5.7. Summary

    5.8. Exercises

    Chapter 6: Microcontroller Program Development

    Abstract

    6.1. Using the Program Description Language and Flow Charts

    6.2. Examples

    6.3. Representing for Loops in Flow Charts

    6.4. Summary

    6.5. Exercises

    Chapter 7: Simple chipKIT MX3–Based Projects

    Abstract

    7.1. Project 7.1 – Flashing LED

    7.2. Project 7.2 – Alternately Flashing LEDs

    7.3. Project 7.3 – Lighthouse Flashing LED

    7.4. Project 7.4 – LED With Push-Button Switch

    7.5. Project 7.5 – Wait Before Flashing the LED

    7.6. Project 7.6 – LED With Two Push-Button Switches

    7.7. Project 7.7 – Rotating LEDs

    7.8. Project 7.8 – Random Flashing LEDs

    7.9. Project 7.9 – Fading LED

    7.10. Project 7.10 – Seven-Segment LED

    7.11. Project 7.11 – Seven-Segment Single-Digit LED Counter

    7.12. Project 7.12 – Using LCD Display

    7.13. Project 7.13 – Scrolling LCD Display

    7.14. Project 7.14 – Seconds Counter With LCD Display

    7.15. Project 7.15 – Event Counter With LCD Display

    7.16. Project 7.16 – External Interrupt–Driven Event Counter With LCD Display

    7.17. Project 7.17 – Voltmeter

    7.18. Project 7.18 – Temperature Measurement

    7.19. Project 7.19 – Temperature Measurement With Serial Monitor Display

    7.20. Project 7.20 – NPN Transistor Tester

    7.21. Project 7.21 – Writing to SD Card

    7.22. Project 7.22 – Reading From SD Card and Displaying on Serial Monitor

    7.23. Project 7.23 – Temperature Data Logging on SD Card

    7.24. Project 7.24 – Generating Sound Using a Buzzer

    7.25. Project 7.25 – Generating Melody Using a Buzzer

    7.26. Project 7.26 – Using an Audio Amplifier

    7.27. Project 7.27 – Waveform Generation: Using DAC

    7.28. Project 7.28 – Using a Keypad

    7.29. Project 7.29 – Keypad Calculator

    7.30. Project 7.30 – Using Graphics LCD

    7.31. Project 7.31 – Creating an Image on the OLED

    7.32. Project 7.32 – I²C Thermometer With OLED Display

    7.33. Project 7.33 – Using the GPS Module

    7.34. Project 7.34 – Stepper Motors

    Appendix: Using the MPLAB IDE with the chipKIT Pro MX7 Development Board

    Index

    Copyright

    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

    Preface

    A microcontroller is a single-chip microprocessor system that contains data and program memory, serial and parallel I/O, timers, and external and internal interrupts, all integrated into a single chip that can be purchased for as little as $2.00. About 40% of microcontroller applications are in office automation, such as PCs, laser printers, fax machines, intelligent telephones, and so forth. About one-third of microcontrollers are found in consumer electronic goods. Products such as CD players, hi-fi equipment, video games, washing machines, cookers, and so on fall into this category. The communications market, automotive market, and the military share the rest of the application areas.

    This book is written for students, for practising engineers, and for hobbyists who want to learn more about the programming and applications of PIC 32-bit series of microcontrollers. It has been written with the assumption that the reader has taken a course on digital logic design, and has been exposed to writing programs using at least one high-level programming language. Knowledge of the C programming language will be useful. Also, familiarity with at least one member of the PIC series of microcontrollers (e.g., PIC16 or PIC18) will be an advantage. The knowledge of assembly language programming is not required because all the projects in the book are based on using the C (and C++) language.

    chipKIT is a series of 32-bit PIC microcontroller-based development boards designed and manufactured by Digilent Inc. (www.digilentinc.com). There are many such development boards in the series, starting from the basic chipKIT Uno32 and chipKIT MX3 to more advanced chipKIT Pro MX4, chip KIT Pro MX7, and so on. These boards are complete 32-bit microcontroller development systems compatible with the MPIDE and the MPLAB IDE integrated development environments. The boards are supported by a large number of plug-in peripheral interface modules called Pmods. Some examples of Pmod modules are: LED arrays, seven-segment display, push-button switches, keypad, LCD, OLED, temperature sensor, GPS, stepper motor controller, and many more. The chipKIT PIC32-based systems are compatible with many existing Arduino® code examples, reference material, and other resources, thus making the programming easy. In this book, many tested and working projects are given based on the chipKIT MX3 development board and the MPIDE integrated development environment.

    Chapter 1 presents the basic features of microcontrollers and gives example of a simple microcontroller-based fluid-level control system.

    Chapter 2 provides a review of the PIC32 series of 32-bit microcontrollers. Various features of these microcontrollers are described in detail. The highly popular PIC32MX360F512L microcontroller has been chosen as an example 32-bit microcontroller.

    Chapter 3 is about the 32-bit microcontroller development tools. The basic features of various development boards available in the market are given in this chapter.

    Chapter 4 discusses the features of the popular chipKIT MX3 (formerly known as the Cerebot MX3cK) 32-bit development board in detail. This development board is used in the projects in this book.

    Chapter 5 is about the MPIDE integrated development environment. The chapter discusses various features of this IDE and gives programming examples.

    Chapter 6 describes the commonly used microcontroller program development tools. Flow charts and the program description language (PDL) are explained in this chapter with examples.

    Chapter 7 provides projects using the chipKIT MX3 development board with the MPIDE integrated development environment. Many tested and working projects are given in this chapter. The following are given for each project:

    • Project title

    • Project description

    • Project hardware

    • Project PDL

    • Complete project program listing

    • Full description of the program

    • Comments for future development (where necessary)

    Finally, the Appendix describes how the MPLAB IDE can be used in developing applications with the chipKIT boards. chipKIT Pro MX7 (formerly known as the Cerebot MX7cK) development board is taken as an example, and a simple project is developed to illustrate the basic steps.

    Dogan Ibrahim

    London

    Acknowledgments

    The following material is reproduced in this book with the kind permission of the respective copyright holders and may not be reprinted, or reproduced in any way, without their prior consent.

    Figures 2.1–2.5, 2.8, and 2.15–2.35 are taken from Microchip Technology Inc. Data Sheet PIC32MX3XX/4XX (DS61143E). Figures 3.1–3.5 are taken from the web site of Microchip Technology Inc.

    Figures 3.6–3.11 and Pmod peripheral interface module pictures are taken from the web site of Digilent Inc.

    Figures 3.12–3.16, 3.19, and 3.20 are taken from the web site of mikroElektronika.

    Figures 3.17 and 3.18 are taken from the web site of Olimex.

    I would like to thank my son Ahmet Ibrahim who has helped in the construction and testing of the projects in this book.

    PIC®, PICSTART®, and MPLAB® are all trademarks of Microchip Technology Inc.

    Chapter 1

    Microcomputer Systems

    Abstract

    This chapter is an introduction to microcontrollers. The basic features of microcontrollers are described briefly with some typical application areas of microcontrollers.

    Keywords

    Microcontrollers

    Microprocessors

    Microcontroller features

    Microcontroller applications

    Chapter Outline

    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

    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

    1.1. Introduction

    The term microcomputer is used to describe a system that includes a minimum of a microprocessor, program memory, data memory, and input–output (I/O). Some microcomputer systems include additional components such as timers, counters, analogue-to-digital converters (ADCs), and so on. Thus, a microcomputer system can be anything from a large computer having hard disks, floppy disks, and printers to a single-chip embedded controller.

    In this book, we are going to consider only the type of microcomputers that consists of a single silicon chip. Such microcomputer systems are also called microcontrollers, and they are used in many household goods such as microwave ovens, TV remote control units, cookers, hi-fi equipment, CD players, personal computers, fridges, etc. There are a large number of microcontrollers available in the market. In this book, we shall be looking at the programming and system design using the 32-bit programmable interface controller (PIC) series of microcontrollers manufactured by Microchip Technology Inc.

    1.2. Microcontroller Systems

    A microcontroller is a single-chip computer. Micro suggests that the device is small, and controller suggests that the device can be used in control applications. Another term used for microcontrollers is embedded controller, since most of the microcontrollers are built into (or embedded in) the devices they control.

    A microprocessor differs from a microcontroller in many ways. The main difference is that a microprocessor requires several other components for its operation, such as program memory and data memory, I/O devices, and external clock circuit. A microcontroller, on the other hand, has all the support chips incorporated inside the same chip. All microcontrollers operate on a set of instructions (or the user program) stored in their memory. A microcontroller fetches the instructions from its program memory one by one, decodes these instructions, and then carries out the required operations.

    Microcontrollers have traditionally been programmed using the assembly language of the target device. Although the assembly language is fast, it has several disadvantages. An assembly program consists of mnemonics, and it is difficult to learn and maintain a program written using the assembly language. Also, microcontrollers manufactured by different firms have different assembly languages and the user is required to learn a new language every time a new microcontroller is to be used. Microcontrollers can also be programmed using a high-level language, such as BASIC, PASCAL, and C. High-level languages have the advantage that it is much easier to learn a high-level language than an assembler. Also, very large and complex programs can easily be developed using a high-level language.

    In general, a single chip is all that is required to have a running microcontroller system. In practical applications, additional components may be required to allow a microcomputer to interface to its environment. With the advent of the PIC family of microcontrollers, the development time of an electronic project has reduced to several hours.

    Basically, a microcomputer (or microcontroller) executes a user program that is loaded in its program memory. Under the control of this program, data is received from external devices (inputs), manipulated, and then sent to external devices (outputs). For example, in a microcontroller-based fluid level control system, the fluid level is read by the microcomputer via a level sensor device and the microcontroller attempts to control the fluid level at the required value. If the fluid level is low, the microcomputer operates a pump to draw more fluid from the reservoir in order to keep the fluid at the required level. Figure 1.1 shows the block diagram of our simple fluid level control system.

    Figure 1.1   Microcontroller-Based Fluid Level Control System

    The system shown in Figure 1.1 is a very simplified fluid level control system. In a more sophisticated system, we may have a keypad to set the required fluid level and an LCD to display the current level in the tank. Figure 1.2 shows the block diagram of this more sophisticated fluid level control system.

    Figure 1.2   Fluid Level Control System With a Keypad and LCD

    We can make our design even more sophisticated (see Figure 1.3) by adding an audible alarm to inform us if the fluid level is outside the required value. Also, the actual level at any time can be sent to a PC every second for archiving and further processing. For example, a graph of the daily fluid level changes can be plotted on the PC. As you can see, because the microcontrollers are programmable, it is very easy to make the final system as simple or as complicated as we like.

    Figure 1.3   More Sophisticated Fluid Level Controller

    A microcontroller is a very powerful tool that allows a designer to create sophisticated I/O data manipulation under program control. Microcontrollers are classified by the number of bits they process. 8-bit devices are the most popular ones and are used in most low-cost, low-speed microcontroller-based applications. 16- and 32-bit microcontrollers are much more powerful, but usually more expensive, and their use may not be justified in many small- to medium-sized general-purpose applications.

    The simplest microcontroller architecture consists of a microprocessor, memory, and I/O. The microprocessor consists of a central processing unit (CPU) and the control unit (CU). The CPU is the brain of the microcontroller, and this is where all of the arithmetic and logic operations are performed. The CU controls the internal operations of the microprocessor and sends out control signals to other parts of the microcontroller to carry out the required instructions.

    Memory is an important part of a microcontroller system. Depending on the type used, we can classify memories into two groups: program memory and data memory. Program memory stores the programs written by the programmer, and this memory is usually nonvolatile, that is, data is not lost after the removal of power. Data memory is where the temporary data used in a program is stored, and this memory is usually volatile, that is, data is lost after the removal of power.

    There are basically six types of memories, summarised as follows.

    1.2.1. RAM

    RAM means random access memory. It is a general-purpose memory that usually stores the user data in a program. RAM memory is volatile in the sense that it cannot retain data in the absence of power, that is, data is lost after the removal of power. Most microcontrollers have some amount of internal RAM. Several kilobytes is a common amount, although some microcontrollers have much more, and some have less. For example, the PIC32MX460F512L 32-bit microcontroller has 512 kilobytes of RAM. In general, it is possible to extend the memory by adding external memory chips.

    1.2.2. ROM

    ROM is read-only memory. This type of memory usually holds program or fixed user data. ROM is nonvolatile. If power is removed from ROM and then reapplied, the original data will still be there. ROM memories are programmed at factory during the manufacturing process, and their contents cannot be changed by the user. They are useful only if we have developed a program and wish to order several thousand copies of it, or if we wish to store some configuration data.

    1.2.3. PROM

    PROM is programmable read-only memory. This is a type of ROM that can be programmed in the field, often by the end user, using a device called a PROM programmer. Once a PROM has been programmed, its contents cannot be changed. PROMs are usually used in low-production applications where only several such memories are required.

    1.2.4. EPROM

    EPROM is erasable programmable read-only memory. This is similar to ROM, but the EPROM can be programmed using a suitable programming device. EPROM memories have a small clear glass window on top of the chip where the data can be erased under strong ultraviolet light. Once the memory is programmed, the window can be covered with dark tape to prevent accidental erasure of the data. An EPROM memory must be erased before it can be reprogrammed. Many development versions of microcontrollers are manufactured with EPROM memories where the user program can be stored. These memories are erased and reprogrammed until the user is satisfied with the program. Some versions of EPROMs, known as one-time programmable (OTP), can be programmed using a suitable programmer device, but these memories cannot be erased. OTP memories cost much less than the EPROMs. OTP is useful after a project has been developed completely and it is required to make many copies of the program memory.

    1.2.5. EEPROM

    EEPROM is electrically erasable programmable read-only memory, which is a nonvolatile memory. These memories can be erased and also be reprogrammed using suitable programming devices. EEPROMs are used to save configuration information, maximum and minimum values, identification data, etc.

    1.2.6. Flash EEPROM

    This is another version of EEPROM-type memory. This memory has become popular in microcontroller applications and is generally used to store the user program. Flash EEPROM is nonvolatile and is usually very fast. The data can be erased and then reprogrammed using a suitable programming device. These memories can also be programmed without removing them from their circuits. Some microcontrollers have only 1k flash EEPROM, while some others have 32k or more.

    1.3. Microcontroller Features

    Microcontrollers from different manufacturers have different architectures and different capabilities. Some may suit a particular application, while others may be totally unsuitable for the same application. The hardware features of microcontrollers in general are described in this section.

    1.3.1. Supply Voltage

    Most microcontrollers operate with the standard logic voltage of +5 V. Some microcontrollers can operate at as low as +2.7 V, and some will tolerate +6 V without any problems. You should check the manufacturers’ data sheets about the allowed limits of the power supply voltage. For example, PIC32MX460F512L 32-bit microcontrollers can operate with a power supply of +2.3 to +3.6 V.

    A voltage regulator circuit is usually used to obtain the required power supply voltage when the device is to be operated from a mains adaptor or batteries. For example, a 5 V regulator may be required if the microcontroller and peripheral devices operate from a +5 or +3.3 V supply and a 9 V battery is to be used as the power supply.

    1.3.2. The Clock

    All microcontrollers require a clock (or an oscillator) to operate. The clock is usually provided by connecting external timing devices to the microcontroller. Most microcontrollers will generate clock signals when a crystal and two small capacitors are connected. Some will operate with resonators or external resistor–capacitor pairs. Some microcontrollers have built-in timing circuits, and they do not require any external timing components. If your application is not time-sensitive, you should use external or internal (if available) resistor–capacitor timing components for simplicity and low cost.

    An instruction is executed by fetching it from the memory and then decoding it. This usually takes several clock cycles and is known as the instruction cycle. PIC32 series of microcontrollers can operate with clock frequencies up to 80 MHz.

    1.3.3. Timers

    Timers are important parts of any microcontroller. A timer is basically a counter that is driven either from an external clock pulse or from the internal oscillator of the microcontroller. A PIC32 microcontroller can have 16- or 32-bit wide timers (two 16-bit timers are combined to create a 32-bit timer). Data can be loaded into a timer under program control, and the timer can be stopped or started by program control. Most timers can be configured to generate an interrupt when they reach a certain count (usually when they overflow). The interrupt can be used by the user program to carry out accurate timing-related operations inside the microcontroller.

    Some microcontrollers offer capture and compare facilities where a timer value can be read when an external event occurs, or the timer value can be compared with a preset value and an interrupt can be generated when this value is reached. PIC32 microcontrollers can have up to five capture inputs.

    1.3.4. Watchdog

    Most microcontrollers have at least one watchdog facility. The watchdog is basically a timer that is refreshed by the user program and a reset occurs if the program fails to refresh the watchdog. The watchdog timer is used to detect a system problem, such as the program being in an endless loop. A watchdog is a safety feature that prevents runaway software and stops the microcontroller from executing meaningless and unwanted code. Watchdog facilities are commonly used in real-time systems for safety where it may be required to regularly check the successful termination of one or more activities.

    1.3.5. Reset Input

    A reset input is used to reset a microcontroller externally. Resetting puts

    Enjoying the preview?
    Page 1 of 1