Distributed Real-Time Control Systems Module 3 Hardware for Real Time Distributed Control Systems 1
General Topology of Real-Time Distributed Control Systems System Management Data Backup Intranet User Interface Coordination Data Logging Control Network Sensing Node Control Node Control Node Driver Node sensor sensor actuator sensor actuator actuator 2
Control Node Requirements Power System Volatile Memory Permanent Memory Watch Dog Sensors Timers/ Counters Signal Acquisition CPU/ALU Interrupts Signal Generation Actuators Communications 3
Microcontroller Units (MCU) Encapsulate all required functions in a single chip. Computer architecture specialized for real-time deterministic and predictible behaviour. 4
Advantages/Disadvantages to General Purpose Computers Advantages: Low cost Small form factor Low energy consumption Reliability Hard Real-Time functions. Very fast boot Disadvantages: Harder to program and debug. Limited functionality (speed, memory, devices). Proprietary software/hardware, difficult support and maintenance. May require some interface electronics. 5
Power Saving Other Features Sleep modes, wake-up on interrupt Security lock bits Reliability Watch-dog, Brown-out detection, Temperature sensing 6
What to do in case of detected failure? Drone Automatic car Segway Coffee Machine Traffic Lights Media Players Power off Hold state Zero Outputs Alarm 7
What to do in case of detected failure? Power off Hold state Zero Outputs Alarm Drone x x Automatic car x x Segway x x Coffee Machine x x x Traffic Lights x x Media Players x 8
Alternative/Complementary Hardware Digital Signal Processors (DSP) : for signal processing applications (vector instructions, floating point units, direct memory access, multiply-add instructions). Field Programmable Gate Arrays (FPGA) and Application Specific Integrated Circuits (ASIC) : for highly optimized and custom purposes. System-on-Chip (SoC), Single- Board-Computers (SBC), Computeron-Modules (COM) : for embedded soft real-time nodes. 9
Applications Ethernet Switches WIFI routers Modems Toys Digital Watches Digital Cameras Multimedia players Traffic lights Factory controllers Robotics Videogame consoles Automatic Sales Machines Electronic Payment Terminals Automotive (ABS,ESC) Microwave Ovens Washing Machines Home Automation (alarm systems, sensors) IP cameras Printers GPS Medical Instruments Musical Instruments Smart Phones and Tablets TV boxes Smart Clothes Aerospace systems (satelites, drones, UAV s) 10
The Lab Project Distributed lighting control system. Cloud Single Board Computer Microcontroller Microcontroller High Power LED Light Sensor High Power LED Light Sensor 11
The Microcontroller Kit Arduino UNO 12
The Embedded Computer Raspberry PI 3B SBC with SoC 13
Project Phases Implementation divided in 2 phases: Real-Time Control Microcontroller Programming. Sensing and Actuation. Digital Controller Implementation. Serial Communications. Distributed Control: Control Networks (I2C). Distributed Optimization. Concurrent Systems. Socket Communications. 14
Microcontroller Architecture ATMEGA328 CPU (20 MIPS) SRAM (2K) Volatile memory. Hold temp variables and stack. FLASH (32K) Store the program to be executed. EEPROM (1K) Permanent data storage. 3 counters/timers I/O ports Digital I/O A/D Analog Inputs USART Serial comms SPI Full-duplex comms interface TWI (I2C) Half-duplex comms interface Watchdog Separate timer to reset the system when it hangs 15
AVR CPU Harvard Architecture Single Level Pipeline 32 8bit Registers 3 16bit address pointers 1 16 bit EEPROM pointer 64 I/O Addresses 16
More Info The Datasheet is the microcontroller s programmer best friend! 17
MCU Selection 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 resolution (8, 12, 16, 24 bit) Timer Units Development Tools Interrupt Lines Serial Comms (SPI, I2C, USB, IR, GbE) Product Family Peripheral Interface Controllers Floating Point units DMA controller Power consumption Cost (HW/SW tradeoff) Environmental Conditions 18
Famous MCU Families Intel 8051 Atmel AVR Microchip PIC Microchip dspic Freescale Zilog Z8 Cypress PSoC TI MSP430 Manufacturer sites provide selection tools: 19
ATMEL AVR Family Developed by two students of NTH in 1996. Alf (Egil Bogen) and Vegard (Wollan)'s RISC processor Easy and inexpensive development tools. tinyavr 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 20
AVR Development Boards Butterfly Demo Board (2003): Self-contained, batterypowered demonstration board with a variety of peripherals and ports. STK500 Starter Kit (2008): Power Supply, Sockets for Chips, RS232 interface to PC, In-System Serial Programming, Push buttons, connectors, etc 21
AVR Third Party Boards Arduino (2005) GPMPU40 Futurlec 2313 Board Olimexino Protostack kits 22
Entry Level Arduino Prototype Boards ARDUINO is a family of ATMEL MCU prototype boards: UNO ATMEGA328 LEONARDO ATMEGA32U4 101 Intel Curie Explora ATMEGA32U4 Micro ATMEGA32U4 Nano ATMEGA328 Mini ATMEGA328 Enhanced MEGA ZERO Cortex M0+ DUE M0 M0 PRO MEGA ADK MKR ZERO power FIO ATMEGA2560 ATSAMD21G18, 32-Bit ARM AT91SAM3X8E ATSAMD21G18, ARM Cortex-M0+ ATSAMD21G18, ARM Cortex-M0+ ATMEGA2560 SAMD21 Cortex-M0+ 32bit low ATMEGA328 23
Arduino Uno V3 24
Arduino Uno V3 Microcontroller Operating Voltage ATmega328 5V Input Voltage (recommended) 7-12V Input Voltage (limits) 6-20V Digital I/O Pins 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 25
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 26
Uno ATmega Pinout Correspondence 27
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 systems can run compilers or interpreters. Compilers Classically provided by the manufacturers. Several open source versions currently available. 28
Arduino IDE For windows, linux, mac, etc. C/C++ like language 29
Downloading Programs to MCU 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 30
Bootloaders When the MCU powers up, program execution starts at a predefined point in program memory. In development cycle, we may want to change the program very often. To facilitate this, a program called bootloader interfaces with the user to load the kernel. The bootloader is active 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 31
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 software 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 Communication Send debug messages via serial communication to a host device. Very simple and efficient but too slow to use in interrupts. LCD Display debug messages in a display attached 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 attached pins. 32