Distributed Real- Time Control Systems Lecture 2 Embedded Systems Basics A. Bernardino, C. Silvestre, IST- ACSDC 1
What are embedded systems? Small computers to efficiently address specific purposes, e.g. sensing and control. Advantages: Low cost Small form factor Low energy consumpoon Reliability Hard Real- Time funcoons. Very fast boot Disadvantages: Harder to program and debug. Limited funcoonality (speed, memory, devices). Proprietary souware/hardware, difficult support and maintenance. May require some interface electronics. A. Bernardino, C. Silvestre, IST- ACSDC 2
ApplicaOons of Embedded Systems SCDTR 2013/2014 - Lecture 2 A. Bernardino, C. Silvestre, IST- ACSDC 3
Microcontroller Units (MCU) Microcontrollers (µc) Applied mostly for sensing, control and automaoon. Contain several I/O ports to interface with physical devices (digital and/or analog). Digital Signal Processors (DSP) Applied mostly for signal processing applicaoons. Contain dedicated instrucoons, floaong point units and special architecture to speed up signal processing operaoons. A. Bernardino, C. Silvestre, IST- ACSDC 4
Basic Architecture ROM (FLASH) - Program memory. Store the program to be executed. Non- volaole. RAM - VolaOle memory. Hold temporary variables and stack. EEPROM - For permanent storage. Slow wriong. SFR Special funcoon registers. Memory mapped I/O. Program Counter Controls execuoon I/O Ports - Connect to peripheral devices. Oscillator Setup the Ome base. Timers/Counters Count Ome WDT (Watchdog Timer) Separate Omer to reset the system when it hangs. Serial CommunicaCons To interface with other devices. Interrupts To respond to events (internal or external) A. Bernardino, C. Silvestre, IST- ACSDC 5
More on Architecture Addressing Models Harvard architecture Separate bus for program and data. Programs execute from ROM. Adopted by most classes of MCU s: Intel 8051, Atmel AVR, Microchip PIC, Cypress PSoC. Princeton (Von Neuman) Architecture Unified address space. You can jump to code anywhere (even if it does not make sense ) FloaCng point operacons Some MCU s do not have floaong point unit. Must use fixed point methods. Some manufacturers provide libraries for emulaoon. Peripheral Interface Controllers Some I/O operaoons can be outsourced from the CPU. Specific controllers for reading/wriong output ports, serial communicaoon, direct memory access (DMA). Adopted by Freescale 68HC11 and PC s A. Bernardino, C. Silvestre, IST- ACSDC 6
MCU SelecOon Criteria Core speed Memory size (RAM, ROM, EPROM) Bus architecture Address/Data bus depth (8, 16, 32, 64 bit) Number of digital I/O ports. Number of analog I/O ports (ADC/DAC) I/O resoluoon (8, 12, 16, 24 bit) Timer Units Development Tools Interrupt Lines Serial CommunicaOons (SPI, I2C, USB, IR, GbE) Product Family Peripheral Interface Controllers FloaOng Point units DMA controller Power consumpoon Cost (HW/SW tradeoff) Environmental CondiOons A. Bernardino, C. Silvestre, IST- ACSDC 7
Famous MCU Families Intel 8051 Atmel AVR Microchip PIC Microchip dspic Freescale Zilog Z8 Cypress PSoC TI MSP430 Manufacturer sites provide selecoon tools: A. Bernardino, C. Silvestre, IST- ACSDC 8
Programming MCU s Compilers and interpreters for MCU s C Ada Assembly C++ BASIC Forth PIC Basic Dynamic C Java Python like (Pyastra, PiMite) Programming modes Compile in PC and download to MCU. Some large embedded systems can run compilers or interpreters. Compilers Classically provided by the manufacturers. Several open source versions currently available. A. Bernardino, C. Silvestre, IST- ACSDC 9
Downloading Programs to MCU IC Programmer Plug the chip in the programmer, reprogram, then put the chip back on the embedded system. In Circuit Serial Programmer (ICSP) Plug a cable from the programmer into an header close to the chip in the embedded system. Bootloaders Programs in ROM that manage the downloading process A. Bernardino, C. Silvestre, IST- ACSDC 10
Bootloaders When the MCU powers up, program execuoonstarts at a predefined point in program memory. In development cycle, we may want to change the program very ouen. To facilitate this, a program called bootloader interfaces with the user to load the kernel. The bootloader is acove for a few seconds when the board resets; then it starts whichever program was most recently uploaded to the microcontroller. Disadvantage Occupies (precious) space in Program Memory A. Bernardino, C. Silvestre, IST- ACSDC 11
Debugging MCU s ICE In Circuit Emulator Special processor that emulates the device to debug but allows breakpoints and inspect. Expensive ICD In Circuit Debugger The microcontroller has a small amout of hadware to allow stepping through the code and inspect variables. Increase MCU cost. Simulator A special souware emulates the hardware and allows debugging features. Not good for debugging interrupts. Breakpoint and step based approaches are not good for control because they interrupt the control loop. We must use other methods Serial CommunicaOon Send debug messages via serial communicaoon to a host device. Very simple and efficient but too slow to use in interrupts. LCD Display debug messages in a display arached to I/O ports. Wastes I/O ports LED Blink to communicate status. PIN debugging Send messages via I/O Pins. Check with oscilloscope Logic Analizer Captures the waveform of arached pins. A. Bernardino, C. Silvestre, IST- ACSDC 12
Atmel AVR Family Memory Data memory: Registers, I/O registers, SRAM Program Flash memory (10000 rewrites) EEPROM Fuse Bits Watchdog Timer Resets processor when it Omes out Interrupts External and Internal Timers/Counters GPIO ADC (8-10 bits) PWM USART (RS- 232, RS- 485, MIDI, Linbus, CAN- BUS). TWI (I2C) SPI A. Bernardino, C. Silvestre, IST- ACSDC 13
ATMEL AVR Family OnyAVR 0.5 8KB Flash 6-32 pins Up to 20MHz 1.0 MIPS/MHz megaavr 4-256KB Flash 28-100- pins Up to 20 MHz 1.0 MIPS/MHz XMEGA (8-16 bit) 16-384KB Flash 44-100 pins Up to 32 MHz 1.0 MIPS/MHz UC3 (32 bit) 16-512KB Flash 48-144 pins Up to 66 MHZ 1.5 MIPS/MHz A. Bernardino, C. Silvestre, IST- ACSDC 14
AVR Development Boards Burerfly Demo Board: Self- contained, barery- powered demonstraoon board with a variety of peripherals and ports. STK500 Starter Kit Power Supply, Sockets for Chips, RS232 interface to PC, In- System Serial Programming, Push burons, connectors, etc A. Bernardino, C. Silvestre, IST- ACSDC 15
AVR Third Party Boards Arduino GPMPU40 Futurlec 2313 Board Olimexino Protostack kits A. Bernardino, C. Silvestre, IST- ACSDC 16
ATMEGA 328 CPU (20 MIPS) SRAM (2K) FLASH (32K) EEPROM (1K) 3 TIMERS A/D USART SPI TWI (I2C) Watchdog 4$ (10+units) 1.8V 5V 28 Pin A. Bernardino, C. Silvestre, IST- ACSDC 17
More about ATMEGA 328 The Datasheet is the embedded system s programmer best friend! A. Bernardino, C. Silvestre, IST- ACSDC 18
Arduino Prototype Boards ARDUINO is a family of ATMEL MCU prototype boards: UNO ATMEGA328 LEONARDO ATMEGA32U4 MEGA 2560 ATMEGA2560 DUE SAM3X8E ARM ETHERNET ATMEGA328 MEGA ADK ATMEGA2560 MICRO ATMEGA32U4 NANO ATMEGA328 FIO ATMEGA328 MINI ATMEGA328 PRO MINI ATMEGA168 LILYPAD ATMEGA168/328 PRO ATMEGA168/328 A. Bernardino, C. Silvestre, IST- ACSDC 19
Arduino Uno V3 A. Bernardino, C. Silvestre, IST- ACSDC 20
Arduino Uno V3 Microcontroller OperaCng Voltage Input Voltage (recommended) Input Voltage (limits) Digital I/O Pins ATmega328 5V 7-12V 6-20V 14 (of which 6 provide PWM output) Analog Input Pins 6 Max DC Current per I/O Pin Max DC Current for 3.3V Pin Max Total DC current Flash Memory SRAM EEPROM Clock Speed 40 ma 50 ma 500 ma 32 KB (ATmega328) of which 0.5 KB used by bootloader 2 KB (ATmega328) 1 KB (ATmega328) 16 MHz A. Bernardino, C. Silvestre, IST- ACSDC 21
Arduino Uno V3 Pins Power VIN, 5V, 3V3, GND Control RESET Analog In A0, A1, A2, A3, A4, A5 Digital I/O 0,1,2,3,4,5,6,7,8,9,10,11,12,13 Reference for Shields AREF, IOREF Programmable LED 13 Serial 0 (RX), 1 (TX) External Interrupts 2, 3 PWM 3,5,6,9,10,11 SPI 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK) TWI (I2S) A4 or SDA, A5 or SCL A. Bernardino, C. Silvestre, IST- ACSDC 22
Uno ATmega Pinout Correspondence A. Bernardino, C. Silvestre, IST- ACSDC 23