An Introduction to Microcontrollers

Document Sample
An Introduction to Microcontrollers Powered By Docstoc
					An Introduction to MICROCONTROLLERS AND EMBEDDED PROCESSORS

For full details, see -
http://microcontroller.com/embedded/references/faqs/microcontroller-faq.htm


What is a Microcontroller?

   The first controllers were analog electrical circuits and mechanical systems. Later
controllers were built exclusively from logic components, and were usually large,
heavy boxes. Later still, microprocessors from computers were used with memory
and added io circuitry and the entire controller could fit on a small circuit board. This
is still common - you can find many [good] controllers powered by one of the many
common microprocessors (including Zilog Z80, Intel 8088, Motorola 6809, and
others).

  As the process of miniaturization continued, all of the components needed for a
controller were built right onto one chip. A one chip computer or microcontroller was
born. A microcontroller is a highly integrated chip which includes, on one chip, all or
most of the parts needed for a controller. The microcontroller could be called a "one-
chip solution". It typically includes:
      CPU (central processing unit)
      RAM (Random Access Memory)
      EPROM/PROM/ROM (Erasable Programmable Read Only Memory)
      I/O (input/output) - serial and parallel
      timers
      interrupt controller

   Because of large volume and specific design for control the cost is relatively low.
A typical microcontroller has bit manipulation instructions, easy and direct access to
I/O (input/output), and quick and efficient interrupt processing. Microcontrollers are
a "one-chip solution" which drastically reduces parts count and design costs.


Applications

Embedded processors / microcontrollers are frequently found in: appliances
(microwave oven, refrigerators, television and VCRs, stereos, cameras), computers
and computer equipment (laser printers, modems, disk drives), automobiles (engine
control, diagnostics, climate control, security), environmental control eg air
conditioners (greenhouse, factory, home), instrumentation, aerospace, and thousands
of other uses. In many items, more than one processor can be found.

  Microcontrollers are typically used where processing power isn't so important;
controlling a microwave oven is easily accomplished with the smallest of
microcontrollers.

  Embedded processors / microcontrollers are used extensively in robotics. In this
application, many specific tasks might be distributed among a large number of
controllers in one system. Communications between each controller and a central,
possibly more powerful controller (or micro/mini/mainframe) would enable
information to be processed by the central computer, or to be passed around to other
controllers in the system.

   A special application that microcontrollers are well suited for is data logging, for
example to monitor and record environmental parameters (temperature, humidity,
rain, etc). Small size, low power consumption, and flexibility make these devices
ideal for unattended data monitoring and recording.


Types

   Embedded processors come in many flavors and varieties. Depending on the
power and features that are needed, you might choose a 4, 8, 16, or 32 bit
microcontroller. Standard microprocessors (such as the Motorola 68000 or National
32032) are frequently used as powerful embedded controllers. In addition,
specialized processors are available which include features specific for
communications, keyboard handling, signal processing, video processing, and other
tasks.


THE MICROCONTROLLER MARKET

  Thanks to Robin Getz of National Semiconductor for supplying much of
  the material in this section.



           WorldWide Microcontroller Shipments (in Millions)

         '90 '91 '92      '93   '94 '95  '96 '97 '98             '99 '00
   4-bit 778 906 979      1036 1063 1110 1100 1096 1064          1025 970
   8-bit 588 753 843      1073 1449 1803 2123 2374 2556          2681 2700
  16-bit 22 38 45         59 106 157 227 313 419 501              585

   Notice that even the lowly 4-bit device is holding its own - what use is a 16-bit part
in a toaster oven? Also notice that the 8-bit market just keeps growing, and will
probably continue to grow. 8-bit devices account for over half of the market, and will
eventually grab even more. Now do you understand why every silicon manufacturer
is really pushing their 8-bit microcontrollers?


Industrial applications
  The automotive market is the most important single driving force in the
microcontroller market, especially at it's high end. Several microcontroller families
were developed specifically for automotive applications and were subsequently
modified to serve other embedded applications.

  Average Semiconductor Content per Passenger Automobile (in Dollars)
     '90 '91 '92 '93 '94 '95      '96 '97 '98       '99 '00
   $ 595 634 712 905 1,068 1,237 1,339 1,410 1,574 1,852 2,126


   The automotive market is demanding. Electronics must operate under extreme
temperatures and be able to withstand vibration, shock, and EMI. The electronics
must be reliable, because a failure that causes an accident can (and does) result in
multi-million dollar lawsuits. Reliability standards are high - but because these
electronics also compete in the consumer market - they have a low price tag.

  Automotive is not the only market that is growing. DataQuest says that in the
average North American's home there are 35 microcontrollers. By the year 2000 -
that number will grow to 240. Consumer electronics is a booming business.


Deciding whose microcontroller to use

  When deciding which devices to implement in a design, there are lots of things to
consider besides who else is using these devices (and how many are they using).
   - Can I expect help when I am having problems?
   - What development tools are available and how much do they cost?
   - What sort of documentation is available (reference manuals,
     application notes, books)?
   - Can I work a deal by purchasing more devices at one manufacturer?
     That is, purchasing not only the microcontroller, but also
     peripherals (A/D, memory, voltage regulator, etc.) from one
     company).
   - Do they support OTPs, windowed devices, mask parts?


Suppliers


            MICROPROCESSORS
     Rank                Sales ($ millions)
  1995 1994               Company           1995        1994
  -----------------------------------------------
    1      1              Intel             $10,800   $8,036
    2      3              AMD               881          992
    3      2              Motorola          781          827
    4     11              IBM               468          297
    5      6              TI                 219         202
    6      4              Cyrix             210          240
    7      5              Hitachi           188           66
    8      7              NEC               100           82
    9      8              LSI Logic           58          51
   10 10                  IDT                45           25

                           Source: In-Stat Inc.
            MICROCONTROLLERS
     Rank                 Sales ($ millions)
  1995 1994 Company                       1995    1994
  -----------------------------------------------
    1 1 Motorola                        $1,781 $1,511
    2 2 NEC                               1,421 1,208
    3 4 Mitsibishi                          945    708
    4 3 Hitachi                             899    782
    5 5 Intel                               835    605
    6 6 TI                                  807    534
    7 8 Philips                             524    345
    8 7 Matsushita                          500    413
    9 10 Lucent (AT&T)                      492    275
   10 9 Toshiba                             400    328

                          Source: In-Stat Inc.




Some popular microcontrollers

  Some common microcontrollers are described below. A common question is "what
microcontroller should I use for...?" Well, that's a tough one. The best advice would
be to choose a chip that has a full set of development tools at the price you can afford,
and good documentation. For the hobbyist, the Intel 8051, Motorola 68hc11, or
Microchip PIC would all make suitable choices.

  8048 (Intel) , 8051 (Intel and others) , 80186,80188 (Intel)
    Some older microcontrollers are still very popular due to very low cost,
availability, and wide range of development tools.




    68HC05 (Motorola) ,      68hc11 (Motorola and Toshiba)


    The 68HC05 (and the earlier 6805) is based loosely on the
    manufacturer's earlier 6800.The popular 68hc11 is a powerful 8-bit data, 16-bit
address microcontroller. Depending on the variety, the 68hc11 has built-in
EEPROM/OTPROM, RAM, digital I/O, timers, A/D converter, PWM generator,
pulse accumulator, and synchronous and ansynchronous communications channels.


  PIC (MicroChip)
    The PIC microcontrollers were the first RISC microcontrollers. RISC generally
implies that simplicity of design allows more features to be added at lower cost.
Although having few instructions (eg. 33 instructions for the 16C5X line versus over
90 for the Intel 8048), the PIC line has a wealth of features included as part of the
chip. The benefits of design simplicity are a very small chip, small pin count, and very
low power consumption.



MICROCONTROLLER PROGRAMMING LANGUAGES

Machine/Assembly language

  Machine language is the program representation as the microcontroller
  understands it. It is not easy for humans to read and is a common
  cause of migraine headaches. Assembly language is a human-readable
  form of machine language which makes it much easier for us flesh and
  bone types to deal with. Each assembly language statement
  corresponds to one machine language statement (not counting macros).

  An assembly/machine language program is fast and small. This is
  because you are in complete charge of what goes into the program. Of
  course, if you write a slow, large, stupid program, then it will run
  slowly, be too big, and be stupid. Assembly language (assembler)
  can't correct stupidity - although sometimes I wish it could ;-).

  If you are starting out learning about microcontrollers, it would be
  worth your while first learning assembler. By programming in
  assembler, you master the underlying architecture of the chip, which
  is important if you intend to do anything significant with your
  microcontroller.


7.2) Interpreters

  An interpreter is a high level language translator that is closer to
  natural language. The interpreter itself is a program that sits
  resident in the microcontroller. It executes a program by reading
  each language statement one at a time and then doing what the
  statement says to do. The two most popular interpreters for
  microcontrollers are BASIC and FORTH.

  BASIC's popularity is due to its simplicity, readability, and of
  course just about everyone has at least played with BASIC at one time
  or another. One common compaint about [interpreted] BASIC is that it
  is slow. Often this can be solved by using a different technique for
  performing the desired task. Other times it is just the price paid
  for using an interpreter.

  FORTH has a very loyal following due to its speed (approaching that
  of assembler language) and its incremental approach to building a
  system from reusable parts. Many FORTH systems come with a host
  system which turns your desktop computer into a development system.
  FORTH can be quite difficult to write in (if you have no experience
  with it) and is probably even harder to read. However, it is a very
  useful and productive language for control systems and robotics, and
  can be mastered in time.

  JVM - Java(TM) Virtual Machine - was added lately to the list of
  interpreters, after the invention of the language and concepts by Sun
  Microsystems. Java was adopted enthusiastically by programmers all
  over the world and has finally found its way into the embedded
  environment. Java provides a new and revolutionary concept, geared
  towards the use of portable software applications which can be
  dynamically downloaded over a network, rather than kept on the local
  disk or in the local memory of a specific computer. This way, the
  client computer does not need to keep all the applications, since
  they can be dynamically downloaded from the server whenever required.
  Another Java main feature is its Operating-System independent
  capability. Java is also a language. The Java language is a new
  object-oriented programming language, also developed by Sun
  Microsystems. In its very own architecture it is particularly suited
  to the development of Java's portable application pieces of software,
  called applets.

  The nicest thing about developing a system with an interpreter is
  that you can build your program interactively. You first write a
  small piece of code and then you can try it out immediately to see
  how it works. When the results are satisfactory, you can then add
  additional components until the final product is achieved.


7.3) Compilers

  A compiler is a high level language translator that combines the
  programming ease of an interpreter with greater speed. This is
  accomplished by translating the program (on a host machine such as a
  desktop PC) directly into machine language. The machine language
  program is then burned onto an EPROM or downloaded directly to the
  microcontroller. The microcontroller then executes the translated
  program directly, without having to interpret first.

  The most popular microcontroller compilers are C and BASIC. PL/M,
  from Intel, also has some popular support due to that company's
  extensive use of that language. Modula-2 has a loyal following due to
  its efficient code and high development productivity. Ada has many
  adherents among those designing on the larger chips (16 bits and
  above).

  Due to both its popularity and its slow speed, it was only logical
  that BASIC would appear as a compiled language. A few companies
  supply a BASIC compiler for several of the more popular
  microcontrollers. Execution speed is drastically increased over
  interpreted BASIC since the microcontroller is freed from the task of
  interpreting the statements as the program runs.

  While interpreted Forth approaches (and sometimes surpasses) the
  speed of many compilers, compiled Forth screams along. Today there
  are many high performance optimizing native code Forth compilers, and
  there are also lots of very cheap or free public domain Forths. Some
  of them like Tom Almy's ForthCMP produces optimized native code with
  less overhead and better performance than just about anything else
  out there. Of course it still has compactness and more elegant
  factoring of functionality than in most languages.

  C is now the language of choice for the entire universe. C is used
  on computers from the tiny microcontroller up to the largest Cray
  supercomputer. Although a C program can be a bit tedious at times to
  read (due to the terse programming style followed by many C
  programmers), it is a powerful and flexible development tool.
  Although a high level language, it also gives the developer access to
  the underlying machine. There are several very good and cheap C
  compilers available for the more popular microcontrollers. It is
  widely used, available, supported, and produces fairly efficient code
  (fast and compact).


7.4) Fuzzy Logic and Neural Networks

  Fuzzy Logic and neural networks are two design methods that are
  coming into favour in embedded systems. The two methods are very
  different from each other, from conception to implementation.
  However, the advantages and disadvantages of the two can complement
  each other.

  The advantage of neural networks is that it is possible to design
  them without completely understanding the underlying logical rules by
  which they operate. The neural network designer applies a set of
  inputs to the network and "trains" it to produce the required output.
  The inputs must represent the behaviour of the system that is being
  programmed, and the outputs should match the desired result within
  some margin of error. If the network's output does not agree with
  the desired result, the structure of the neural network is altered
  until it does. After training it is assumed that the network will
  also produce the desired output, or something close to it, when it is
  presented with new and unknown data.

  In contrast, a fuzzy-logic system can be precisely described. Before
  a fuzzy control system is designed, its desired logical operation
  must be analyzed and translated into fuzzy-logic rules. This is the
step where neural networks technology can be helpful to the
fuzzy-logic designer. The designer can first train a software neural
network to produce the desired output from a given set of inputs and
outputs and then use a software tool to extract the underlying rules
from the neural network. The extracted rules are translated into
fuzzy-logic rules.

Fuzzy logic is not a complete design solution. It supplements rather
than replaces traditional event control and PID (proportional,
integral, and derivate) control techniques. Fuzzy logic relies on
grade of membership and artifical intelligence techniques. It works
best when it is applied to non-linear systems with many inputs that
cannot be easily expressed in either mathematical equations used for
PID control or IF-THEN statements used for event control.

In an effort to change fuzzy logic from a "buzzword" (as it is in
most parts of the world) to a well established design method (as it
is in Japan), most manufacturers of microcontrollers have introduced
fuzzy logic software. Most software generates code for specific
microcontrollers, while other generates C code which can be compiled
for any microcontroller.