Lecture 6: Embedded Systems and Microcontrollers Bo Wang Division of Information & Computing Technology Hamad Bin Khalifa University bwang@hbku.edu.qa 1
What is Embedded System? Embedded System = Computers Inside a Product Device used to control, monitor, or assist the operation of equipment, machinery or plants _UK EEE. 2
Embedded System - Definition An embedded system is a specific-purpose system in which the computer is completely encapsulated by the device it controls. An embedded system performs pre-defined tasks, usually with very specific requirements. A combination of hardware and software, and perhaps additional mechanical or other parts, designed to perform a dedicated function. Mobile phones, Music players, Digital cameras, TVs are very common embedded systems in our life. 3
Embedded System - Characteristics Job Specific: designed for a specific task, has strong correlation with the application. e.g.: ECG can only used for cardio signal acquisition and processing. Complete redesign is needed if using the microcontroller for other purpose. Invisibility: it is a part of the whole system, people mostly will only focus on the system function, performance and usage instead of the embedded system inside it. Real-time: provide response within a limited period of time. strong: us ~ ms; typical: ms ~ s; weak: ~s Limited resources: the available hardware resources of embedded system is limited due to its low-cost, small form factor, low-power, etc. 4
Layered Architecture of Embedded System An embedded system is a tightly coupled Hardware(HW) + Software (SW) system to perform a dedicated system. 5
Embedded System - Application Areas 6
Embedded System - Importance Average car has about 50 MCUs in it. S-class has 63; a 1999 BMW 7- series has 65 [2009]. Average middle-class household has about 40 to 50 MCUs in it. MCU market size: ~$60 Billion by 2020 Potentially driven by Internet of Things Global Microcontroller Market, 2014-2024 (USD Billion) 7
Embedded System - History The first mass-produced embedded system was the guidance computer for the Minuteman missile in 1961, named as Autonetics D-17 guidance computer. The first modern embedded systems was Apollo Guidance Computer, developed by Charles Stark Draper at the MIT Instrumentation Laboratory. Used in real-time by astronaut pilots to collect and provide flight information. Automatically control all of the navigational functions of the Apollo spacecraft. Autonetics D-17 guidance computer from a Minuteman I missile Apollo Guidance Computer 8
Embedded System - Development 60~70 s o Manufacturing -In 1962, one ethylene plant in US achieved direct digital control (DDC) in the facilities. -In 1963, DEC released its DP-11 series of minicomputers. o Aeronautics -In 1963, Gemini3 adopted digital computer control for the first time -In 1968, Apollo IV, Saturn V 70~90 s o In 1973, Microprocessor was developed, e.g. 8085, Z80 single board computer. o In early 80 s, single-chip microcomputer (microcontroller) was developed, e.g. 8051. o In 1982, DSP was developed for high-speed real-time signal processing -X 10 ~ 50 faster than the CPUs in the same era. 9
Embedded System - Development After 90 s o More applications -Billions of microprocessors/microcontrollers sold per year, 95% are for embedded products. - Cars: > 50 embedded processors in a car The computing capability of the devices sold by Ford > IBM. - Airplane: 10 s of embedded systems, > 100 microcontrollers. o 4, 8, 16, 32, 64 bit processors used in different fields o More development references and tools 8b 64b 16b 32b 10
What is a microcontroller? Basically, a device which integrates a number of the components of a microprocessor system onto a single chip Microcontroller combines on the same chip: The CPU core Memory I/O Only need to be supplied power and clocking Micro suggests that the device is small, and controller tells you that the device might be used to control objects, processes, or events. Another term to describe a microcontroller is embedded controller, because the microcontroller and its support circuits are often built into, or embedded in, the devices they control A typical microcontroller topology using Harvard architecture 11
Microcontroller A Processor Instruction Set + memory + accelerators Memory Non-Volatile ROM, EPROM, EEPROM, Flash Volatile RAM (DRAM, SRAM) Interfaces H/W: Ports S/W: Device Driver Parallel, Serial, Analog, Time I/O Memory-mapped vs. I/O-instructions (I/Omapped) A typical microcontroller: the different sub units integrated onto the microcontroller chip. The heart of the microcontroller is the CPU core (traditionally based on an 8-bit microprocessor). 12
Microcontroller vs. Microprocessor Microcontroller CPU, RAM, ROM, I/O and timer are all on a single chip Fixed amount of on-chip ROM, RAM, I/O ports For applications in which cost, power and space are critical Single-purpose (control-oriented) Low processing power Low power consumption Bit-level operations Instruction sets focus on control and bit-level operations Typically 8/16/32 bit Microprocessor CPU is stand-alone, RAM, ROM, I/O, timer are separate Designer can decide on the amount of ROM, RAM and I/O ports. Expensive Versatility General-purpose High processing power High power consumption Instruction sets focus on processing-intensive operations Typically 32/64 bit 13
What is an Arduino? Open Source electronic prototyping platform based on flexible easy to use hardware and software. It consists of a circuit board, which can be programmed (referred to as a microcontroller) and a ready-made software called Arduino IDE (Integrated Development Environment), which is used to write and upload the computer code to the physical board. The key features are: Arduino boards are able to read analog or digital input signals from different sensors and turn it into an output such as activating a motor, turning LED on/off, connect to the cloud and many other actions. You can control your board functions by sending a set of instructions to the microcontroller on the board via Arduino IDE (referred to as uploading software). Unlike most previous programmable circuit boards, Arduino does not need an extra piece of hardware (called a programmer) in order to load a new code onto the board. You can simply use a USB cable. Additionally, the Arduino IDE uses a simplified version of C++, making it easier to learn to program. Finally, Arduino provides a standard form factor that breaks the functions of the micro-controller into a more accessible package. 14
Arduino Types Many different versions Number of input/output channels Form factor Processor Leonardo Due Micro LilyPad Esplora Uno 15
Arduino Uno Pinout Power pin, analog pin, digital pin, etc. 16
How to Start Get an Arduino (starter kit) Download the IDE Connect the device Configure the IDE to match with your device Connect the circuit Write the program Get frustrated/debug/get it to work Get excited and immediately start to improve it 17
Arduino IDE Download current compiler from: arduino.cc/en/main/software Arrogantly refers to itself as an IDE (Ha!). Run the software installer. Written in Java, it is fairly slow. 18
Arduino Program Development Based on C++ without 80% of the instructions. Easy to use the existing functions. A handful of new commands. Programs are called 'sketches'. Sketches need two functions: void setup( ) void loop( ) setup( ) runs first and once. loop( ) runs over and over, until power is lost or a new sketch is loaded. 19
Basic Functions pinmode(pin, mode) Designates the specified pin for input or output digitalwrite(pin, value) Sends a voltage level to the designated pin digitalread(pin) Reads the current voltage level from the designated pin analog versions of above analogread's range is 0 to 1023 serial commands print, println, write 20
Example: LED Blink void setup( ) { pinmode(13, OUTPUT); } //set pin 13 to be an output pin void loop( ) { digitalwrite(13, HIGH); //set pin 13 to be high delay(1000); //wait for 1000 ms digitalwrite(13, LOW); //set pin 13 to be low delay(1000); //wait for 1000 ms } 21
Example LED Dancing void setup( ) { pinmode(1, OUTPUT); pinmode(3, OUTPUT); pinmode(5, OUTPUT); pinmode(7, OUTPUT); } void loop( ) { digitalwrite(1, HIGH); delay (200); digitalwrite(1, LOW); digitalwrite(3, HIGH); delay (200); digitalwrite(3, LOW); digitalwrite(5, HIGH); delay (200); digitalwrite(5, LOW); } digitalwrite(7, HIGH); delay (200); digitalwrite(7, LOW); 22
Inputs Digital inputs will come to the Arduino as either on or off (HIGH or LOW, respectively). HIGH is 5VDC. LOW is 0VDC. Analog inputs will be converted in the Arduino to a range of numbers, based upon the electrical characteristics of the circuit. 0 to 1023 0.0049 V per digit (4.9 mv) Read time is 100 microseconds (10,000 readings per second) Used for most of the sensor applications (sensor outputs are analog) 23
Outputs Digital outputs of the Arduino can either be HIGH or LOW, respectively. HIGH is 5VDC. LOW is 0VDC. Some special pins (with a ~ mark) can generate analog outputs 0 to 255 0.0195 V per digit (19.5 mv step) Only pin 3, 5, 6, 9 can be configured as analog output. 24
Reference http://home.hit.no/~hansha/documents/lab/lab%20equipment/arduino/intr oduction%20to%20arduino.pdf https://www.tutorialspoint.com/arduino/arduino_tutorial.pdf https://playground.arduino.cc/main/resources 25