Embedded Systems & Microcontrollers Lecture Slides PDF
Document Details
Uploaded by WellPositionedDialogue1847
University of Glasgow Singapore
2025
Tags
Summary
These lecture slides from the University of Glasgow in Singapore introduce embedded systems and microcontrollers. The slides cover fundamental concepts such as the ARM Cortex M3 microcontroller, Arduino programming, and different types of memory and computer architecture. The document appears to be aimed at undergraduate-level students.
Full Transcript
Embedded Systems and Introduction to Microcontrollers Rev.2025 | 13 Introduction Survey embedded electronic systems and the types of microelectronics on which they are based Examine microcontrollers, concentrating on a small, modern...
Embedded Systems and Introduction to Microcontrollers Rev.2025 | 13 Introduction Survey embedded electronic systems and the types of microelectronics on which they are based Examine microcontrollers, concentrating on a small, modern device — the ARM Cortex M3 microcontroller Explore operation of a microcontroller on two levels: capabilities of the microcontroller itself and how they can be programmed at a low level (assembly language — more or less the instructions understood by the chip itself) experiments using the Arduino Due, which hides some of the nitty-gritty details from the users This is not a full course in hardware or software engineering we want to give you a feel for what modern microelectronics can do Rev.2025 | 14 What is an embedded (electronic) system? Almost every electrical product now contains an electronic system to control its operation. It is called an embedded (electronic) system because it improves the function of the product in some way, but is not itself the primary purpose of the product. For example, almost every washing machine is now controlled electronically by a microcontroller (MCU or µC) — a ‘computer on a chip’. This is an embedded system because the purpose of the product is to wash your clothes, not computation. In contrast, a PC is not an embedded system because its main task is computation of some sort. (Actually, it contains embedded systems in the keyboard, disk drives and so on.) Nowadays the world is full of embedded systems, from small scale to large scale, and these can be implemented in many ways. Rev.2025 | 15 Approach 1 — discrete components In the past, embedded systems would have been constructed from discrete components (transistors etc) or small-scale integrated circuits such as ‘7400’ logic circuit. This approach is now largely obsolete. For example, suppose that you needed a timer (in a washing machine, for example, but they are very common). In the past this might have been made using a famous integrated circuit (‘chip’) called the 555. It comes in an 8-pin package and costs about $1 but needs several external components (resistors and capacitors). Nowadays you can buy a complete microcontroller in an 8-pin package for less than $2. This is more than the 555 but it does a better job and needs no external components. Moreover, most microcontrollers include timers that run automatically in the background, leaving the computer free to carry out other tasks! Rev.2025 | 16 Approach 2 — buy a computer At the other end of the scale, you could buy a computer ‘off the shelf’ to do the job. This is commonly done for cash machines (ATMs), for example. Advantages standard hardware, no development needed operating system provides all basic services needed contrast with microcontrollers, where you must do everything wide range of application software available Disadvantages large and uses lots of power unreliable operating system (e.g. Windows), prone to crashes couldn’t use in critical applications not basically a ‘real time system’ (although versions are available) We’ll be looking at much smaller-scale systems Rev.2025 | 17 Approach 3 — application-specific integrated circuits (ASIC) Suppose that we can fit most of the system into a single integrated circuit (IC or chip), rather than needing a printed circuit board (PCB), carrying lots of ICs as in a PC. The IC will be a modern device with millions of transistors — very large scale integration (VLSI). There are still several approaches. For very large scale production, or where the highest performance is needed, application-specific integrated circuits (ASICs) are used. These are very expensive to design. Used in mobile phones, which contain amazingly powerful electronics. Can cost over $1M in up-front costs! Rev.2025 | 18 Approach 4 — configurable hardware A less expensive approach is to use general-purpose hardware that can be ‘wired up’ to perform a given function. Typically these contain a large array of logic gates and flip-flops, whose connections can be programmed to give the desired operation. Many types of integrated circuit available: programmable logic devices (PLDs) field-programmable gate arrays (FPGAs) They are designed by specifying the desired function using a type of pro- gramming language, a ‘hardware description’ language: VHDL or Verilog. Computer-aided design software then works out the connections needed inside the chip. There is no clear-cut distinction between this approach and microcontrollers (next). A FPGA can be programmed to act as a microcontroller. Rev.2025 | 19 Approach 5 — microcontrollers This approach uses a device with (nearly) fixed hardware but whose operation can be programmed in a versatile way — microcontrollers (µCs or MCUs). A microcontroller is essentially a ‘computer on a chip’. Modern devices incorporate almost all the functions that needed peripherals in the past. We shall concentrate on microcontrollers because they are versatile, cheap, widely used and fairly easy to understand. More specialized ICs are sometimes used, notably digital signal processors (DSP), but these can be built into a microcontroller or designed into a FPGA. Rev.2025 | 20 A small embedded system — remote control crystal (clock) infra-red light- emitting diode (LED) It is nearly empty inside! printed circuit board (PCB) under front cover (pads act as front cover buttons) rear view Rev.2025 | 21 Compare microcontroller and discrete logic Simulation for dice (first year electronics) JK flip- flops PIC12C 508 µC The board based on the µC could be much smaller and doesn’t really need the power switch, because the current drawn during ‘sleep’ is so low! Rev.2025 | 22 Compare microprocessor and microcontroller Microcontroller (MC68HC908QY4) on top of (old) microprocessor (Pentium II) Rev.2025 | 23 More modern chips microprocessor core i7 Cortex M3 processor runs at 100W – needs heatsink & runs at ~ 100mW full power, fans no heatsinks required Rev.2025 | 24 Microcontrollers Take a general view of functions provided by a microcontroller Examine memory, which is central to any computer system: how it is arranged how we communicate with memory types of memory (RAM and ROM) different architectures Operating system in a typical small microcontroller there isn’t one! Programming a microcontroller different languages and approaches Approach used here: C Rev.2025 | 25 Product with a microcontroller: washing machine What does the microcontroller need to handle? Inputs: 23 buttons on control panel (on/off — digital) water level (digital?) water temperature (continuous — analog) Outputs: display on control panel heater, water valves,… (on/off — digital) motor (may appear to be analog, but usually digital using ‘pulse width modulation’) Also needs: timer to control washing programme memory for program and variables (state of washing programme), clock generator, logic to start machine up correctly… Rev.2025 | 26 What is inside a microcontroller? (1) What do we need inside a microcontroller? Arithmetic logic unit (ALU) - perform arithmetic and other manipulations on data Memory for program - must be non-volatile: retain program even while power is off - read-only memory (ROM) Memory for data - may be volatile: doesn’t matter if contents are lost while power is off - random-access memory (RAM) Communication with outside world - input and output ‘ports’ - may need to handle both digital and analog signals These need to be connected so that they operate together Rev.2025 | 27 What is inside a microcontroller? (2) Core features Program The components memory Instruction are joined together (flash ROM) decoder by buses. They are shown as single lines but are Arithmetic Data actually sets of 8 or logic unit, memory ALU more wires. (RAM) (‘cruncher’) Details later. Input/output The clock keeps all Clock ports parts synchronized. address bus data bus Rev.2025 | 28 What is inside a microcontroller? (3) Core features ‘Peripherals’ Program The components Instruction Timers memory are joined together (flash ROM) decoder by buses. Watchdog Theytimer are (WDT) shown as single lines but are Arithmetic Data Interrupts actually sets of 8 or memory logic unit, ALU more wires. (RAM) (‘cruncher’) Analog–digital Details later. converter Control of reset Input/output The and clockstartup keeps all ports Clock parts Interfaces synchronized. address bus data bus (serial, USB) These are examples of the ‘peripherals’ Data EEPROM that may be available in a microcontroller. Rev.2025 | 29 Memory — the heart of a computer Address Memory in a computer is just like a (tall) 0 stack of pigeonholes. 1 There may be several stacks for different 2 types of memory. 3 Each pigeonhole is identified by its 4 address, which is a serial number 5 starting from 0 6 The address is said to point to a memory 7 location (register). 8 When we communicate with memory, we 9 need to handle both the data and the 10 address. 11 … Rev.2025 | 30 Communication with memory Data is transferred between memory and the rest of the system using buses. These are shared sets of wires that join the components, something like a multi-lane highway. Several parallel sets of wires are needed: address bus, carries address (serial number) of pigeonhole data bus, carries byte either from the memory (read operation) or to the memory (write operation) control lines are also needed to synchronize timing, select read/write, ensure that only one device tries to use the bus at once, … ignore! In a PC the memory and … but in a µC devices are external (on the everything is usually motherboard) so the buses central processing unit (CPU) within a single come outside the processor… integrated circuit address bus other memory devices data bus Rev.2025 | 31 Types of memory (1) Microcontrollers have two types of memory: volatile — contents lost when power is removed, commonly known as RAM — random-access memory. Used for variables/data. non-volatile — contents retained even when power is removed, commonly known as ROM — read-only memory. Used for program. Unfortunately the common names are obsolete and misleading: access to both RAM and ROM is equally random most modern ROM is of a type called flash, which can be written and erased (although the process is much slower than with RAM) ROM used to live up to its name — it was ‘written’ when the chip was fabricated and could never be changed again. Flash memory (or EEPROM — electrically erasable, programmable ROM) can be erased and rewritten electrically — much more convenient, and enables upgrades to be distributed to the end user. Rev.2025 | 32 Types of memory (2) Almost all memory in a PC is RAM. Each program must be read into RAM from non-volatile memory (usually disk) whenever it is needed. Similarly the operating system must be loaded into RAM whenever the system boots. In contrast, microcontrollers execute only one program, which can therefore be stored in ROM and is available instantly. Rev.2025 | 33 Harvard and Princeton architectures The two types of memory that we have just seen, non-volatile (ROM for program) volatile (RAM for variables) can be treated in two general ways: two completely separate memory systems: each has its own data and address bus — Harvard architecture, used in most microcontrollers single memory system — Princeton architecture, (almost) universal in general-purpose computers, but employed in some microcontrollers. Look at both briefly, as both are used in microcontrollers. Rev.2025 | 34 Harvard architecture More efficient use of memory: program and data can be accessed simultaneously width of address and data buses can be optimized for each memory Most microcontrollers use this architecture, including the PIC families from Arizona Microchip and the Cortex-M3 processors developed by ARM. we shall explore the SAM3X8 implementation of the Cortex-M3 also has reduced instruction set (RISC) — see later Rev.2025 | 35 Princeton architecture More versatile architecture, almost universal in general-purpose computers: several bus cycles are needed to get a complete instruction, including the data needed, so intrinsically slower like a stack of different colour pigeonholes: some locations are ROM and some are RAM. Needs care! Study the memory map carefully. Older Motorola microcontrollers use this architecture: For example Nitron (68HC908QT/Y) range they used a complex instruction set (CISC) — see later Rev.2025 | 36 Operating system — desktop computer When you buy a desktop computer, it comes with an ‘operating system’ (linux, MacOS, Windows…). The original purpose of many operating systems was to keep track of files on disks (DOS = disk operating system). Modern operating systems provide a vast range of services to the applications that run on them. Suppose that you press the key ‘a’ on a keyboard. Then (in brief!): the operating system reads a byte from the keyboard (itself an embedded system!) it informs the application that an ‘a’ has been pressed the application requests that an ‘a’ be drawn on the screen in a particular font at a given location the operating system retrieves the pattern of dots (pixels) needed, and draws them on the screen to form the character Rev.2025 | 37 Operating system — small microcontroller You are on your own! A small microcontroller usually has no operating system at all. The development software may help you, but basically you must do everything yourself. For example, you have to: configure the microcontroller when it starts up (which pins are inputs and outputs, for example) make sure that your program starts at the right place keep track of your variables and ensure that you don’t run out of space react to inputs when they occur keep track of different tasks if you have more than one running (as is usually the case) The development of software is a heavy, one-off cost. Rev.2025 | 38 Programming a microcontroller (1) There are several ways in which the program for a microcontroller can be written, depending on the size of the project and how critical the performance may be. 1. Assembly language. This is no more than the instructions understood by the µC but written in a form that is easier for humans to understand. We will give some examples because it shows precisely what the µC does. This is useful for small projects but rapidly gets incomprehensible. 2. C. This is the language of choice for most projects on small µCs. It is close enough to the hardware to be efficient, but is much easier to understand than assembly language. 3. Java/C++. These are ‘object-oriented’ languages and are increasingly used for major projects. Many mobile phones contain interpreters for Java, for example (so that they can run games!). These need much larger µCs than we will discuss. Rev.2025 | 39 Programming a microcontroller (2) 4. Arduino C. This is what we will be using in this course. Essentially it is the standard C language, but there are some additions. The great advantage of this approach is that C is a standard language, found on almost all computers. So learning to program in C is very much a transferable skill. Arduino make the process easier by supplying many ‘libraries’ which make common tasks easy, for instance communicating via USB, Ethernet or Wi-Fi, or saving data to an SD card. For instance, connecting to a Wi-Fi network is accomplished using the command status = WiFi.begin(network_name, password); (Of course, you also need to have the correct hardware!) You will also find that Arduino supply many examples, both in their software and on their website. Rev.2025 | 40 Summary Looked at major systems to be found inside a microcontroller. ALU, memory, communication with outside world may be many ‘peripherals’ on-chip to simplify overall system Memory can be visualized as a stack of pigeonholes with addresses given by serial numbers non-volatile ROM for program and volatile RAM for data separate (Harvard) or common (Princeton) address space most µCs, including the PIC use Harvard model although Motorola uses the Princeton model There is usually no operating system! you must write everything yourself It is important, but particularly difficult, to develop a good interface for users — a major discipline within computer science. Rev.2025 | 41