Microcont Made Easy
Microcont Made Easy
Microcont Made Easy
APPLICATION NOTE
WHAT IS A MICROCONTROLLER?
A few years ago, system control functions were implemented using logic components and
were usually large, heavy boxes. Later on, microprocessors were used and the entire 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 low.
A typical microcontroller has bit manipulation instructions, easy7 and direct access to I/O, and
quick and efficient interrupt processing. Therefore, a microcontroller is a highly integrated
device which includes, on one chip, all or most of the parts needed to perform an application
control function.
Microcontrollers come in many varieties. Depending on the power and features that are
needed, customers might choose a 4, 8, 16, or 32 bit microcontroller.
Figure 1. Typical MCU Block Diagram
CONTAINS CONTAINS
PROGRAM ROM RAM TEMPORARY
AND DATA DATA
CONTAINS
EXECUTES PROGRAM
MANAGES EVENTS
CPU EEPROM PERMANENT
DATA
SIGNAL GENERATION A/ D
ANALOG DATA
EVENT COUNTING TIMER
CONVERTER ACQUISITION
APPLICATION TIMEBASE
VR02101A
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 Flash memory is its endurance 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 execution of a program, data have to be saved for later use. Data are usually
stored in RAM.
EEPROM (Electrically Erasable Programmable Read Only Memory)
There is another way to store data in a microcontroller: EEPROM is used to store 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 execute a program, the CPU will read the first instruction from program memory.
This instruction is decoded by the CPU and executed. At the completion of the execution of
the instruction, the next instruction is fetched from memory and is executed. This procedure is
repeated until the end of the program (or an endless loop) is found.
Figure 2. Typical Microcontroller Block Organization
PROGRAM
MEMORY
INPUT BUS ROM
OUTPUT DATA
MEMORY
PERIPHERAL
RAM
SYSTEMS CENTRAL
TIMING EEPROM
PROCESSING
SYSTEM
UNIT
VR02101B
TIMERS
The timer or timing system makes it possible 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 less bits, usually programmable as either input
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
asynchronous interface is called a serial communication interface (SCI or UART) while the
synchronous interface is called a serial peripheral interface (SPI). A typical SCI application is
to connect a PC for debugging purpose while a typical SPI application is to connect 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 asyn-
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 ASYNCHRONOUS
CLOCK
CLOCK
0 b b b b b 1 +
Start Stop DATA
b b b b b b b DATA
VR02101C
A/D CONVERTER
Converts an external analog signal (typically relative to voltage) into a digital representation.
Microcontrollers that have this feature can be used for instrumentation, environmental data
logging, or any application that lives in an analog world.
Figure 4. A/D Converter Principle
Voltage
A/D
ANALOG CONVERTER DIGITAL
5
4
ANALOG
3 SIGNAL
5 4 2 1 1 2
2
Time VR02101D
3/12
MICROCONTROLLERS MADE EASY
DASHBOAD
FRONT PANEL
REMOTE
REMOTE BATTERY CHARGER DIMMER METER
SWITCH KEYLESS
CONTROL
While microprocessors target the maximum processing performance, the purpose of micro-
controllers is to implement a set of control function in the most cost effective way. Although
controlling a microwave oven with a Pentium(TM) 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
FUNCTION
KEYBOARD INFORMATION
SCANNING DISPLAY
MEASURE CHANGE
TEMPERATURE TEMPERATURE
VR02101E
The ability to manage control tasks by hardware or by software is the main performance indi-
cator for MCUs.
4/12
MICROCONTROLLERS MADE EASY
VR02101F
SEAT BELT FASTENER DASHBOARD DISPLAY
VR02101F
The automotive market is demanding in term of device performance and component reliability.
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 be-
cause these electronics also compete in the consumer market - they have a low price tag.
Figure 8. MCU Applications in Today’s and Tomorrow’s Home
TODAY’S TOMORROW’S
HOME HOME
VR02101G
5/12
MICROCONTROLLERS MADE EASY
2.1 TIMERS
Watchdog timer. A watchdog timer provides a means of graceful recovery from a system
problem. This could be a program that goes into an endless loop, or a hardware problem that
prevents the program from operating correctly. If the program fails to reset the watchdog at
some predetermined interval, a hardware reset will be initiated. The bug may still exist, but at
least the system has a way to recover. This is especially useful for unattended systems.
Auto Reload Timer. Compared to a standard timer, this timer automatically reloads its
counting value when the count is over, therefore sparing a waste of CPU resource.
Figure 9. Standard Timer and Auto-Reload Timer Principle
End of End of
Count Count
TIMER TIMER
CPU CPU
Load Register Load Register
Reload Reload
VR02101H
CLOCK ANALOG
V VOLTAGE
PWM RC Filter
time
VR02101I
Pulse Accumulator. A pulse accumulator is an event counter. Each pulse increments the
pulse accumulator register, recording the number of times this event has occurred.
Input Capture. Input Capture can measure external frequencies or time intervals by copying
the value from a free running timer into the input capture register when an external event oc-
curs.
6/12
MICROCONTROLLERS MADE EASY
Output Compare. Output Compare can time an external event by sending a value stored in-
side the output compare register.
Figure 11. Input Capture and Output Capture Timer Functions
OUTPUT COMPARE
OUTGOING
EVENT
TIMER CLOCK
value
OC register
VR02101J
7/12
MICROCONTROLLERS MADE EASY
DIGITAL
ANALOG A/D D/A ANALOG
DATA
DATA CONVERTER CONVERTER DATA
PROCESSING
FAN
THERMOMETER VR02101K
Analog to digital conversion (A / D). Converts an external analog signal (typically relative to
voltage) and converts it to a digital representation. Microcontrollers that have this feature can
be used for instrumentation, environmental data logging, or any application that lives in an an-
alog world. Various types of A/D converters that can be found.
Comparator. One or more standard comparators can sometimes be placed on a microcon-
troller die. These comparators operate much like standard comparators however the input and
output signals are available on the microcontroller bus.
Digital to analog conversion (D/A). This feature takes a Digital number and converts it to a
analog output. The number 50 would be changed to the analog output of (50 / 256 * 5 Volts)
= .9765625 V on a 8 bit / 5 Volt system.
8/12
MICROCONTROLLERS MADE EASY
2.4 COMMUNICATION
CAN & J1850
CAN (Controller Area Network) is a multiplexed wiring scheme that was developed jointly by
BOSH and Intel for wiring in automobiles. J1850 is the SAE (Society of Automotive Engineers)
multiplexed automotive wiring standard that is currently in use in North America.
The CAN specification seems to be the one that is being used in industrial control both in
North American and Europe. With lower cost microcontrollers that support CAN, CAN has a
good potential to take off.
Figure 13. CAN Principle
VR02101L
9/12
MICROCONTROLLERS MADE EASY
2.5 INTERRUPTS
Polling. Polling is what you have to do if your microcontroller does not have interrupts or if
what you want to do is not time critical. It is a software technique whereby the controller con-
tinually asks a peripheral if it needs servicing. The peripheral sets a flag when it has data
ready for transferring to the controller, which the controller notices on its next poll. Several pe-
ripherals can be polled in succession, with the controller jumping to different software routines,
depending on which flags have been set.
Figure 14. Polling versus Interrupt
POLLING INTERRUPT
TASK 1 TASK 1
POLLING LOOP
TASK 2
TASK 2
Interrupts. Rather than have the microcontroller continually polling - that is, asking periph-
erals (timers / UARTS / A/Ds / external components) whether they have any data available
(and finding most of the time they do not), a more efficient method is to have the peripherals
tell the controller when they have data ready. The controller can be carrying out its normal
function, only responding to peripherals when there is data to respond to. On receipt of an in-
terrupt, the controller suspends its current operation, identifies the interrupting peripheral, then
jumps to the appropriate interrupt service routine. The advantage of interrupts, compared with
polling, is the speed of response to external events and reduced software overhead (of con-
tinually asking peripherals if they have any data ready).
Most microcontrollers have at least one external interrupt, which can be edge selectable
(rising or falling) or level triggered. Both systems have advantages. Edge is not time sensitive,
but it is susceptible to glitches. Level must be held high (or low) for a specific duration (which
can be a pain but is not susceptible to glitches).
10/12
MICROCONTROLLERS MADE EASY
+ TRANSISTOR +
- -
SIZE SPEED
COST POWER
SUPPLY VOLTAGE
VR02101N
For years people have been using 5 Volts to power integrated circuits. Because the transistors
were large, there was little danger damaging the transistor putting this voltage across it. How-
ever, now that the transistors are getting so small, 5 Volts would now destroy them. The only
way around this is to start lowering the voltage. This is also why people are now using 3 (ac-
tually 3.3) Volt logic, and this will certainly lead to lower voltages in the next few years.
11/12
MICROCONTROLLERS MADE EASY
“THE PRESENT NOTE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH INFORMATION
REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, STMICROELECTRONICS
SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO
ANY CLAIMS ARISING FROM THE CONTENT OF SUCH A NOTE AND/OR THE USE MADE BY CUSTOMERS OF
THE INFORMATION CONTAINED HEREIN IN CONNEXION WITH THEIR PRODUCTS.”
Information furnished is believed to be accurate and reliable. However, STMicroelectronics assumes no responsibility for the consequences
of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. No license is granted
by implication or otherwise under any patent or patent rights of STMicroelectronics. Specifications mentioned in this publication are subject
to change without notice. This publication supersedes and replaces all information previously supplied. STMicroelectronics products are not
authorized for use as critical components in life support devices or systems without the express written approval of STMicroelectronics.
The ST logo is a registered trademark of STMicroelectronics
2000 STMicroelectronics - All Rights Reserved.
Purchase of I2C Components by STMicroelectronics conveys a license under the Philips I2C Patent. Rights to use these components in an
I2C system is granted provided that the system conforms to the I2C Standard Specification as defined by Philips.
STMicroelectronics Group of Companies
Australia - Brazil - China - Finland - France - Germany - Hong Kong - India - Italy - Japan - Malaysia - Malta - Morocco - Singapore - Spain
Sweden - Switzerland - United Kingdom - U.S.A.
http://www.st.com
12/12