Lecture 2:
Introduction to Microcontrollers
EEC1: Introduction to Electrical
and Computer Engineering
Instructor: Dr. Hooman Rashtian
What is a Microcontroller?
A) The CPU for a Desktop/Laptop Computer
C) An Arduino
B) A Small Computer
D) A Raspberry Pie
E) None of the above
2
Analog Signals
➢ An electric signal is a waveform that carries information.
➢ Signals that occur in nature can assume all values in a given
range.
➢ Called “analog”, such signals include voice, video and music
waveforms.
➢ Analog signals are difficult to process due to sensitivities to
“noise” and “distortion”.
Figure from Fundamentals of Microelectronics, B. Razavi, Wiley, 2nd edition, 2014
https://www.compadre.org/osp/pwa/soundanalyzer/
3
Digital Signals
➢ By contrast, a digital signal assumes only a finite number of values at
certain points at time.
➢ A “binary” waveform, remains at only one of two levels at each period.
➢ So long as the two voltages corresponding to ONEs and ZEROs differ
sufficiently, digital circuits sensing such a signal process it correctly
even if noise and distortion create some corruption.
➢ We therefore consider digital signals more robust than their analog
counterparts.
➢ The storage of binary signals (digital memory) is also much simpler.
Figure from Fundamentals of Microelectronics, B. Razavi, Wiley, 2nd edition, 2014 4
Analog and Digital Signal Processing
➢ The forgoing observations favor processing of signals in the digital
domain, suggesting that inherently analog information must be
converted to digital form as early as possible.
➢ Indeed complex systems such as digital cameras, camcorders, and
compact disk (CD)/digital audio recorders, mobile phones, etc. perform
some analog processing, “analog-to-digital conversion”, and digital
processing.
5
Example: Light-Meter System
Op-amp Difference
Amplifier Wheatstone Bridge
Passive
Low-pass
Filter
Light-Dependent
Resistor (LDR)
Teensy 3.2 Board 7-Segment
(Arduino) Display
6
Binary Numbers
➢ We are most familiar with the decimal (base
10) number system. For example, Volts
(1984 )10 = 1103 + 9 102 + 8 101 + 4 100
➢ Digital systems use the binary number system
because the two voltage levels can be
represented as the two digits 0 and 1.
➢ Signals in digital electronics have two distinct
voltage levels. For example, a system may
define 0 V as logic 0 and +5 V as logic 1.
➢ Thus, we can use binary (base 2) numbers:
(1001)2 = 1 23 + 0 22 + 0 21 + 1 20 = ( 9 )10
7
Bit, Byte and Word
➢ Any digital line can only assume two
values: “0” and “1”.
➢ The exact voltages which represent the
two logic states can be 0V and 5V.
➢ Several digital lines (bits) are used to
represent a range of numbers.
➢ In the same way that base-10 numbers
can encode 𝟏𝟎𝑵 different values with N
discrete numbers in the range of 0-9,
𝟐𝑵 different values can be encoded by
N binary bits.
➢ Eight such bits make up a byte (e.g.,
the value 01101111 is a byte).
➢ Two or more bytes (16 or more bits)
are a word.
➢ Letters and other typographics can be
represented using the 7-bit ASCII
codes.
Tables from “Circuits”, F. Ulaby, M. Maharbiz, and C. Furse, National Technology & Science Press, 2015. 8
Analog-to-Digital Conversion
➢ The analog voltage can be
converted to digital using an
ADC to sample it, find the
closest step that matches the
signal, and convert the value of
that step to a digital value.
➢ The number of steps
(controlled by the number of
bits in ADC) controls the
precision of ADC.
➢ The difference between the
actual analog signal and the
level that can be represented
with the ADC is called the
quantization error.
9
A Microprocessor is:
➢ A Circuit (chip) used in computers,
tablets, phones, etc.
➢ A digital system
▪ Perform bitwise calculations using
“Binary Logic”
➢ Generally designed to maximize
computational capability
▪ Limited on-chip memory
➢ Memory is “mostly” external
➢ Require external commands to set states
and run programs
➢ Not typically Energy Efficient
➢ Part of a large-scale circuit
➢ Highly flexible
By Lambtron - Own work, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=37716438
10
A Microcontroller is:
➢ Used in small-scale systems
➢ Generally, provide a specific
function
➢ Low power microprocessor
➢ Memory is “mostly” internal
➢ Programs are stored on-device
➢ Boot-up is fast, and programs run
at start-up
➢ Part of smaller-circuit
➢ Less flexibility
11
The March of Arduino
➢ Have you used an Arduino before?
➢ Have you heard of one?
➢ It started off as a project to give artists access to
embedded microprocessors for interactive design
projects.
➢ Originally based around the 8-bit Atmel AVR
microcontroller line
➢ An Arduino Board is a development board for a
microcontroller. Includes:
▪ analog to digital converters (ADC)
▪ General Purpose Input/Output (GPIO)
▪ Memory
▪ A way to interface to a Computer
➢ The real power of Arduino isn’t really in the
hardware, but the software — the Arduino IDE.
➢ Once a program is loaded, it will run
automatically whenever the board is powered
12
Alternatives to Arduino
➢ Texas Instruments Launchpads:
▪ Arduino might be quite simple to program and prototype because of
all the available APIs, but when it comes to better control of hardware,
MSP432 has the advantage.
▪ We can not only access the address space of MSP432 but also, we can
change a values of different registers which will appropriately affect
different settings.
▪ For the beginning stages Arduino can be used, but when performance
becomes critical, TI MSP432 works much better because of the control
over hardware.
13
Raspberry Pie vs Microcontroller
➢ The Raspberry Pi is a Single Board
Computer (SBC). This means that
the board is a fully functional
computer with its own dedicated
processor, memory, and can run
an operating system (runs on
Linux).
➢ Microcontrollers are not as
powerful as SBCs, but they can be
great for quick setups.
Microcontrollers excel when
controlling small devices (like
LEDs, motors, several different
types of sensors) but cannot run a
full operating system. The
microcontrollers run one program
at a time.
14
LaunchPad works with Energia
➢ Download and Install
Energia
▪ Can have problems with
either Mac or Linux
➢ Works well with Arduino
programming
15
Pin Map
16
LEDs and Switches
17
Digital to Analog Conversion
18
Digital to Analog Conversion
➢ Launchpad Does not have any Direct DAC
Capabilities
➢ Can use LEDs
▪ Produce Light we can see
Digital Signal: Analog Voltage:
01101101 4.2353 V
By Robert F Coughlin - Text Book: Operational Amplifiers, Attribution, https://commons.wikimedia.org/w/index.php?curid=16885785 19
Digital to Analog Conversion:
Pulse Width Modulation (PWM)
Square Wave Digital Signal
How to use this scheme?
Assume 8 bits on digital bus, and a 0-
5V output. Range.
1 Cycle Average Value = 2.5V
28 = 256 (0 to 255)
50% Duty Cycle 5V/ 28 = 0.0195 V
Set the duty cycle based on the
nearest average value…
1 Cycle Average Value = 3.75V
75% Duty Cycle
20
PWM – Writing Analog in Energia
21
Color-Coded System
➢ Resistors are generally
marked with a banded color
code to denote the resistor’s
specifications.
➢ 4-band color code:
𝑅 = (𝑏1 𝑏2 ) × 10𝑏4 ± 𝑏5
➢ 5-band color code:
𝑅 = (𝑏1 𝑏2 𝑏3 ) × 10𝑏4 ± 𝑏5
➢ 6-band color code:
𝑅 = (𝑏1 𝑏2 𝑏3 ) × 10𝑏4 ± 𝑏5
𝑏6 denotes the temperature
coefficient of the resistor
measured in parts-per-million/℃
22
Building with the Breadboard
➢ Each horizontal clip on the breadboard creates a node, so each ROW of the
board is one node, and any wires plugged in on that row are connected to
the same node.
➢ The vertical clips on the sides of the board create nodes that extend the full
length of each side of the board. They are marked with red and blue lines
and are often called rails.
➢ These rails are commonly used for power and ground by plugging a voltage
on the red rail and ground on the blue rail.
23
24
A node is a point where two components of a circuit can be connected.
25
26
27