DPRG
DPRG Events Shoptalk

Website design and hosting by NCC

MCU Primer

July 1997, Written by Erick Wagner, Kip Moravec, and Jim Brown
August 2002, page format revised, links updated by NCC

Computer Basics

Microprocessor You are probably familiar with the term microprocessor. All personal computers have one. It is a chip that does all of the computing in your computer. They have names like Pentium, 80486DX2, MC68040, PowerPC, and many varients. For them to work correctly they have to have a lot of things around them.
The Clock The first thing is a clock, that sets the speed the processor and all of the devices will be synchronized to. Since I am a PC person, not a Mac person, I will use PC processors for examples. Different Pentium processors can be found that run at 60 MHz up to 266 MHz. In general, a 266 MHz Pentium will run at a little less than 4 times as fast as a 60 MHz Pentium. Do not compare clocks between different processors, because different processor architectures have different throughput. So two different types of processors running at 166 MHz do not process at the same speed.
Memory The second item is memory. The processor uses memory to store programs and to store data. In personal computers there are two types of memory, ROM and RAM. ROM is Read-Only Memory. The computer can only read it, it can not write to it. RAM is Random Access Memory. The computer can read and write to it. In a PC there is usually 8, 16, 32, or 64 Megabytes (1 Megabyte = 1,048,576 bytes, but usually people say one million bytes).
Boot A PC uses ROM to start itsself. When power is turned on, the computer executes a program in ROM that tests the computer, and loads the operating system from a disk, and then executes the operating system (DOS, OS2, Windows, NT, Linux, etc.)
Peripherals After memory, there are peripherials, so named because the operate on the periphery of the computer. Common peripherials for computers are serial ports, parallel ports, disks and disk controllers, magnetic tape drives and controllers, ethernet controllers, etc.

Microcontrollers

Microcontrollers Where PC is designed to be very general to perform any number of tasks (programs) and microcontrollers are used to perform specialized single tasks, (more or less). Instead of running Quicken for your finances, the microcontroller may be keeping your tires from locking up if you have ABS, or controlling the speed on your blender, or the operation of your microwave or VCR.
One Chip Solution Whereas a CPU is just a central processing unit and requires "glue" chips to help it run, a microcontroller tries to put everything on a single chip. It has a processor, memory, and peripherials all often on one chip. The tradeoff is usually speed for cost. While processors for PC cost as much as $500 and run at 266 MHz (Million cycles per second), and need a lot of support chips to make them work (look at the board in your computer) Most microcontrollers run from 3.5 MHz to 32 MHz and need very few other chips to work.
Microcontroller limits Most microcontrollers are limited to 64 Kilobytes (1 Kilobyte(KB) = 1024 bytes) of Data (for reading and writing) and 64 KB of program (for reading only) This is just a fraction of the memory that is in today's PCs. Many of the robotic controllers get by with less than 8 KB data and 32 KB Program. 8 KB is 1/1024 of the RAM in a 8 MB PC!

With this little amount of memory the memory can reside on the microcontroller or external to the microcontroller. If it is external, then it can reside in one chip.

Microcontroller memory There are different kinds of memory, that you should be aware of for a microcontroller. First lets talk about memory that keeps its data/program when there is no power. I mentioned ROM. ROM is programmed at the semiconductor factory as the memory is built. It is the cheapest in high quantities, but we do not approach that quantity with our robots. :) PROM is Programmable Read-Only Memory, which means you can program it once. If there is a bug in your program, throw the PROM away and program a new one. EPROM is Erasable Programable Read-Only Memory. This memory is like PROM you program it, but it has a little window in the chip. If it is exposed to a high intensity ultraviolet lamp for a few minutes, it will erase the memory, and you can program it again. EEPROM is Electrically Erasable Programable Read-Only Memory it can be reprogrammed without exposing it to UV light. The tradeoff here is convenience versus price. Each one I talked about is more expensive than the predecesor.

There is also memory that loses its data when the power is removed. The most common types of RAM is SRAM and DRAM. SRAM is Static Random Access Memory. DRAM is Dynamic Random Access Memory. For robotics and microcontrollers using SRAM is simplier than DRAM. DRAM needs to be refreshed regularly, so the circuitry is more complicated.

EPROM & EEPROM Eproms or EEproms are the most common types of program memory for microcontrollers.

An EPROM is an Eraseable Programmable Read Only Memory. They are electrically programmed but erased with a UV light source.

An EEPROM is an Electrically Eraseable Programmable Read Only Memory. They are electrically programmed and electrically erased.

Microcontroller Families

The 8051 family The microcontroller I am most familiar with is the 8051 family of microcontrollers. It is one of the most popular and oldest microcontroller still around. A number of manufacturers make these microcontrollers, and there are many variations with different memory types and sizes, and different peripherals built in. Because it is so old, there are a lot of free or nearly free software assemblers, compilers, simulators. There is a version that runs Basic. So while my examples use this family, it is appropriate for the PIC family, 68HC11 family, and other microcontroller families.

The reason I have to get specific, is to discuss peripherals, and memory options in the families. In the 8052 family there are many many different types. They range from around $3 to $89 each. You can get a very good one with no program memory for about $8.

There are members of the 8051 family with 128, 256, 512, and 1024 bytes of SRAM built in. They have ROM (factory programmed for high volume), PROM, EPROM and EEPROM memories in 4, 8, 16, and 32 KB on chip available. There are memoryless versions for you to use with external memory. With all those memory combinations, there are lots of choices.

The peripherials make even more choices. The standard systems have 8 to 32 I/O lines which can be individually programmed as input or output lines for turning things on or off, or to see if something is on or off. In a robot, this is handy to see if a contact switch has bumped into something, or with the appropriate additional circuitry turn the wheel motors on or off, etc.

They all have some type of serial port. Usually a microcontroller's serial port has a TTL output, so you have to add a chip to convert it to RS-232 to make it talk to the serial port on your computer. If it is used for one microcontroller talking to another, RS232 is not needed, except perhaps for debugging.

They all have timers, so you can set something like an alarm clock, (except very short times), and counters, so when something external happens a counter is incrememted.

Some have PWM (pulse width modulated) outputs. This is usually used as a convenient way to control the speed of DC motors.

Some have ADC (Analog to Digital Converters) 8-bit or 10-bits. This converts a voltage to a digital number.

Some have PCA (Programmable Counter Arrays) which can measure the time differences between two pulses. This can be useful for calculating speed by counting a rotation of the wheel, or distance with an acoustic sensor.

There are lot's of choices between all of the different microcontrollers.

The 68HC11 family The 68HC11 is a popular microcontroller from Motorola. It is so popular with manufacturers (such as GM) that certain models are very difficult to find. However, if you want to do things from a Mac, the 68HC11 or 68HC12 (next generation) may be your best bet. Traditionally, Motorola has offered evaluation boards that use a serial connection and they provide free assemblers for both Mac and PC.
PICS Pics are programmable integrated circuits. They can do most anything you can think of (just like most any other microprocessor). They are based on a RISC or reduced instruction set chip archetecture and usually don't use 12 or more bits for a program byte.

The PIC is from a company called Microchip and the folks at Parallex that make the BASIC Stamps use "PIC" technology along with a PBASIC interpreter.

Using the PIC chips without the BASIC intepreter can yield processing up to 20 times faster than a Stamp.

PIC Varients There are many varieties of PICs (as small as 8-pin DIP) with varying types and amounts of memory. The most affordable are the OTP (one time programmable) but they are only cost effective once you have perfected your design and you are cranking out copies.

In single quantities, the 18-pin PIC16C84 costs about $9.00

Microcontroller Utilities

Programming Languages MCUs can be programmed in just about any language. Below are some common langugages MCUs are programmed in:
  • Assembler
  • Basic interpreter
  • Basic compiler
  • C (these are typically pricey)
Burning MCUs The term "burning" simply means to load a program or data onto a chip's memory. To burn an eprom or an eprom built into an mcu requires some sort of device programmer. Generally, the eprom or mcu chip is placed into the device programmer, "burned" and then removed from the device programmer and inserted into the chip socket of a printed circuit board. Some MCU chips have eeprom on board and may only require a serial hookup to program their memory. Other MCU's may not have any program memory at all and must rely on a seperate program eprom chip residing in it's address space.

Device programmers come in all types. The most affordable device programmers are usually available for the PC parallel port or an internal PC card. These less expensive device programmers generally only program one type of chip like only pics or only eproms. Sometimes these program programmers may have an adapter socket to program the eprom memories inside mcus. The higher priced models usually are not limited to one type of device and can program a vast array of devices including MCUs, pics, eproms, and eplds.

Copyright © 1984 - 2014 Dallas Personal Robotics Group. All rights reserved.