Introduction to the Microcontroller Part of the Course

The Microcontroller

Common component in modern electronic systems
Single-chip computer
Microprocessor-based device
Completely self-contained with memory and I/O

Primary role: provide inexpensive, programmable logic control and interfacing to external devices
     e.g., turn devices on/off, monitor external conditions

Microcontrollers used in a wide number of electronic systems such as:

·Engine management systems in automobiles

·Keyboard of a PC

·Electronic measurement instruments (e.g., digital multimeters, frequency synthesisers, and oscilloscopes)


·Motor controls

·Security systems

·Cordless and cellular phones

·Televisions, radios, CD players, tape recording equipment

·Hearing aids

·Security alarm systems, fire alarm systems, and building services systems

·Microwave ovens

·Handheld tools

·Remote control devices

·Many, many more

  What is a microprocessor?

A device that integrates a number of useful functions into a single IC package
Some functions are:

·Ability to execute a stored set of instructions to carry out user defined tasks.

·Ability to access external memory chips to read/write data from/to memory.

·Ability to interface with I/O devices


These form the basic connections between the microprocessor and its memory devices.
Basic connections between the microprocessor and external memory


   What is I/O?

I/O is Input/Output. It can be:

·A number of digital bits formed into a number of digital inputs or outputs called a port

    usually eight bits wide
    referred to as a BYTE wide port

·A serial line from/to the microprocessor

   (Transmit or TX) and a serial line to the microprocessor (Receive or RX)
   Allows serial data (bit stream) to be transmitted/received via a two-wire interface

·Other I/O devices

    Analog to Digital Converters (ADC) and Digital to Analog Converters (DAC)
    Timer modules
    Interrupt controllers

Relatively complex subsystems
Can be obtained as separate ICs (e.g., Intel 8255 PPI, 8259 PIC, 8254 PIT)

Connected to microprocessor in a similar manner to that of the memory devices

Often contain their own memory to support internal operations (ie. registers).

   What is a microcontroller?

Basically, a device which integrates a number of the components of a microprocessor system onto a single chip

Only need to be supplied power and clocking

Microcontroller combines on the same chip:

·The CPU core



Variable RAM memory

Most microcontrollers will also combine other devices such as:

·A Timer module to allow the microcontroller to perform tasks for certain time periods.

·Serial I/O (UART) for data flow between microcontroller and devices such as a PC or other microcontroller.

·Analog input and output (e.g., to receive data from sensors or control motors)

·Interrupt capability (from a variety of sources)

·Bus/external memory interfaces (for RAM or ROM)

·Built-in monitor/debugger program

·Support for external peripherals (e.g., I/O and bus extenders)

A typical microcontroller; the different sub units integrated onto the microcontroller chip.

The heart of the microcontroller is the CPU core
     Traditionally based on an 8-bit microprocessor unit
     e.g., Motorola uses basic 6800 microprocessor core in M68HC11 microcontroller devices

Some differences between microprocessors and microcontrollers

MP: suited to contro of I/O devices requiring a minimum component count
MC: suited to processing information in computer systems

Instruction sets:
     MP: processing intensive
          powerful addressing modes
          instructions to perform complex operations & manipulate large volumes of data
          processing  capability of MCs never approaches those of MPs
          large instructions -- e.g., 80X86 7-byte long instructions
    MC: cater to control of inputs and outputs
          instructions to set/clear bits
          boolean operations (AND, OR, XOR, NOT, jump if a bit is set/cleared), etc.
          Extremely compact instructions, many implemented in one byte
                (Control program must often fit in the small, on-chip ROM)

Hardware & Instructionset support:
          MC: built-in I/O operations, event timing, enabling & setting up priority levels
          for interrupts caused by external stimuli
          MP: usually require external circuitry to do similar things (e.g, 8255 PPI, 8254 PIT,
                 8259 PIC)

Bus widths:
     MP: very wide
          large memory address spaces (>4 Gbytes)
          lots of data (Data bus: 32, 64, 128 bits wide)
    MC: narrow
          relatively small memory address spaces (typically kBytes)
          less data (Data bus typically 4, 8, 16 bits wide)

Clock rates:
     MP very fast (> 1 GHz)
     MC: Relatively slow (typically 10-20 MHz)
          since most I/O devices being controlled are relatively slow

     MP's expensive (often > $100)
     MCs cheap (often $1 - $10)
          4-bit:  < $1.00
          8-bit:  $1.00 - $8.00
         16-32-bit:  $6.00 - $20.00

Microcontroller Software and Programming Tools

     Generally done in either the core's native assembly language or C
     Sometimes HLL support (often BASIC) is available
     Assemblers/Linkers often supplied free by the micro's manufacturer
     C compilers vary from free and very buggy to very expensive and only moderately buggy
     Environments generally not friendly or reliable

     Program development usually done on a PC
     Software tools must produce a file to download to the MC's EPROM
     Several standard formats (e.g., binary, hex)
     EPROM burner often necessary
         Can download program to an EPROM emulator
But to reprogram, must us an UV erasor first
     Flash memory programmers make this easier
         Very easy to reprogram with inexpensive "in-circuit debugger"
              Interacts with MC via 3 pins + power + ground
              Or can be programmed/debugged with a resident monitor program
                   on-chip UART for communications with PC
         No burner or UV erasor needed
         No expensive quartz window required
         Expedites program-test-erase-reprogram code development cycle

     A program module that communicates with PC software
     Typically uses a serial port to talk to a PC's terminal program
     Capabilities vary widely
     Usually can send/receive text and ASCII-converted numbers
     Often has commands to examine/change registers, memory locations, I/O ports

Microcontroller Architectures
Princeton (Von Neumann) vs. Harvard
Princeton (Von Neumann) Architecture

     All memory space on same bus
     Every location has unique address
     So instructions and data treated the same way
          Possible bottleneck between instruction and data fetches
          Overcome with instruction prefetching (overlapping, pipelining) and/or Instruction/Data
     Simplifies processor design -- one memory interface
          More reliable -- fewer things can fail
     Also RAM can be used for both data and instruction storage
          Greater flexibility in design of software (esp. real-time OS)
     PC (80X86/Pentium) uses this arquitecture
          (except for separate I/O address space)
     Motorola 68HC11 microcontroller


Harvard Architecture
     Code and data strorage areas (address spaces) on separate buses
     Potentially more efficient
          Instructions execute in fewer cycles
               Since greater instruction parallelism possible
               Instructions and data fetched simultaneously
               (new instruction fetches can occur during prior instruction execution)
     Example: Microchip's PIC microcontroller


Princeton won early competition
     Better suited to technology of the time


CISC (Complex Instruction Set Computers)
     Tend to have many instruction in instruction set
     Can carry out complex operations
          (many used very infrequently)
     Many are very long (many bits)
     And require many clock cycles

RISC (Reduced Instruction Set Computer)
     Few instructions
     Simple instructions
     Short (few bits) and fast
     Often orthogonal instruction sets
          Can read/write/use all registers in same way
          Allows for great power and flexibility
     Example PICmicro
     Many other microcontrollers use RISC

Some microprocessors offer both CISC and RISC features

Microcoded versus Hardwired processors

The under cover design of a processor

     Processor within a processor
     Signals required to execute instructions "fetched" from internal "Control ROM" memory
     Allows for great flexibility in instruction set
     Easier to design
     Slower than hardwired

     Signals required to execute instruction generated by logic gates (combinational circuitry)
          The "control matrix"
     Less flexible


Some examples of Microcontrollers
Intel 8051

   Microchip's PICmicro
   Motorola 68HC11
   Hitachi H8 (used in the LEGOS RIS RCX)

Intel 8051

Introduced in late 70s
At the heart of the biggest variety of micros on earth
Biggest player now Philips Electronics (Intel concentrating on PC CPU chipset)

General pros:

     Powerful bit manipulation instructions
          part of RAM and many special registers are bit-addressable.
     Multiply and divide instructions.
     At least two 16-bit timers.
     UART capable of 500kb/s at 16MHz on all but very small parts.
     Plentiful internal RAM.
     Straightforward code addressing - always starts at zero.
     I/O design makes bi-directional I/O easy.
     Excellent free assembler from Metalink
     Free C compiler available

General cons:

     Very quirky instruction set
     Confusing variety of internal and external memory spaces.
     I/O design prevents true floating inputs, and pins are always high after reset.
     Not very fast due to clock division.
     Access to external data very weak - single pointer register only.
     Poor compiler support - no stack-relative access.
     Watchdog not standard

Microchip's PICmicro

Modern PIC16F452 trainer used in first half of this course

Harvard Architecture

Some pros:

Simple instruction set
Robust hardware
Excellent support
Microchip's MPLAB free development environment 
Wide range of sizes and peripheral choices
Many language and tool choices

Some cons:

4 times slower at same clock speed
Relatively weak instruction set
Limited code and data addressing
Complex "banked" addressing
Accumulator-based data processing
     Single "working" acculumulator

Motorola 68HC11 

Some pros:

Competetive with 8051
Von Neumann architecture is easy to understand
Powerful, easy-to-use instruction set
Popular parts are good value
Good support for C compilers
Good support from Motorola

Some cons:

Weak timers
No consistency within family - many variants specialised
Evaluation board (EVB) is expensive, unreliable
Not price-competitive
Old technology

Hitachi H8

Used in LEGO Mindstorms Robotics Invention System RCX
Similar architecture to the HC11

Some pros:

Many devices with flash.
Powerful instruction set with good C support
Wide range of 8 and 16-bit devices
Good free C compiler
Nice evaluation/programming boards available
Abundant timers and interrupts

Some Cons:

Most packages surface-mount
     Emulation expensive