This dev board has a socket to plug in a microcontroller (in this case a PIC32MX microcontroller of the 300 series). The dev board accepts PIMs (Plug-In Modules) to try out different microcontrollers. These are 100-pin packages, 25 pins per side arranged in a square.
The board has peripheral hardware like LEDs, an LCD screen, a serial port, and push buttons so you can write some programs to put the PIC32 through it's paces and see what it can do, interfacing with the world outside the PIM itself.
The photo also shows the PICkit3 programmer neccessary to load programs onto the microcontroller. Program code is written using Microchip's MPLAB software (on a host computer), and a USB cord connects the host computer to the PICkit3 to send the program over to flash memory on the dev board.
The book is set up as 16 "Days" worth of material. Each chapter explores one basic hardware peripheral of the PIC32MX family of microcontrollers, and one aspect of the C language per day.
Recommended Hardware and Software to Use with the Book:
All of the above hardware and software is made by Microchip Technology Incorporated (headquartered in Chandler, AZ), with the exception of the microcontroller core design, which is made by MIPS (San Jose, CA).
The MCU:
In order to program the PIC32, you need a physical device in between your dev board and your computer. There are many devices made for this (all proprietary Microchip products):
How do these connect to the Dev Board?
The concept:
Here are the options for the Debugger (under Debugger -> Select Tool)
The first half of the book can just use the simulator (MPLAB SIM) Debugger, not actually programming the board with the PICkit3. The second half of the book requires programming the hardware itself.
This book really should have started with Day 7, which talks about all the configuration options that are set each time a new program is flashed to the PIC32MX chip.
These configuration options select which oscillator feeds into the Primary Oscillator Clock Chain (which then defines the System Clock and the Peripheral Bus Clock, both used extensively in Chapters 1-6)
This configuration can be set to be programmed whenever you flash new code to the PIC32MX, or can be programmed dynamically in source code. For this book (at least for the early chapters), we'll be setting them directly.
The high-level idea:
All this is configured by setting just 3 special function registers (because these are each 32-bits wide). Within these SFRs are individual Fields which are set accordingly:
System Clock = 72 MHz
Peripheral Bus Clock = 36 MHz
Written in 2008, author has background in 8-bit microcontrollers and assembly language. Now migrating to Microchip's 16-bit and 32-bit MCUs.
Microchip Inc. has a horrible way of naming their chips:
"The PIC32 is a powerful machine based on a well established 32-bit core (MIPS)"
MIPS (Microprocessor without Interlocked Pipelined Stages) is a family of reduced instruction set computer (RISC) instruction set architectures (ISA) developed by MIPS Computer Systems, now MIPS Technologies, based in the United States.
There are multiple versions of MIPS: including MIPS I, II, III, IV, and V; as well as five releases of MIPS32/64 (for 32- and 64-bit implementations, respectively). The early MIPS architectures were 32-bit; 64-bit versions were developed later. As of April 2017, the current version of MIPS is MIPS32/64 Release 6. MIPS32/64 primarily differs from MIPS I–V by defining the privileged kernel mode System Control Coprocessor in addition to the user mode architecture.
Documentation needed for the PIC32MX360F512L (all published by Microchip Technology Inc):
Power supply: an unregulated DC supply of 9V to 15V (preferably 9V) supplied to J12. For default functionality, a power supply with a current capability of 250 mA is sufficient. The Explorer 16 kit does not include a power supply.
This chapter focuses on the embedded programming version of "hello world", light up some LEDs. A peripheral is examined: PortA. This is a 12-pin input/output peripheral routed to 12 pins on the PIC32 itself. It is controlled primarilty by two SFRs:
PORTA (set 1 for +3.3V output, set 0 for 0.0V output)
TRISA (set each pin as an Input or an Output)
8 of these pins are connected to LEDs on the Explorer 16 board. These LEDs live right below the PIM module and are in order: bits 7 6 5 4 3 2 1 0.
PORTA is 32-bits, so: 0x000000E1
will turn on LEDs in this fashion: 11100001
The "Hello World" program introduces the MPLAB IDE and it's built-in MPLAB SIM simulator.
The header file contains a long list of definitions for all the internal special-function registers (SFRs).
Running a program:
I/O pins on the PIC32:
Build All (Project):
****************************************************************** * Important note when using the simulator: That "Simulator Reset Button" is the key - it sets the green arrow / breakpoint to the main() function, and allows you to step through the program from there, using the step-into and step-over buttons. ******************************************************************
A closer look at PortA:This project expands on Hello World by using another peripheral, Timer1, to systematically turn LEDs on and off. Also covered:
Key concept: "When the main() function terminates and returns back to the startup code crt0, a new function _exit() is called and the PIC32 remains stuck there in a tight loop from which it can escape only if a processor reset is performed"
A proper application main loop is needed so it doesn't go to this _exit()
To run on real hardware, you'll need to utilize the Timer1 peripheral to introduce a delay between toggling the PORTA value (otherwise the LED will toggle several million times a second).
There are 3 SFRs that control most of Timer1's functions:Day 3's Project: lighting up the LED set attached to PortA in such a way that when the Explorer 16 board is moved quickly back and forth, a message will appear in big letters.
Use Logic Analyzer:The PIC32 has 32 registers (32-bits wide), and a 32-bit ALU.
The MPLAB C32 compiler assigns the following bit-sizes per datatype:
As far as PERFORMANCE, the 32-bit CPU can work as effienctly on 8, 16, or 32 bit values (one cycle each for math operations, thanks to the MMU and MDU units in the PIC32). 64 bit values will take a slight performance hit though.
As far as RESOURCES (limited RAM), datatype choices have direct consequences. For example, 8-bit values (char) only take up 1 byte of memory, not 4.
MIPS M4K Core ISA
To make sense of the disassembled code above, knowledge of the MIPS M4K ISA is needed. Like all other ISAs, this defines the number of registers, their definitions/names, the instruction types and instruction encoding, as well as the overall architecture such as the LOAD-STORE architecture MIPS uses.
The LOAD-STORE architecture is also known as "register-to-register" architecture. Basically, it means all operations (math/logic) are performed only on REGISTER contents, and so to work with RAM, values must be brought in from RAM (LOAD) and results must later be stored back into RAM (STORE).