PH415 Computer Interfacing 2013
OSU logo
Microcontrollers and Applications

Table of Contents

Introduction

  • Microprocessors (MPUs) lie at the core of modern instruments. A microcontroller (μC, uC or MCU) is a microprocessor core enhanced with a variety of input/output devices and other functional devices. Though very different from the CPUs of desktop and hand-held computers, μCs have many of the same basic attributes. Interfacing experimental hardware directly to a μC is a worthwhile endeavor because one can learn about two subjects of fundamental importance: how the arithmetic logic unit (ALU) operates in conjunction with memory and peripheral interfaces; how instruments can be designed and operated to provide the specific capabilities needed for an experimental system or a machine.
  • An absolutely necessary attribute of a laboratory instrument is deterministic behavior, that is, control signals are sent and data is acquired at precise times. To explore the timing precision of your desktop download real-time-test.py and open it with Geany. Run this program and notice that the time to complete the loops varies. Then open a Chrome window and reduce the size to about 1/4 of the full screen. Run the program, grab the Chrome window with the mouse, move it all over the screen and observe the execution times. Draw a conclusion about the timing precision attainable using a desktop computer with a busy operating system.
  • Many μC families are available from a variety of manufacturers, and it is difficult to select a family on which to expend the required time and effort. Selecting one device from many possibilities ranging from the venerable 8051 core to very high speed 32-bit devices is difficult. Factors important to the decision are the availability of development boards and reference designs and the availability and quality of programming tools.
  • The Arduino is a sytem of development and application boards based upon the Atmel ATmegaAVR series of 8-bit μCs. The Arduinos are very popular because of the simplicity of the basic boards, the availability of add-on cards (shields) from many sources and the quality of the open-source and cross-platform C-based IDE.
  • The Texas Instruments MSP430 family of microcontrollers provides a rich selection of ultra-low power 16-bit devices with flash memory, static RAM, general purpose digital I/O (GPIO), standard serial communications protocols, analog I/O, counters/timers and other capabilities. TI also provides many evaluation boards and reference designs along with Code Composer Studio, an IDE based upon Eclipse. CCS is available for Windows and Linux, and an open-source compiler and loader/debugger are available.
  • The 32-bit PIC microcontroller family from Microchip has a 32-bit register width, speed, IO ports, memory and special functions. For this course, the PIC32MX795F512L (specifications) has the balance of functionality useful for many applications requiring control of and data acquisition from experimental instruments. The ChipKit Max32 microcontroller board from Digilent uses this processor in an easy to use and expandable format. Furthermore, extensive libraries and an effective IDE are available.

Microprocessor Concepts

Arithmetic Logic Unit

  • An arithmetic logic unit (ALU) is a structure of logic gates that can perform the following operations on a data word of length 4 bits, 8 bits or more: ADD; SUBTRACT; AND; OR; NOT; XOR; shift left (multiply by 2); shift right (divide by 2). The data words are presented on two input ports, A and B. A port is defined as simply a set of lines into or out of the ALU. The result appears on port F. Since several N-bit ALUs can be used in parallel, a carry input and a carry output are necessary for addition, subtraction and shift operations. Exactly which instruction is executed is determined by an operation code (opcode) of length 4 bits, 8 bits or more. This code is presented to the ALU on port S. There can also be a set of flags available, such as zero result.
  • A simple ALU is the 74LS181 4-bit arithmetic logic unit (ALU). It is not difficult to implement the logic diagram of page 2 in an FPGA. Note the operations and opcodes in the function table of page 3. The Wikipedia ALU page has some references.

Basic MPU

  • Embellishing an ALU with more operations, a set of registers for temporary storage, address and data buses for communicating with external memory, internal memory, a pointer to the current memory location, a pointer to the current instruction, a block of memory defined as a stack, a pointer to the position of the top of the stack, interrupts and several flags leads to a basic MPU such as the venerable Intel 8080.
  • Peruse the architecture of the i8080 as an svg or a png file.
  • A modern version is the Intel MCS-51, better known as the 8051. Peruse the architecture as an svg or a png file.
  • Other important, early processors: very popular Zilog Z80, Motorola 6800, and the 6800-inspired MOS 6502.
  • High performance 8 to 32-bit 8051 cores are available for FPGAs..

Opcodes and Assembly Language

  • Assembly language is a human-readable representation of binary machine code.
  • View the instruction set of the 8051. The ANL set of opcodes perform AND operations with a variety of inputs.
    • ANL A,R1 performs an AND operation with register R1 and the special register A used as the accumulator. The machine code for this is the single byte 0x59, and the operation requires a single clock cycle.
    • ANL iram addr,#data performs an AND operation with data at the internal memory address iram addr and a byte specified by #data. The result appears in the accumulator A. The machine code for this consists of three bytes: 0x59, iram addr and #data. iram addr would be an address within the internal memory such as 0x03, and #data would be a number such as 0xf7. The operation requires two clock cycles.

Real-Time, Deterministic Behavior

  • A necessary attribute of a microcontroller is that it can perform operations without interruptions with timing precision determined by the clock frequency and jitter.

chipKIT Max32 Microcontroller Board

The Digilent chipKIT Max32 microcontroller board has been chosen for a number of reasons. It is based upon a PIC32 uC which has the speed and functionality needed for the course. The Max32 board is well-designed and can be enhanced with a shield and Pmods. It also very affordable. The availability of extensive code libraries and an IDE is important as well.

PIC32 Microcontroller

  • Looking at Figure 1-1 on page 33 of the PIC32MX795F512L datasheet, the microprocessor core is surrounded by a rich set of resources and IO devices. The features that will be used in this course are the following: USB serial communication port; SPI and I2C serial communications; 10-bit analog to digital converter (ADC); timers; memory; digital IO lines.

Digilent ChipKit Max32