Phillip Stanley-Marbell
Foundations of
Embedded Systems
Physical Constraints, Sensor Uncertainty, Error Propagation,
Low-Level C on RISC-V, and Open-Source FPGA Tools
Draft Version of Michaelmas 2020
0
Preface
Figure 1: Embedded com-
puting systems interact
with the physical world
through sensors, actuators,
and displays.
Theory is when you know something, but it doesn’t work.
Practice is when something works, but you don’t know why.
Some people combine theory and practice:
Nothing works and they don’t know why.
—Source unknown.
Table 1: Concepts.
Concept
Embedded system § 0.1
Embedded processor § 0.1
Internet of Things (IoT) § 0.1
Cyberphysical system § 0.1
SCADA § 0.1
PLC § 0.1
IEC61131-3 § 0.1
Energy-efficiency § 0.2.1
Measurement uncertainty § 0.2.2
At the end of this course, you will be able to design, implement,
and analytically evaluate standalone and internetworked embedded systems.
These systems may be made up of microcontrollers, sensors, and communi-
cation interfaces that solve a given engineering problem. Typically, you will
require the systems you design to be energy-efficient, time-efficient, and to
deal with uncertainty in measurement data from sensors. The principles and
techniques introduced in this course will equip you with the skills you need
to design and implement the hardware and firmware for embedded comput-
ing platforms
1
from the ground up. This course is designed specifically for the
1
Of the form of the BBC
micro:bit, Arduino, or
Raspberry Pi.
2 phillip stanley-marbell
context of the curriculum of the Department of Engineering at the University
of Cambridge
2
.
2
As you might have no-
ticed, the University’s coat
of arms has an SOT353
integrated circuit package
at its center! Not quite...
0.0.1 Learning outcomes pre-assessment
Complete the following
quiz to evaluate your prior knowledge of the material
for this course.
0.0.2 Things to think about
Complete the following
thinking exercise to stimulate your thoughts about
the contents of this chapter before proceeding with the material.
0.0.3 Things to look out for
Things people sometimes get confused by in the material in this chapter and
in the overall course include:
1. Why we only discuss the buzzword “Internet of Things” (IoT) in the first
lecture and avoid it judiciously in the remainder of the course.
2. That hardware platforms such as Arduino and the Raspberry Pi are not
microcontrollers but are rather embedded systems (which contain microcon-
trollers).
3. Why experienced engineers usually refer to configuring an FPGA and pro-
gramming a microcontroller and not the other way round (and a unit of
software is a program
3
).
3
A technical term, whose
spelling does not change
across the many variants of
the English language.
4. Why many mature engineers refer to the process of writing programs as
programming and not coding.
0.1 Embedded Systems
What is an embedded system? What is an embedded processor? What is the
difference between a microcontroller and an embedded processor? What is a
sensor? What is an internet of things (IoT) device or platfor m and how is that
different from an embedded system or a cyber-physical system? How are all of
these related to SCADA systems, PLCs, and IEC 61131-3?
The content in this course is relevant to these questions: Computing sys-
tems that interact with the physical world through sensors, interact with hu-
mans through displays, and communicate with each other through wired or
wireless I/O interfaces. Because they interact with the physical world, these
computing systems are typically embedded in objects in the physical world
or deployed outside a typical desktop computing environment. For example,
foundations of embedded systems 3
many so-called white goods such as washing machines or microwave ovens
contain one or more microcontrollers and sensors to control their operation.
Thus, for at least the last decade or more, almost anything that plugged into
a mains socket or which contained a battery also contained one or more
microcontrollers and sensors. For this reason, these computing systems are
traditionally referred to as embedded systems.
Other examples of embedded systems range from the FitBit family of fit-
ness trackers, to the flight controller for the Apollo moon mission, to the ap-
proximately two dozen sensors in Rolls Royce aircraft engine health manage-
ment (EHM) systems
4
, to car engine control units (ECUs), to programmable
4
These monitor and an-
alyze several engine pa-
rameters and transmit a
short (3 kB) summary to
a central analysis center
(in Derby, UK) using ei-
ther a VHF or satellite
data communication link.
For more information,
see
Rolls-Royce Engine
Health Management (link).
logic controllers (PLCs) in the supervisory control and data acquisition (SCADA)
systems of factories, power plants, and other industrial applications, and so
on.
Unlike traditional computing systems, embedded systems are typically for
a fixed function and deployed (embedded) in hostile or energy-constrained
environments. An embedded system typically consists of sensor integrated
circuits such as temperature sensors or MEMS inertial sensors such as ac-
celerometers or may have inputs as simple as circuits for detecting the state
of a switch. The outputs of sensors feed into a computing element such as
a microprocessor, microcontroller, or digital signal processor (DSP) via an
analog to digital converter (ADC). A typical system then stores the results of
the processing of sensor data into a local log or memory, communicates the
data to a data collection point, or uses the data to determine how to drive an
actuator or a display.
Because embedded computing systems bridge the world of computation
with the physical world, they are sometimes referred to as cyber-physical sys-
tems. The contraction of the words cyber (of or relating to computers) and
physical in “cyberphysical”, as well as the word embedded imply these com-
putation and sensing systems are part of physical objects (or, colloquially,
things). Traditionally, embedded systems were standalone devices, typically
operating autonomously without human intervention and with little com-
munication with traditional computer networks. In the last decade, it has
become economically feasible to network embedded systems with each other
and with the Internet, leading to the term the Internet of Things (IoT). While
embedded systems are by no means new, what has fundamentally changed
in recent years is the availability of cheap sensors
5
, the interaction between
5
As an example, at the
time of writing the
MMA8451 MEMS ac-
celerometer costs as little
as 0.952 GBP when pur-
chased in quantity from a
distributor such as Mouser.
computation and sensors, the processing of data from those sensors, and
the ability to connect them to a global network. The economies of scale made
possible by the integration of sensors such as accelerometers, gyroscopes, and
pressure sensors into smartphones has made these dramatic cost reductions
possible, benefitting all systems which use these sensors.
4 phillip stanley-marbell
We can obtain a partly-quantitative analysis of the rise in popularity of
connecting embedded or cyber-physical systems to the Internet, by study-
ing the trend in popularity of search engine queries related to these systems.
Figures
2 and 3 show an analysis of the popularity of search terms by topic
for the topics “Embedded system” and “Internet of Things” on the Google
search engine, normalized to a scale of 1 to 100. For comparison with an-
other computing system topic of great recent interest, Figure
4 compares the
popularity of the two topics to that for “Deep learning”.
Figure 2: Interest over time
represented by Google
searches for the topic
“embedded system”
(normalized to 100).
Source: Google trends.
Figure 3: Interest over
time as represented by
searches on the Google
search engine for the topic
“Internet of Things”.
Source: Google trends.
Figure 4: Interest over time
represented by Google
searches for topics “In-
ternet of Things” (red/top
in 2017), “embedded
system” (blue/middle in
2017), and “deep learning”
(yellow/bottom in 2017).
Source: Google trends.
The data in Figures
2 through 4 show that while the term embedded system
was dominant in 2005 compared to the term Internet of Things, by March 2015
the two terms were searched for in equal amounts. By August 2017, the term
Internet of Things is about twice as popular as a search term, compared to
either embedded system or deep learning. These trends do not indicate that one
field is dying out and another is being born: Internet-of-Things platforms are
foundations of embedded systems 5
embedded or cyber-physical systems that are connected to the Internet, and
the term “Internet of Things” is increasingly being used as a broad synonym
for all embedded or cyber-physical systems. But the trends provide some
insight into the changing terminology used by industry, academia, and the
general public to refer to the topic of this course: computing systems that
interact with the physical world through sensors and with humans through
actuators and displays.
      

-



#    
Figure 5: Improvements in
integration density based
on publications from the
IEEE ISSCC conference
and the JSSC journal.
    





 
··
Figure 6: Improvement in
efficiency of integrated
circuits (energy needed
per logic transition /
transistors per Hz).
What underlying physical trends have made it economically ever cheaper
to embed sensing and computation in “things” and to network those objects
together? Figure
5 shows the reported transistor integration densities and
energy usage, per transistor, per clock cycle, from research and commercial
publications on integrated circuit designs, from the last three decades.
6
The
6
Stanley-Marbell, Caparros
Cabezas, and Luijten
2011.
figure shows how transistor integration density (Figure 5) and energy effi-
ciency (Figure
6) have improved by about 100-fold in the last decade alone.
Despite these recent advances in semiconductor device technology and
the equally important advances in communication technologies, computer
architectures, programming languages, compiler tools, and operating sys-
tems for embedded systems, embedded systems today are far from reaching
their full potential: Computation and sensing can in principle be embedded
into everything from the most mundane items such as nails or bolts, to all the
parts of household items such as chairs, to items of clothing such as shoes
or helmets. All of these items could be constructed out of materials with
basic sensing and computation embedded, to process the data from sensors.
The benefits of such per vasive embedding of computation and sensing could
range from safety (is a child’s bicycle helmet no longer safe to use because
it has suffered damage from impact by being dropped?) to new applica-
tions (data gathered from sensors in clothing could provide quantitative in-
put for optimizing fibers for more comfortable clothing). There are however
many significant challenges to be addressed before these future applications
of embedded systems would be possible: energy efficiency, dealing with the
inherent uncertainty of measurements of signals from the physical world,
dealing with the potentially large amounts of data that can be generated by
indiscriminate sampling from sensors, and dealing with security of sensing
systems and the privacy of the individuals who use them. This course will
cover some of these challenges.
0.2 Outline of the Course
This course is about the foundational insights and theoretical underpin-
nings and the practical engineering techniques for designing, implement-
ing, and evaluating efficient computing systems that interact with the physi-
cal world and with humans.
6 phillip stanley-marbell
Throughout the course, you will repeatedly be challenged to create new
designs that solve a given problem. There will often be many ways to achieve
a design goal and you will develop the practical knowhow to choose between
design options made possible by the underlying fundamentals and to turn
design choices into implementations. The course will provide the necessary
theoretical underpinning so that you not only know why a system works,
but will have the depth of understanding to create fundamentally new and
novel solutions to engineering problems. With this theoretical underpinning,
you will also be well-placed to develop new theoretical solutions to engi-
neering problems that go beyond what the implementation technologies of
today permit. And you will develop both the theoretical understanding and
practical engineering skills to evaluate these systems in terms of their time
efficiency (performance), in terms of their energy efficiency (battery life), and
in terms of their error efficiency (noise, errors, and uncertainty in the outputs
provided). These are essential skills that will help you get an edge over your
peers who might either only have knowledge of theoretical foundations or
knowledge of only practical implementation tactics.
0.2.1 The importance of energy efficiency
Computing systems that interact with the physical world through sensors
and actuators and which may communicate with each other span a broad
spectrum, from SCADA systems in industrial automation which control power
plants and factories, to wearable health monitoring platforms. In the case of
embedded systems used in industrial automation, the computing systems
are often powered off the electrical grid or at least can be, and the primary
concerns are reliability and safety of the systems (e.g., nuclear reactors) un-
der the control of the embedded computation. In the case of wearable health
monitoring, the computing and sensing systems are invariably powered by
batteries and the primary concerns are energy usage and battery life. Al-
though many of the topics in this course will apply to both on-grid and
off-grid/battery-powered systems, our focus will be primarily on battery-
powered or energy-scavenged systems where average power and overall en-
ergy usage is a severe constraint.
0.2.2 The importance of uncertainty in measurement
Because we will focus very heavily on the interaction of computing systems
with the physical world, we will spend some time developing a deeper un-
derstanding of measurements: In the same way that measurement in a lab-
oratory environment requires careful attention to noise, so also does mea-
surement in embedded systems. We will study the concept of measurement
uncertainty from the perspective of embedded sensing systems, we will study
foundations of embedded systems 7
the sources of uncertainty in embedded systems, and we will study how un-
certainty and noise interplay with energy. Measurement uncertainty is also
important for a surprising reason: The recent dramatic reductions in the cost
of sensors such as accelerometers and gyroscopes has been driven primarily
by the use of these sensors in mobile phones. But these lower costs achieved
through economies of scale also mean that low-cost sensors are only as accu-
rate and as reliable or durable as needed in mobile phone applications.
0.3 Course-Level Intended Learning Outcomes
The course will introduce you to the principles underlying sensor operation,
signal acquisition, the role of measurement uncertainty and noise, common
sensor communication interfaces, and how they interact with traditional em-
bedded microcontrollers such as the ARM Cortex-M0 family. The course will
link these concepts in the signal acquisition and processing chain to a study
of output interfaces in embedded systems. This exploration of output sys-
tems will be built on a study of the principles of operation of OLED displays
and how the flexibility of the human visual system enables interesting circuit-
and algorithm-level techniques to reduce display power dissipation. At the
end of the course, you should be able to:
1. Define the role of uncertainty in measurements of physical signals and
quantify measurement uncertainty for a given sensing system.
2. Evaluate energy use in an embedded system using in-system current
monitoring circuits such as the INA219 integrated circuit.
3. Define the role of noise in both measurements and displays and identify
appropriate metrics to use in quantifying noise for a given design.
4. Design sensor communication subsystems and the required electrical
circuit support between a collection of I2C- or SPI-interfaced sensor in-
tegrated circuits and an ARM Cortex-M0 microcontroller.
5. Numerically quantify measurement uncertainty and noise in outputs
given a system design.
6. Recall and explain properties of OLED displays and the interaction be-
tween displays and the human visual system.
7. Design modifications to sensing, communication, and display systems
to improve their energy efficiency.
8. Design the logical organization and required firmware for new systems
built around an ARM Cortex-M0 microcontroller and sensors or displays
connected via I2C and SPI communication interfaces.
8 phillip stanley-marbell
0.4 Structure of this Course
The material in the main body of this course is split into 9 units. Figure
7
shows the order of dependencies between the parts of the course. Chapter 1,
Chapter 2, Chapter 4, Chapter 9, Chapter 11, and Chapter 15 form the core of
the course and are expected to be completed in sequence. Chapter
3, Chapter
7, Chapter 10, Chapter 12, and Chapter 13 can be inserted into the sequence of
topics in any order but form part of the core topics. Several recorded videos
for the main topics as well as supplementary standalone fascicles, available
online at
https://f-of-e.org and complement the main material in the course.
The course provides a substantial index. You may find it useful to refer to
the index when you encounter unfamiliar terms.
Figure 7: Dependencies
between chapters in this
course.
0.5 Exploring Further Beyond this Course
There are many ways to look at embedded systems, ranging from a pri-
marily theoretical emphasis (e.g., with a focus on models of computation,
synchronous dataflow, and so on) or a purely applied emphasis (e.g., pro-
gramming embedded device-, mobile-, and server-side software). Each of
these approaches has merits. The emphasis in this course is to give you a
practical grounding of the topics you will need to address in the real world,
and to underpin that practical grounding with both foundational theory and
links to academic research.
This course was designed from the ground up to fill a need in the cur-
riculum in the Department of Engineering at the University of Cambridge. If
you are interested in other ways to introduce embedded systems, you might
be interested in the course
EECS 149 at Berkeley, the course EE107 at Stan-
ford, and the course 6.S08 at MIT. Other information you will find useful are
the textbooks which I have requested to be made available at the Cambridge
University Engineering Department (CUED) Engineering Library:
1. Introduction to Embedded Systems, A Cyber-Physical Systems Approach, ISBN:
978-0262533812. Available
online.
2. An Introduction to Uncertainty in Measurement, ISBN: 978-0521605793.
foundations of embedded systems 9
3. Linkers and Loaders, ISBN: 978-1558604964.
4. The Circuit Designers Companion, 3rd Edition, ISBN: 978-0080971384.
5. The Practice of Programming, ISBN: 978-0201615869.
6. Expert C Programming, ISBN: 978-0131774292.
7. C: A Reference Manual (5th Edition), ISBN: 978-0130895929.
8. Bluetooth Low Energy: The Developers Handbook, ISBN: 978-0132888363.
9. Programming Embedded Systems: With C and GNU Development Tools, 2nd
Edition, ISBN: 978-0596009830.
10. Embedded Systems Dictionary, ISBN: 978-1578201204.
11. The Art of Designing Embedded Systems, Second Edition, ISBN: 978-0750686440.
12. The Art of Electronics, ISBN: 978-0521809269.
13. Color Science: Concepts and Methods, Quantitative Data and Formulae, ISBN:
978-0471399186.
10 phillip stanley-marbell
0.6 The Muddiest Point
Think about the following two questions and submit your responses through
this
link.
1. What was least clear to you in this chapter? (You can simply list the section
numbers or write a few words.)
2. What was most clear to you in this chapter? (You can simply list the
section numbers or write a few words.)