purpose – this course introduces basic facts about microcontrollers. objectives – understand the...
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…)
• Sampling frequency• Conversion technology (successive
approximation, delta-sigma, etc.)
• Digital-to-analog converter (DAC or D/A)
– Converts digital values to analog signal levels– Can be improvised using a low-pass filter
after a PWM output
ADC
Analoginput
Digitaloutput
DAC
(Serial [PWM]or Parallel)
Analogoutput
Digitalinput
Serial Interface
• Connects MCU to other parts of embedded system or to other systems
• Various types
– Asynchronous mode (most widely used)
– Synchronous mode (has higher transfer rate)
– Other examples: USB, I2C, SPI, LIN, CAN • Based on industry standards• Optimized for certain applications
• Generally uses only 3 pins
– Serial In, Serial Out, and Clock
Accept
Select
Receivemessage
CAN bus
Accept
Select
Receivemessage
Prepare
Sendmessage
Receivemessage
Select
X
CAN #1 CAN #2 CAN #3 CAN #4
CAN: a high-integrity, asynchronous serial data communication
bus for automotive and industrial applications
Bus Controller
• Incorporated in MCUs that must access external memory as well as internal memory
• Manages internal and external memory buses
• Controls bus communication functions– Refresh for DRAM – Length of wait states– Bus arbitration– Other signal-control tasks
Bus Controller
CPU
RAM
ROM
MCU
ExternalMemory(DRAM)
On-Chip Debug (OCD)
• Circuitry incorporated in MCU for system development and debugging
• JTAG interface commonly used (No standard for JTAG debugging)
• Debugger (typically purchased from MCU manufacturer or custom built)
• Usually requires only a few device pins to implement MCU control via a “JTAG-like” emulator on a PC
– Mode selection
– Data in/out
– ClockUSB I/F
PC
Target Board
OCD Emulator (Example: Renesas E8)
MCU
Typical System Debug Setup
Other On-chip Functions
• Many other peripherals can be integrated to perform specific tasks
– LCD controller, power-line communication (PLC), Ethernet MAC, 3-phase motor control timer, DMA, and more
• Additional functions enhance fail-safe design of embedded systems
– Low-voltage detection (LVD), power-on reset (POR), oscillation-stop detection (OSD)
Application example: MCU control of brushless DC motor
Timer A0
ADC(AN0, AN1)
I/OsTimer
A3
INT3
INT4
INT5
BLDC
INT0
3-phaseMotor
Control Timer
Hall Sensors
Pulse-widthMeasurements
ErrorPulse
OSCDCurrents
DCCTCurrents
PressureSensor
Bus-voltageSensor
ADC(AN2, AN3)
ADC(AN6)
ADC(AN7)
LEDs
IPM
M16C/28
DMA
Basic Embedded System Signals
• Required for MCU/system operation
– Power (VCC & GND), Clock, Mode, Reset, and Debugging (optional)
• Used by application
– Inputs (keypad, switches, sensor data, network communication, etc.)– Outputs (motor control, LCD drive, network communication,
actuator energization, etc.)
ClockModeReset
VCC
Debugging(Optional)
Outputs(Control signals, display drive, actuator drives, etc.)
Inputs(keypad, sensors, switches, etc.)
System Requirements Application Needs
GND
MCU
Interrupts(Internal)
What System Developers Want
8. Good development environmentSupport tools that
shorten system development time
2. Small code size
1. Sufficient performance
3. Requisite peripherals
4. Low power consumption
5. Good EMC performance
6. Fail-safe features
7. Good Flash ROM technology
MCUs that meet the requirements of the application
9. Complete set of SW/HW tools