Introduction

Download Report

Transcript Introduction

Introduction

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

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

CLASSIFICATION Device System implementation MPU Typically contains only the main processor (CPU core) — no memory for program storage Multiple chips MPU

(Typically, only the CPU Core)

Memory IO Peripherals MCU Contains CPU core, memory, peripherals, and I/O integrated Single chip MCU CPU Core Memory Peripherals I/O Processor core (CPU) Application considerations Application examples Renesas product lines 32 bits or above Necessary for very complex, high performance and expandable systems Needs external memory & peripherals to accomplish a task Handheld multimedia phone, car navigation system SH-3 and SH-4 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 Washing machine, rice cooker, air conditioner M16C, H8, SH-1, and SH-2 series

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 Main Clock CPU

(16-bit H8 type)

Sub-Clock RAM ROM PWM Timer Timer PWM Timer Timer Serial Interface Timer WDT ADC LCD Controller Example: H8/38024 16-bit MCU

Processor Core (CPU)

Function

– Fetches and executes machine code – Provides levels of code efficiency and performance •

Architectural design features Instruction execution Code efficiency

– CISC type or RISC type • RISC has fewer instructions – Word size: 4, 8, 16, or 32 bits

RISC CISC Fast

: 1 instruction/cycle

Slower

: Many instructions take multiple cycles

Lower

: Moderate – General registers for data processing and temporary storage to assist in program control – Data bus for interconnections

High

: Very compact code – Arithmetic Logic Unit for arithmetic and floating point operations – Special registers (program counter, stack, conditional, status) – Operating frequency/clock speed range Voltage dependent

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 Yes

Reads & writes, but temporary storage 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

Main Clock Circuit MCU OSC1 OSC2

Quartz crystal C 1 C 2

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

MCU

Port Types Input/Output (SCI, I 2 C, etc.) Input only (ADC, etc.) Output only (DAC, LED drive, 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

Watchdog Timer Internal Reset Signal ITI

(interrupt request signal)

Interrupt Control Overflow Reset Control Bus I/F

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.

PWM Signals PWM Output Control signal sets nominal width of PWM output pulse and causes it to vary

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

Analog input Digital input

(Serial [PWM] or Parallel)

ADC DAC Digital output Analog output

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, I 2 C, SPI, LIN, CAN • Based on industry standards • Optimized for certain applications

Generally uses only 3 pins

– Serial In, Serial Out, and Clock

CAN:

a high-integrity, asynchronous serial data communication bus for automotive and industrial applications

CAN #1 Accept Select Receive message CAN bus CAN #2 Prepare Send message CAN #3 X Select Receive message CAN #4 Accept Select Receive message

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

CPU RAM ROM MCU Bus Controller External Memory

(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 – Clock

Typical System Debug Setup PC USB I/F OCD Emulator

(Example: Renesas E8)

Target Board MCU

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) OSCD Currents DCCT Currents Pressure Sensor Bus-voltage Sensor LEDs ADC

M16C/28

ADC (AN0, AN1) (AN2, AN3) 3-phase Motor Control Timer INT0 ADC (AN6) DMA Timer A0 ADC (AN7) INT3 I/Os Timer A3 INT4 INT5 IPM

BLDC

Error Pulse Hall Sensors Pulse-width Measurements

Application example: MCU control of brushless DC motor

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.)

Application Needs System Requirements Debugging

(Optional)

VCC Clock Mode Reset Interrupts

(Internal)

MCU GND Inputs

(keypad, sensors, switches, etc.)

Outputs

(Control signals, display drive, actuator drives, etc.)

What System Developers Want

MCUs that meet the requirements of the application 1. Sufficient performance 2. Small code size 3. Requisite peripherals 4. Low power consumption 5. Good EMC performance 6. Fail-safe features 7. Good Flash ROM technology Support tools that shorten system development time 8. Good development environment 9. Complete set of SW/HW tools

Course Summary

Differences between MCUs and MPUs

Functions within an MCU

Basic embedded system signals

Questions engineers ask when choosing an MCU

For more information, please visit our Web site:

www.renesas.com