ST AN887 Application note

AN887
APPLICATION NOTE
MICROCONTROLLERS MADE EASY
by Microcontroller Division Applications
WHAT IS A MICROCONTROLLER?
A few years ago, system control functions were impleme nted using logic components and were usu ally lar ge, heav y box es. Lat er on, microp roce ssors were us ed an d the ent ire con ­troller could fit onto a small circuit board. As the process of miniaturization continued, all of the components needed for a controller were built right onto one chip. By only including the fea­tures specific to the task, cost is relatively lo w.
A typical microcontroller has bit manipulation instructions, easy7 and direct access to I/O, and quick and effi cient int errupt pr ocessi ng. There fore, a m icroc ontroller is a highly integrated device which includes, on one ch ip, all or most of the parts needed to perform an application control function.
Microcontrollers come in many varieties. D epending on the power and features that are needed, customers might choose a 4, 8, 16, or 32 bit microcontroller.
Figure 1. Typical MCU Block Diag ram
CONTAINS PROGRAM
AND DATA
EXECUTES PROGRAM
MANAGES EVENTS
SIGNAL GENERATION
EVENT COUNTING
APPLICATION TIMEBASE
PERIPHERAL INTERFACE
ROM
CPU
TIMER
I/O P OR T
RAM
EEPROM
A / D
CONVERTER
SERIAL
INTERFACE
CONTAINS
TEMP ORARY
DATA
CONTAINS PERMANENT
DATA
ANALOG DATA
ACQUISITION
SENDS AND
RECEIVES
DATA
VR02101A
ROM (Read Only Memory) ROM is usually used to store program instructions. RO M is the l east expensive mean of
storing a program in a microcontroller, especially for high volume manufacturing.
AN887/1100 1/12
1
MICROCONTROLLERS MADE EASY
Flash
Flash is an electrically erasable and programmable memory. It can be used instead of ROM to store program instructions and data. A key parameter of F lash memory is i ts enduranc e or the number of times it can be erased or reprogrammed. Depending on the technology used, flash endurance can be either 100 or 300,000 program/erase cycles.
RAM (Random Access Memory) During in the e xec ution o f a prog ram, d ata ha ve to be sav ed for la ter use. D ata a re u sual ly
stored in RAM. EEPROM (Electrically Erasable Programmable Read Only Memory) There is anothe r way to store data in a microcon troller : EEPRO M is used to sto re data that
must be saved through a power down cycle. CPU (Central Processing Unit) It is the brain of the system that processes all data and their travel along the bus. For example,
in order to e xecute a program , th e C PU will re ad th e f irst i nstruct ion from pr ogram mem o ry. This instruction is decoded by t he C PU a nd exec ute d. At the co mpletio n o f the e xec ution of the instruction, the next instruction is fetched from memory and is executed. This pr ocedure is repeated until the end of the program (or an endless loop) is found.
Figure 2. Typical Microcontroller Block Organization
PROGRAM
INPUT
OUTPUT
PERIPHERAL
SYSTEMS
BUS
CENTRAL
PROCESSING
TIMING
SYSTEM
MEMORY
ROM
DATA
MEMORY
RAM
EEPROM
UNIT
VR02101B
TIMERS
The timer or timing system makes it poss ible to measure and time external and internal events. The power of the timers varies greatly between different MCUs.
I / O (INPUT / OUTPUT) PORTS
Most microcontrollers have several digital I/O ports that are used to drive a LED or get a key­board input. Usually, a port consists of eight or l ess bi ts, usually programmable as either i nput or output bits.
2/12
2
MICROCONTROLLERS MADE EASY
SERIAL INTERFACE
Serial interface are used to exchange data with the external world. Many microcontrollers have both asynchronous and synchronous communications peripherals built in. Usually, an asynchro nous interfa ce is cal led a se rial com munic ation interfac e (SCI or UART) while the synchronous interface is called a serial peripheral interface (SPI). A typical SCI application is to conne ct a PC for debu gging pu rpose while a t ypical SPI appl icatio n is to co nnect an ex­ternal EEPROM.
A synchronous bus includes a separate line for the clock signal which simplifies the transmitter and receiver but is more susceptible to noise when used over long distances. With an as yn­chronous bus the transmitter and receiver clocks are independent, and a resynchronization is performed for each byte at the start bit.
Figure 3. Synchronous and Asynchronous Communication Principles
SYNCHRONOUS
CLOCK
bbb
b b
bb
DATA
0b bbb
Start
ASYNCHRONOUS
b1
Stop
CLOCK
+
DATA
VR02101C
A/D CONVERTER
Converts an external analog signal (typically relative to voltage) into a digital representation. Microcont rollers that have th is featu re can be used fo r instrume ntation , envir onmen tal data logging, or any application that lives in an analog world.
Figure 4. A/D Converter Principle
Voltage
ANALOG
5 4
3 2
ANALOG
SIGNAL
A / D
CONVERTER
DIGITAL
54
2
11
2
1
Time
VR02101D
3/12
MICROCONTROLLERS MADE EASY
1 TYPICAL MICROCONTROLLER APPLI CATIONS
Microcontrollers are frequently found in home appliances (microwave oven, refrigerators, tel­evision and VCRs, stereos), computers and computer equipment (laser printers, modems, disk drives), cars (engine control, diagnostics, climate control), environmental control (green­house, factory, home), instrumentation, aerospace, and thousands of other uses. In many items, more than one processor can be found.
Figure 5. Typical MCU Applications
TV SET
CAR RADIO
REMOTE
CONTROL
BATTERY CHARGER
BODY CONTROLLER
KEYBOARD
DIMMER SWITCH
TELEPHONE SET
REMOTE
METER
MONITOR
DASHBOAD
FRONT PANEL
KEYLESS
While microproc essors targe t the maximu m proces sing performa nce, the pur pose of micro ­controllers is to impl ement a se t of control functi on in the most cos t effective w ay. Although
(TM)
controlling a microwave oven with a Pentium
might seem an attractive idea, it can be easily accomplished with an ST6. In a typical application, the MCU has to manage several tasks according to their priority or to the occurrence of external events (new command send by the keyboard, external temperature rise,...)
Figure 6. Example of MCU Task Management.
CENTRAL MCU
KEYBOARD SCANNING
MEASURE
TEMPERATURE
FUN CTIO N
CHANGE
TEMPERATURE
INFORMATION
DISPLAY
VR0 2101E
The ability to manage control tasks by hardware or by software is the mai n performance indi­cator for MCUs.
4/12
Loading...
+ 8 hidden pages