Embedded Computing and Mechatronics with the PIC32 Microcontroller

Book description

For the first time in a single reference, this book provides the beginner with a coherent and logical introduction to the hardware and software of the PIC32, bringing together key material from the PIC32 Reference Manual, Data Sheets, XC32 C Compiler User's Guide, Assembler and Linker Guide, MIPS32 CPU manuals, and Harmony documentation. This book also trains you to use the Microchip documentation, allowing better life-long learning of the PIC32. The philosophy is to get you started quickly, but to emphasize fundamentals and to eliminate "magic steps" that prevent a deep understanding of how the software you write connects to the hardware.

Applications focus on mechatronics: microcontroller-controlled electromechanical systems incorporating sensors and actuators. To support a learn-by-doing approach, you can follow the examples throughout the book using the sample code and your PIC32 development board. The exercises at the end of each chapter help you put your new skills to practice.

Coverage includes:

  • A practical introduction to the C programming language
  • Getting up and running quickly with the PIC32
  • An exploration of the hardware architecture of the PIC32 and differences among PIC32 families
  • Fundamentals of embedded computing with the PIC32, including the build process, time- and memory-efficient programming, and interrupts
  • A peripheral reference, with extensive sample code covering digital input and output, counter/timers, PWM, analog input, input capture, watchdog timer, and communication by the parallel master port, SPI, I2C, CAN, USB, and UART
  • An introduction to the Microchip Harmony programming framework
  • Essential topics in mechatronics, including interfacing sensors to the PIC32, digital signal processing, theory of operation and control of brushed DC motors, motor sizing and gearing, and other actuators such as stepper motors, RC servos, and brushless DC motors

For more information on the book, and to download free sample code, please visit http://www.nu32.org

  • Extensive, freely downloadable sample code for the NU32 development board incorporating the PIC32MX795F512H microcontroller
  • Free online instructional videos to support many of the chapters

Table of contents

  1. Cover image
  2. Title page
  3. Table of Contents
  4. Copyright
  5. Dedication
    1. Figure Credits
  6. Preface
    1. Contents
    2. Choices made in this book
    3. The NU32 development board
    4. How to use this book in a course
    5. Website, videos, and flipped classrooms
    6. Other PIC32 references
  7. Acknowledgments
  8. I: Quickstart
    1. Chapter 1: Quickstart
      1. Abstract
      2. 1.1 What You Need
      3. 1.2 Compiling the Bootloader Utility
      4. 1.3 Compiling Your First Program
      5. 1.4 Loading Your First Program
      6. 1.5 Using make
      7. 1.6 Chapter Summary
  9. II: Fundamentals
    1. Chapter 2: Hardware
      1. Abstract
      2. 2.1 The PIC32
      3. 2.2 The NU32 Development Board
      4. 2.3 Chapter Summary
      5. 2.4 Exercises
    2. Chapter 3: Software
      1. Abstract
      2. 3.1 The Virtual Memory Map
      3. 3.2 An Example: simplePIC.c
      4. 3.3 What Happens When You Build?
      5. 3.4 What Happens When You Reset the PIC32?
      6. 3.5 Understanding simplePIC.c
      7. 3.6 Bootloaded Programs vs. Standalone Programs
      8. 3.7 Build Summary
      9. 3.8 Useful Command Line Utilities
      10. 3.9 Chapter Summary
      11. 3.10 Exercises
    3. Chapter 4: Using Libraries
      1. Abstract
      2. 4.1 Talking PIC
      3. 4.2 The NU32 Library
      4. 4.3 Bootloaded Programs
      5. 4.4 An LCD Library
      6. 4.5 Microchip Libraries
      7. 4.6 Your Libraries
      8. 4.7 Chapter Summary
      9. 4.8 Exercises
    4. Chapter 5: Time and Space
      1. Abstract
      2. 5.1 Compiler Optimization
      3. 5.2 Time and the Disassembly File
      4. 5.3 Space and the Map File
      5. 5.4 Chapter Summary
      6. 5.5 Exercises
    5. Chapter 6: Interrupts
      1. Abstract
      2. 6.1 Overview
      3. 6.2 Details
      4. 6.3 Steps to Configure and Use an Interrupt
      5. 6.4 Sample Code
      6. 6.5 Chapter Summary
      7. 6.6 Exercises
  10. III: Peripheral Reference
    1. Chapter 7: Digital Input and Output
      1. Abstract
      2. 7.1 Overview
      3. 7.2 Details
      4. 7.3 Sample Code
      5. 7.4 Chapter Summary
      6. 7.5 Exercises
    2. Chapter 8: Counter/Timers
      1. Abstract
      2. 8.1 Overview
      3. 8.2 Details
      4. 8.3 Sample Code
      5. 8.4 Chapter Summary
      6. 8.5 Exercises
    3. Chapter 9: Output Compare
      1. Abstract
      2. 9.1 Overview
      3. 9.2 Details
      4. 9.3 Sample Code
      5. 9.4 Chapter Summary
      6. 9.5 Exercises
    4. Chapter 10: Analog Input
      1. Abstract
      2. 10.1 Overview
      3. 10.2 Details
      4. 10.3 Sample Code
      5. 10.4 Chapter Summary
      6. 10.5 Exercises
    5. Chapter 11: UART
      1. Abstract
      2. 11.1 Overview
      3. 11.2 Details
      4. 11.3 Sample Code
      5. 11.4 Wireless Communication with an XBee Radio
      6. 11.5 Chapter Summary
      7. 11.6 Exercises
    6. Chapter 12: SPI Communication
      1. Abstract
      2. 12.1 Overview
      3. 12.2 Details
      4. 12.3 Sample Code
      5. 12.4 Chapter Summary
      6. 12.5 Exercises
    7. Chapter 13: I2C Communication
      1. Abstract
      2. 13.1 Overview
      3. 13.2 Details
      4. 13.3 Sample Code
      5. 13.4 Chapter Summary
      6. 13.5 Exercises
    8. Chapter 14: Parallel Master Port
      1. Abstract
      2. 14.1 Overview
      3. 14.2 Details
      4. 14.3 Sample Code
      5. 14.4 Chapter Summary
      6. 14.5 Exercises
    9. Chapter 15: Input Capture
      1. Abstract
      2. 15.1 Overview
      3. 15.2 Details
      4. 15.3 Sample Code
      5. 15.4 Chapter Summary
      6. 15.5 Exercises
    10. Chapter 16: Comparator
      1. Abstract
      2. 16.1 Overview
      3. 16.2 Details
      4. 16.3 Sample Code
      5. 16.4 Chapter Summary
      6. 16.5 Exercises
    11. Chapter 17: Sleep, Idle, and the Watchdog Timer
      1. Abstract
      2. 17.1 Overview
      3. 17.2 Details
      4. 17.3 Sample Code
      5. 17.4 Chapter Summary
      6. 17.5 Exercises
    12. Chapter 18: Flash Memory
      1. Abstract
      2. 18.1 Overview
      3. 18.2 Details
      4. 18.3 Sample Code
      5. 18.4 Chapter Summary
      6. 18.5 Exercises
    13. Chapter 19: Controller Area Network (CAN)
      1. Abstract
      2. 19.1 Overview
      3. 19.2 Details
      4. 19.3 Sample Code
      5. 19.4 Chapter Summary
      6. 19.5 Exercises
    14. Chapter 20: Harmony and Its Application to USB
      1. Abstract
      2. 20.1 Overview
      3. 20.2 The Framework
      4. 20.3 PLIB
      5. 20.4 Harmony Concepts
      6. 20.5 Drivers
      7. 20.6 System Services
      8. 20.7 Program Structure
      9. 20.8 USB
      10. 20.9 Chapter Summary
      11. 20.10 Exercises
  11. IV: Mechatronics
    1. Chapter 21: Sensors
      1. Abstract
      2. 21.1 Contact: Buttons and Switches
      3. 21.2 Light
      4. 21.3 Angle of a Revolute Joint
      5. 21.4 Position of a Prismatic Joint
      6. 21.5 Acceleration and Angular Velocity: Gyros, Accelerometers, and IMUs
      7. 21.6 Magnetic Field Sensing: Hall Effect Sensors
      8. 21.7 Distance
      9. 21.8 Force
      10. 21.9 Temperature
      11. 21.10 Current
      12. 21.11 GPS
      13. 21.12 Exercises
    2. Chapter 22: Digital Signal Processing
      1. Abstract
      2. 22.1 Sampled Signals and Aliasing
      3. 22.2 The Discrete Fourier Transform
      4. 22.3 Finite Impulse Response (FIR) Digital Filters
      5. 22.4 Infinite Impulse Response (IIR) Digital Filters
      6. 22.5 FFT-Based Filters
      7. 22.6 DSP on the PIC32
      8. 22.7 Exercises
    3. Chapter 23: PID Feedback Control
      1. Abstract
      2. 23.1 The PID Controller
      3. 23.2 Variants of the PID Controller
      4. 23.3 Empirical Gain Tuning
      5. 23.4 Model-Based Control
      6. 23.5 Chapter Summary
      7. 23.6 Exercises
    4. Chapter 24: Feedback Control of LED Brightness
      1. Abstract
      2. 24.1 Wiring and Testing the Circuit
      3. 24.2 Powering the LED with OC1
      4. 24.3 Playing an Open-Loop PWM Waveform
      5. 24.4 Establishing Communication with MATLAB
      6. 24.5 Plotting Data in MATLAB
      7. 24.6 Writing to the LCD Screen
      8. 24.7 Reading the ADC
      9. 24.8 PI Control
      10. 24.9 Additional Features
      11. 24.10 Chapter Summary
      12. 24.11 Exercises
    5. Chapter 25: Brushed Permanent Magnet DC Motors
      1. Abstract
      2. 25.1 Motor Physics
      3. 25.2 Governing Equations
      4. 25.3 The Speed-Torque Curve
      5. 25.4 Friction and Motor Efficiency
      6. 25.5 Motor Windings and the Motor Constant
      7. 25.6 Other Motor Characteristics
      8. 25.7 Motor Data Sheet
      9. 25.8 Chapter Summary
      10. 25.9 Exercises
    6. Chapter 26: Gearing and Motor Sizing
      1. Abstract
      2. 26.1 Gearing
      3. 26.2 Choosing a Motor and Gearhead
      4. 26.3 Chapter Summary
      5. 26.4 Exercises
    7. Chapter 27: DC Motor Control
      1. Abstract
      2. 27.1 The H-Bridge and Pulse Width Modulation
      3. 27.2 Motion Control of a DC Motor
      4. 27.3 Chapter Summary
      5. 27.4 Exercises
    8. Chapter 28: A Motor Control Project
      1. Abstract
      2. 28.1 Hardware
      3. 28.2 Software Overview
      4. 28.3 Software Development Tips
      5. 28.4 Step by Step
      6. 28.5 Extensions
      7. 28.6 Chapter Summary
      8. 28.7 Exercises
    9. Chapter 29: Other Actuators
      1. Abstract
      2. 29.1 Solenoids
      3. 29.2 Speakers and Voice Coil Actuators
      4. 29.3 RC Servos
      5. 29.4 Stepper Motors
      6. 29.5 Brushless DC Motors
      7. 29.6 Linear Brushless Motors
      8. 29.7 Chapter Summary
      9. 29.8 Exercises
  12. Appendix A: A Crash Course in C
    1. A.1 Quick Start in C
    2. A.2 Overview
    3. A.3 Important Concepts in C
    4. A.4 C Syntax
    5. A.5 Exercises
  13. Appendix B: Circuits Review
    1. B.1 Basics
    2. B.2 Linear Elements: Resistors, Capacitors, and Inductors
    3. B.3 Nonlinear Elements: Diodes and Transistors
    4. B.4 Operational Amplifiers
    5. B.5 Modular Circuit Design: Input and Output Impedance
  14. Appendix C: Other PIC32 Models
    1. C.1 The PIC32MX5xx/6xx/7xx Family
    2. C.2 PIC32MX3xx/4xx Family
    3. C.3 PIC32MX1xx/2xx Family
    4. C.4 PIC32MX1xx/2xx/5xx 64-100 Pin Family
    5. C.5 PIC32MX330/350/370/430/450/470 Family
    6. C.6 PIC32MZ Family
    7. C.7 Conclusion
  15. Index

Product information

  • Title: Embedded Computing and Mechatronics with the PIC32 Microcontroller
  • Author(s): Kevin Lynch, Nicholas Marchuk, Matthew Elwin
  • Release date: December 2015
  • Publisher(s): Newnes
  • ISBN: 9780124202351