Advanced Microcontrollers Grzegorz Budzyń Lecture 1: Introduction
Plan Introduction Course requirements Workplan for thesemester Firstlecture Basic definitions, Microcontroller, Microprocessor
Introduction Whatisthiscourseabout Whatistheaimofthiscourse
Courserequirements Course consists of: Lecture 2h/week Project 2h/week Courseendswithanexam Course completion requires passing project classandtheexam Theexamwill be heldduringexamination period andwill be oral
Lecture1 Workplanfor thesemster Basic definitions. Embedded systems. Main elements of embedded systems Lecture2 8-bit microcontrollers: AVR family. PIC Micro family Lecture3 8-bit/16-bitmicrocontrollers:8051 family, MSP430 family
Lecture4 Workplanfor thesemster 32-bit microcontrollers: AVR32 and PIC32 family Lecture5 32-bit microcontrollers: ARM family. ARM7, ARM9, ARM11, Cortex M, R, A Lecture6 32-bit microcontrollers: ARM based microcontrollers: STM, NXP
Lecture7 Workplanfor thesemster DSC & PSoCcontrollers Lecture8 DSP processors Lecture 9,10 Serial interfaces: USB, RS232, SPI, I2C, CAN
Workplanfor thesemster Lecture11 ADC anddac Lecture 12,13 RTOS introduction, main parameters Lecture14 RTOS -examples Lecture15 Methods of interfacing ADC and DAC to advanced microcontrollers
Lecture1 Embedded systems Microcontrollers
Embedded systems
Embedded systems Embedded system a system designed to perform/ control specific function in a larger design Often with real time computing constraints (i.e. with predictable response)
Embedded systems
Embedded systems Because Embedded System has defined functionality, thus it can be heavily optimized in order to: Minimize total cost Maximize performance Maximize perfomance/cost ratio
Embedded systems Main elements: Microcontrollers: 8-bit 16-bit 32-bit Digital Signal Processors Digital Signal Controllers FPGA / ASIC programmable logic
Embedded systems Embedded software architecture: Simple control tasks/loops: Used for simples applications Used mostly for 8-bit and 16-bit constructions Efficient (in assembly code even very efficient) Difficult to construct for more complicated tasks
Embedded systems Embedded software architecture: Interrupt based system: Most common type of embedded system software architecture Can be very efficient and rapid in development even for quite complicated tasks/devices Functionality depends greatly on the used microcontroller : Number of serviced interrupt sources Interrupt latency
Embedded systems Embedded software architecture: Simple real-time operating system: Very usable for programming different, nondependent on themselves tasks Very usable for parallel development by a few programmers Timing control & latency control worse than in simpler systems Cooperative or Preemptive multitasking can be used
Embedded systems Embedded software architecture: Monolithic operating system: Large kernel gives programmers an environment similar to a desktop operating systems like MS Windows (WinCE, Win 8 RT), Linux or Android Usable in the largest applications like GPS or cell phones Hardware layer controlled totally by the system applications isolated from the hardware
Microcontroller- basics
Microcontrollers - basics Microcontroller is a combination of a microprocessor and peripheral blocks like: Memory (RAM, ROM, flash) Serial port Ethernet controllers USB controllers ADC DAC etc
Microcontrollers - basics Microprocessor (CPU) inside a microcontroller (MCU) is supervising data transfer berween peripherals over data buses Main advantages of MCUs are: High integration scale Low cost
Microprocessor- operation
Microprocessor - basics Microprocessor: is a programmable device accepts digital input data processes the data according to instructions stored in memory provides results as output operates on symbols represented in binary numeral system
Microprocessor - basics Main elements: Arithmethic Logic Unit Status Register Stack Pointer Program Counter Instruction Decoder Registers / Scratch Memory
Microprocessor - basics
Microprocessor - ALU ALU Arithmetic Logic Unit is the heart of microprocessor Width of A,B and R defines if microprocessor is 8-, 16-, 32- or 64 bits!!!
Microprocessor - ALU Functionality of ALU depends on the paticular realisation Usually it offers: Addition Subtraction Comparison Logical operations Multiplication Division
Microprocessor Status register Status register contains various flags and control bits Flags in the register are modified by different assembly code instructions
Microprocessor Stack Pointer TheStackismainlyused: for storing temporary data for storing local variables for storing return addresses after interrupts and subroutine calls The Stack Pointer Register always points to the top ofthestack the Stack is implemented as growing from higher memory locations to lower memory locations
Microprocessor Program Counter Program Counter (PC) - a special register holding the address of the instruction currently being executed Programcounter is automatically advanced to point to the next instruction in the case of a jump, subroutine call, etc., a new value will simply be loaded into the program counter in order to cause a jump
Microprocessor Instruction decoder Instruction decoder fetches instructions from a proper memory In the next cycle the instructions are decoded and then executed For faster execution pipelining is used
Microprocessor Registers Each CPU consists of a certain number of universal registers They are usually used as temporary storage of data In some CPUs instead of registers a memory is used Access to the registers/momey is much faster than to external memory
Microprocessor program flow
Microprocessor program flow The program control logic and programaddressgenerationlogicworktogetherto provide proper program flow Normally, theflowofa program issequential: the CPU executes instructions at consecutive program-memory addresses Discontinuities are caused by branches, function calls or interrupts
Microprocessor program flow Program execution starts from the address pointed by a special RESET pointer Instructionsareina machinecode i.e. streamof8-, 16-or32b longvalues For simplicity assembly code is used:
Microprocessor memory map
Microprocessor addressing modes
Microprocessor addressing modes Direct Single Register Addressing Direct Register Addressing, Two Registers I/O Direct Addressing Direct Data Addressing Data Indirect with Displacement Data Indirect Addressing Data Indirect Addressing with Pre-decrement
Microprocessor addressing modes Data Indirect Addressing with Post-increment Program Memory Constant Addressing Program Memory Addressing with Postincrement Direct Program Memory Addressing Indirect Program Memory Addressing Relative Program Memory Addressing
DirectSingle Register Addressing Very simple, efficient and fast addressing mode Usableonlyfor accessto register file
Direct Register Addressing, Two Registers Very simple, efficient and fast addressing mode Usableonlyfor accessto register file
I/O Direct Addressing Easyandefficientaccessto I/O memory Access only to limited memory space(6-bit wide)
DirectData Addressing Access to wholememoryspace Instruction takes much more memory Instruction decoding lasts long
Data IndirectwithDisplacementAddressing Target address calculated in dependance on the special addressing-register (Y orz)
Data IndirectAddressing Targetaddresstakefromthespecial addressing-register (X, Y orz)
Data Indirect Addressing with Pre-decrement The content of an addressing register is decremented before use Especially useful in higher level languages
Data IndirectAddressingwithPost-increment The content of an addressing register is incremented after use Especially useful in higher level languages
Program MemoryConstantAddressing Access to program memory(loadingwithlpm or storing with SPM instructions)
Program Memory Addressing with Post-increment Access to program memory(loadingwithlpm or storing with SPM instructions) Z-register incremented after use
DirectProgram MemoryAddressing Program execution continues at the address immediate in the instruction word UsedinJMP andcall instructions
IndirectProgram MemoryAddressing Program execution continues at address contained by the Z-register (i.e., the PC is loaded with the contents of the Zregister)
RelativeProgram MemoryAddressing Program executioncontinuesataddresspc + k + 1. Therelativeaddressk isfrom-2048 to 2047.
Microprocessor- classifications
Microprocessorclassifications SIMD ang. Single Instruction Multiple Data SISD ang. Single Instruction Single Data MIMD ang. Multiple Instruction Multiple Data MISD ang. Multiple Instruction Single Data
Microprocessorclassifications CISC ang. Complex Instruction Set Computers RISC ang. Reduced Instruction Set Computers
Microprocessorclassifications Architectures: Von Neuman Harvard Harvard modified
Microprocessorclassifications SISD features: One data stream One instruction stream Simple construction Reduced efficiency Very popular Most microcontrollers works with this architeture Source: [1]
Microprocessorclassifications MISD features: Many instruction streams Single data stream Parallel operation Many unitsmakesthe same operationon one data Rarely used Source: [1]
Microprocessorclassifications SIMD features: Single instruction stream Many data streams Efficient parallel processing Different data processed in the same way Used in supercomputers, vector coprocessors and DSP Source: [1]
Microprocessorclassifications MIMD features: Many instruction streams Many data streams Efficient parallel processing Many units operates independently and asynchronously Used in computation networks Source: [1]
Microprocessorclassifications CISC architecture: Large number of instructions Small optimization Some instructions need many clock cycles Existance of complex instructions Large number of addressing modes Smallerprocessorclockingas comparedto RISC architecture
Microprocessorclassifications RISC architecture: Reduced number of instructions(even below 30) Most instructions performed in one clock cycyle Instructions simple or very simple Limited access to memory Large number of auxiliary registers
Microprocessorclassifications Von Neumann architecture Source: [2]
Microprocessorclassifications Harvard architecture Source: [2]
8-bits vs16-bits vs32-bits Some remarks: More bits= easier operation with large number of data More bits = less problems with computation errors More bits faster operation
8-bits vs16-bits vs32-bits Some remarks: Simpler processors can be overclocked more easily 32-bit processors are usually fasterbecause that is necessary Smaller processors are very often much more efficient and simpler for programming then their large brothers
Numbers in microcontrollers CPUs natively support only integer numbers signed or unsigned CPU accumulator width defines size of supported numbers: 8b -> [0;0xff] = [0;255] 16b -> [0;0xffff] = [0;65535] 32b -> [0;0xffffffff] = [0;4294967296]
Numbers in microcontrollers Signed integers are usually written in U2 code: i.e. -1 = 0xff -128 = 0x80
Numbers in microcontrollers In CPUs there is problem with non-integer numbers Some CPUs support fractional numbers Some have additional coprocessor (Floating Point Unit FPU) for real numbers calculation
Numbers in microcontrollers Comparison of Integer and Fractional numbers:
Numbers in microcontrollers Integer: 8-bit (Byte) 16-bit (Word) 32-bit (Long) Float: Single precision (float) Double precision (double)
Numbers in microcontrollers Single precision: S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF 0 1 8 9 31 X = ( 1) S 1. F 2 E 127 S sign E exponent bits F - fraction
Numbers in microcontrollers Double precision: S EEEEEEEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 0 1 11 12 63 X = ( 1) S 1. F 2 E 1023 S sign E exponent bits F - fraction
Endiannes Endiannes is the same as byte-order Big-endian = MSB goes first Little-endian = LSB goes first
Benchmarking
Benchmarking Benchmarking is used for speed comparation of microprocessors and microcontrollers Comparing microprocessors is difficult Comparing microcontrollers is even more difficult itisfairlyeasyto comparecoresbut very hard to compare peripherals!!!
Benchmarking Main measures of microcontrollers core speed are: MIPS DMIPS FLOPS
Benchmarking-MIPS MIPS Millions of Instructions Per Second Simplealgorithmusuallyused speedofnop instruction Comparison of processors speeds requires thorough analysis. The speed of a given CPU is dependent upon many factors: the type of instructions being executed, the execution order and the presence of branch instructions(pipeline!)
Benchmarking-MIPS CPU instruction rates are usuallydifferent from clock frequencies Each instruction usuallyrequire several clock cycles to complete The number of cycles required for instructions to complete is dependent upon the instruction being executed MIPS can be useful when comparing performance between processors made from a similar architecture
Benchmarking-DMIPS DMIPS anothernamefor Dhrystonetype computer speed test Dhrystone is a synthetic computing benchmark intended to be representative of system (integer) programming Thealgorithmiswelldocumentedandcan be made to work on almost any system
Benchmarking-DMIPS DMIPS shortcomings: it features unusual code that is not usually representative of real-life programs it is susceptible to compiler optimizations Dhrystone'ssmall code size may fit in the instruction cache of a modern CPU, so that instruction fetch performance is not rigorously tested
Benchmarking-FLOPS FLOPS - FLoating-point Operations Per Second Measure of floating point arithmetic operation speed of a microcontroller Similarto MIPS but for floatingpoint numbers
Thank you for your attention
References [1] www.wikipedia.org [2] http://www.scribd.com/doc/1532910/von-neumann- Computer-Architecture [3] www.atmel.com