microcontroller basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf ·...

18
Microcontroller Basics Microcontroller Basics Gabe Cohn CSE 599U February 8, 2010 CSE 599U February 8, 2010

Upload: others

Post on 18-Aug-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

Microcontroller BasicsMicrocontroller Basics

Gabe CohnCSE 599U – February 8, 2010CSE 599U  February 8, 2010

Page 2: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

OutlineOutline

O i f E b dd d S• Overview of Embedded Systems

• What is a Microcontroller?

• Microcontroller Features

• Common Microcontrollers

Ch i Mi ll• Choosing a Microcontroller

• Development Kitsp

Page 3: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

Overview of Embedded SystemsOverview of Embedded Systems

• Minimal computation, simple software (no/simple OS)p , p ( / p )• Low power (typically battery powered)• Event Driven Design• Mostly IO (Inputs and Outputs)

– Sensors, Switches, KeypadDi l LED– Displays, LEDs

– Actuators, Servos– Data communication (wired or wireless)Data communication (wired or wireless)

• Data Conversion– Analog‐to‐Digital, Digital‐to‐Analog

Page 4: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

Generic Embedded SystemsGeneric Embedded Systems

Page 5: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

Example: Using Discrete ComponentsExample: Using Discrete Components

Page 6: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

What is a Microcontroller?What is a Microcontroller?

Page 7: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

Example: Using A MicrocontrollerExample: Using A Microcontroller

Page 8: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

Microcontroller FeaturesMicrocontroller Features

• CPUCPU• Program and Data Memory (ROM and RAM)• Reset and Oscillator Circuitry• Reset and Oscillator Circuitry• TimersD t C t (ADC DAC)• Data Converters (ADC, DAC)

• Buffered GPIOs• Simple Peripheral Interface• Reduced System Size, Complexity and Cost

Page 9: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

CPUCPU

• RISCSC• Harvard Architecture (separate program and data memory)p g y

• Pipelined Load‐Store Architecture

• Lower clock speeds (8‐32 MHz)• Optimized for low‐level compilers like C

• Typically no OS is used ( i OS)(sometimes RTOS)

Page 10: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

MemoryMemory

• On‐chip RAM and ROMOn chip RAM and ROM• No external access to address and data buses

d “ ” h d• Need a “programmer” to program the code into the ROM (typically Flash these days)

• Size range 10s of bytes to 100s of KB– main difference in price between similar products

Page 11: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

Reset and Oscillator CircuitryReset and Oscillator Circuitry

• ResetReset– Internal or ExternalWatchdog Timer (WDT)– Watchdog Timer (WDT)

– Brownout Reset (BOR)

O ill t• Oscillator– Several sources to choose from– Internal or External– PLL and clock frequency adjustment

Page 12: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

TimersTimers

• Typically several different timersTypically several different timers– Real‐Time Clock (RTC)Watchdog Timer (WDT)– Watchdog Timer (WDT)

– PWM output common

S l l ki ti• Several clocking options• Event based notification (Interrupts)

– Allows CPU to focus on foreground tasks

Page 13: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

Data ConvertersData Converters

• ADC (very common)ADC (very common)– Several channelsMultiple clocking options– Multiple clocking options

– Several different typesC t d th l i it– Comparators and other analog circuitry

– Important for ratiometric sensors

(l )• DAC (less common)– Several different types

Page 14: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

GPIOsGPIOs

• Many General Purpose Analog/Digital IOsMany General Purpose Analog/Digital IOs– Buffered to drive typical embedded loadsMultiplexed for several functions– Multiplexed for several functions

– Switchable internal pull‐up, latch, etc…Ed d t ti– Edge detection

– Schmitt trigger inputs on somei diff i i b i il d– main difference in price between similar products

Page 15: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

Simple Peripheral InterfaceSimple Peripheral Interface

• Serial (Sync/Async SPI I2C)Serial (Sync/Async, SPI, I C)• CAN bus (automotive)

d C ll• LED and LCD controllers• Ethernet, USB, and Video controllers• DMA, DRAM, SDRAM controllers• Host Processor Interface External MemoryHost Processor Interface, External Memory Bus

Page 16: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

Common MicrocontrollersCommon MicrocontrollersFamily Manufacturer Word Size* Common Uses

ARM Various 32‐bit Consumer Electronics

AVR Atmel 8‐bit

PIC Microchip 8‐bit HobbyistPIC Microchip 8 bit Hobbyist

MSP430 TI 16‐bit Low Power

6805 Motorola/Freescale 8‐bit Automotive

* Many of these µCs now come in wider bus architectures as well

Page 17: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

Choosing a MicrocontrollerChoosing a Microcontroller

• All very similar so stick with a family you knowAll very similar, so stick with a family you know• Required features

i d b f G O• Required number of GPIOs• Memory requirements• Availability of programmer (USB?)• Availability of a good C compilerAvailability of a good C compiler• Packaging

Page 18: Microcontroller Basicshomes.cs.washington.edu/~shwetak/classes/cse599u/notes/micro.pdf · Microcontroller Basics Gabe Cohn CSE 599U – February 8, 2010. Outline • OiOverview of

Development KitsDevelopment Kits

• Fast and Easy!y• Everything you need is included– uC, power supply, USB connection, simple IO

• Low level code is writtenLow level code is written for you!– port_write(addr, value)

• Example code and projects• Often large online forums for support

Example: Arduino (AVR based kit)

for support