Purpose – This course introduces basic facts about microcontrollers. Objectives – Understand the differences between microcontrollers (MCUs) and microprocessors (MPUs) – Obtain an overview of on-chip functions and basic system signals – Learn about the typical questions engineers ask when choosing MCUs for new embedded system designs Content – 19 pages Learning Time – 25 minutes Introduction
19
Embed
Purpose – This course introduces basic facts about microcontrollers. Objectives – Understand the differences between microcontrollers (MCUs) and microprocessors.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Purpose – This course introduces basic facts about microcontrollers.
Objectives – Understand the differences between microcontrollers (MCUs) and
microprocessors (MPUs)– Obtain an overview of on-chip functions and basic system signals– Learn about the typical questions engineers ask when choosing MCUs
for new embedded system designs
Content– 19 pages
Learning Time– 25 minutes
Introduction
What is a Microcomputer?
• General definition: Small computer capable of performing specific tasks
– Examples of tasks: controlling operation and functions of alarm systems, power tools, digital cameras, traffic signals, etc.
– Acts as “brain” of an embedded system, executing functions according to stored instructions (application software)
• More-specific definition: Computer chip with Central Processing Unit (CPU)
– Two classifications
• Microprocessor unit (MPU)
• Microcontroller unit (MCU)
Differences Between MPUs and MCUs
System implementation
Handheld multimedia phone, car navigation system
Application examples
SH-3 and SH-4 seriesRenesas product lines
32 bits or aboveProcessor core (CPU)
Necessary for very complex, high performance and expandable systems
Needs external memory & peripherals to accomplish a task
Application considerations
Typically contains only the main processor (CPU core) — no memory for program storage
Device
MPUCLASSIFICATION
MPU(Typically, only the
CPUCore)
Memory
Peripherals
IO
Multiple chips
Washing machine, rice cooker, air conditioner
M16C, H8, SH-1, and SH-2 series
4, 8, 16, or 32 bits
Self-contained to complete a task with no/few external components
Ideal for small, compact, and low-cost systems
Contains CPU core, memory, peripherals, and I/O integrated
MCU
CPUCore
Memory
Peripherals
I/O
Single chip MCU
Typical MCU On-chip Functions
• CPU• Memory (RAM and ROM)• Clock(s)• Low-power Modes• Input/Output Ports• Timers & Watchdog Timer (WDT)• Pulse Width Modulator (PWM)• Analog-to-Digital Converter (ADC)• Serial Interface• Bus Controller• On-chip Debug• Other
CPU(16-bit H8 type)Main Clock
Sub-Clock RAM
ROM
Timer
Timer
Timer
Timer
WDTTimer
ADCLCD
Controller
Serial Interface
PWM
PWM
I/O P
ort
Example: H8/38024 16-bit MCU
I/O P
ort
Inp
ut
Po
rt
I/OI/O
Po
rtI/O
I/O P
ort
I/O P
ort
Ou
tpu
t P
ort
I/O
Processor Core (CPU)
• Function– Fetches and executes machine code – Provides levels of code efficiency and performance
• Architectural design features– CISC type or RISC type
• RISC has fewer instructions– Word size: 4, 8, 16, or 32 bits– Arithmetic Logic Unit for arithmetic and floating point operations– General registers for data processing and temporary storage– Special registers (program counter, stack, conditional, status)
to assist in program control– Data bus for interconnections– Operating frequency/clock speed range Voltage dependent
RISC
CISC
Instruction execution
Fast: 1 instruction/cycle
Slower: Many instructions take multiple cycles
Code efficiency
Lower: Moderate
High: Very compact code
Measuring CPU performance• MIPS (million instructions per second)
- Number of machine instructions that a computer can execute in one second- Benchmark tests provide only a rough indication of performance- Ultimate test is how well the MCU or MPU performs in the actual application
Memory (ROM/RAM)
• ROM (Read Only Memory) = Non-volatile – Used for program and fixed data storage– Contents retained when power is turned off– Size: from 1KB to 512KB and more– Examples:
• Mask ROM• Programmable Read-Only Memory (PROM),
also called One-Time Programmable (OTP)• Flash ROM (reprogrammable)
• RAM (Random Access Memory) = Volatile– Used for temporary data storage – Contents lost when power is turned off– Size: from 256 bytes to 48KB or more– Examples:
• Dynamic RAM (DRAM) — needs refresh• Static RAM (SRAM) — uses less power• Other: Cache — tightly coupled to CPU
of high-performance MPUs/MCUs
Memory Type
Mask ROM
PROM/OTP
Flash
DRAM
SRAM
Data Retained?
Yes
Yes
Yes
No
No
Reprogram-mable?
No
No
YesReads & writes,
but temporarystorage only
Clocks
• Essential for MCU operation • Typically there are two clocks
- Main clock • Drives CPU and controls its operation• Can be divided or multiplied for slower or faster
operating speed• External design uses crystal and two capacitors• Internal design built with modern technology produces
40MHz with 1% accuracy; saves cost, simplifies design
- Sub-clock• Generates a second (lower) frequency that drives CPU
in a slower, low-power mode (Standby mode, etc.) • Also used for driving some peripheral functions• Typically a 32.768kHz clock that enables accurate
generation of a second frequency via a 16-bit counter
OSC1 OSC2
MCU
Quartzcrystal
C1 C2
Main Clock Circuit
Low-power Modes
• Required for portable devices that achieve extended operating time on battery power, as well as many other energy-efficient products
• Reduce power consumption by various means
– Running at slower speed, such as sub clock (32.768kHz)• Sleep, Sub-active, Standby modes
– Shutting off unused peripherals• Module Stop mode
In some of the latest MCUs, Standby mode consumes <1µA
Ports: I/O, Input and Output
Interface to the “outside world”
• I/O ports monitor and control communication between devices
– Can be parallel or serial
• Input-only ports acquire data from external sensors, etc.
• Output-only ports drive external displays and actuators, etc.
– High-current (20mA) port • Drives an LED directly
– Open-collector/drain port• Interfaces with higher-level supply
circuitry• Implements wired-NOR condition
MCUPort Types
Output only(DAC, LED drive, etc.)
Input only(ADC, etc.)
Input/Output(SCI, I2C, etc.)
Timers and Watchdog Timer (WDT)
• Count clock pulses to control sequences of events or processes
• Timers (8-bit or 16-bit)
– Measure timing of events or generate output signals– Have various operating modes and features for different applications– Can be cascaded to create larger timers
• WDT (Watchdog Timer)
– Safeguards MCU by providing safe exit from a malfunctioning program– Must be reset at regular intervals or reset/restart will be generated
ResetControl
Internal Reset Signal
ITI (interruptrequest signal)
WDTOVFClock
Internal Clock Sources
WTCNTOverflow
Clock Select
WTSCR
BusI/F Module bus
Internal bus
InterruptControl
WRCSR
ResetControl
Internal Reset Signal
ITI (interruptrequest signal)
WDTOVFClock
Internal Clock Sources
WTCNTOverflow
Clock Select
WTSCR
BusI/F Module bus
Internal bus
InterruptControl
WRCSR
Watchdog TimerInternal Reset Signal
Overflow
Pulse Width Modulator (PWM)
• Generates continuous pulses at preset intervals
• Width of pulse can be set and varied in response to a control signal
• Can be used to drive a motor, light an LED, change power level, etc.
Control signal sets nominal width of PWM output pulse and causes it to vary
PWM Output
PWM Signals
ADCs and DACs
Provide interfaces to the analog (real) world
• Analog-to-digital converter (ADC or A/D)
– Converts analog signal levels to digital values– Important characteristics
• Accuracy and Resolution (determined by number of bits: 10, 12, 14…)