Page 473 - Robot Builder's Bonanza
P. 473

442  UNDERSTANDING MICROCONTROLLERS


                   •   Central processing unit (CPU). This is the core of the microcontroller and performs all of
                     the logic and arithmetic computations. The CPU takes your programming instructions and
                     evaluates each one in turn.
                   •   23 input/output pins. The I/O lines are the gateway of information in and out of the
                     microcontroller. An I/O line can be set to act as an input, in which case it can accept data
                     from the outside, or it can act as an output, where it can control some external component.
                     The ATmega328 has 28 pins total, of which 23 may be used for input/output  chores— it’s
                     said to have 23 I/O lines or I/O pins. The remaining five pins are used for power supply
                     connections.
                   •     Built- in analog converter. Six of the chip’s input/output pins are connected to an inter-
                     nal  analog- to- digital converter (ADC), which translates analog voltages to digital binary
                     values.
                   •     Built- in analog comparator. The internal analog comparator can be used for basic go /
                     no- go evaluation of analog voltage levels.
                   •   Flash program storage. Programs you write and download to the microcontroller are
                     stored in 32K bytes of rewritable flash memory. This allows the controller to be repro-
                     grammed over and over again. Note that some MCUs are  program- once only. Read more
                     about these later in this chapter.
                   •   RAM and EEPROM data storage. Small amounts of RAM (2K bytes) and EEPROM (1K
                     bytes) storage are provided for the data that the controller uses during operation. Data in
                     RAM  (random- access memory) is lost when the controller loses power. Data in EEPROM
                     (electrically erasable programmable  read- only memory) retains its value even when the
                     microcontroller is no longer powered.
                   •  Hardware interrupts. Microcontrollers are designed to interact with the outside world, and
                     hardware interrupts allow the chip to be literally “interrupted” by some external stimulus.
                     It’s not unlike asking someone to pinch you to wake you up. Interrupts make many com-
                     mon robotic programming tasks easier and more elegant. The ATmega328 has two pri-
                     mary hardware interrupts that are connected to two of its pins.
                   •     Built- in timers and counters. These  all- purpose accessories of microcontrollers operate
                     separately from the CPU and provide a wide variety of useful services. For example, under
                     program control, you can command a timer to generate a pulse every second. Counters
                     are likewise special accessories separate from the CPU and literally count individual signal
                     events, like the number of times a robot’s wheels have rotated.












                                                             Figure 35- 4  Basic block diagram of the
                                                             Atmel AVR ATmega328 microcontroller.
                                                             The central processing unit (CPU) forms the
                                                             core of the controller. Additional  built- in
                                                             hardware provides special functions, such
                                                             as timers, an analog comparator, and an
                                                               analog- to- digital converter.









   35-chapter-35.indd   442                                                                     4/21/11   11:57 AM
   468   469   470   471   472   473   474   475   476   477   478