0% found this document useful (0 votes)
132 views173 pages

3 TcHxW6S6 k3B8VuouvuA Mod2 Devices QC Whiteoutsremoved Mar 2021

Uploaded by

Umair Ejaz Butt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views173 pages

3 TcHxW6S6 k3B8VuouvuA Mod2 Devices QC Whiteoutsremoved Mar 2021

Uploaded by

Umair Ejaz Butt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 173

Internet of Things

Module 2: Devices
UNIVERSITY OF ILLINOIS AT URBANA-CHAMPAIGN
You Need to Build…
• Flyover drone to analyze crops

• Generator defect detector

• Intelligent smartwatch

• Shopper gaze monitor


How do you build IoT things?
• IoT is a synthesis of hardware and software
• Software implementation plus a collection of attached circuits

• Not enough to understand Arduino programming


• Good designers know the system they are building on
• Underlying algorithms, protocols, architectures
• External interfaces, APIs, components
Roadmap
1. IoT Hardware
• Components, sensors/actuators, reference circuits, integrated circuits
• Memory, microcontrollers, storage
2. IoT Platforms
• Arduino, Raspberry PI, Amazon FreeRTOS, VxWorks, RIOT
• Designs, architectures, and tradeoffs
3. Deep Dive: Arduino Programming
• Development workflow, language, API, coding examples
4. Case Studies
• Deployment scenarios: cars, aircraft, buildings, retail
IoT Hardware
We Are Going through a Hardware
Revolution
• Low-cost, componentized hardware enables rapid prototyping
without advanced electrical engineering knowledge

Componentized Cloud-Based Open-Source


Circuits Fabrication Schematics

• This lecture: What You Need to Know to Build IoT Hardware Systems
• Electricity Fundamentals, IoT Circuits, Microcontroller Platforms
Background: Atoms
• Made of protons,
neutrons, and
electrons
• In materials, nucleus +
n
held in fixed position -
n
+ + n -
• Some electrons are +

also fixed
• But some electrons
may be free to
“move”
Background: Electrical Current
• Usually free electrons hop around randomly
• However, outside forces can encourage them to flow in a particular direction
• Magnetic field, charge differential  this is called current
• We can vary properties of current to transmit information (via waves, like dominos, as
electron drift velocities are very slow)

_ +

No charge differential Charge differential


Making an Electrical “Circuit”
Electrical Current Can Be Manipulated
• It is possible to take current and change it

Example: Resistor Example: Capacitor

Reduces flow rate of electricity Stores electrical “charge”


Flowing Electricity Is Like Flowing Water
Flow Rate Current (I)
Pipe

Voltage (V)

Water
Pump Pressure

Resistor
Resistance Constriction Resistance
(R) (R)
Water Analogy: Capacitance
Flow Rate (I) Current (I)
Pipe

Voltage (V)
Expansion
Water
Pump Bladder
Pressure Capacitance
Capacitance
(C) (C)

Capacitor
Electrical Components

Resistor Potentiometer Diode


Relay
Capacitor Transistor

Photocell Crystal
Oscillator
Light-Emitting DC Fan Speaker
Diode (LED)

Toggle AA Battery Electrical


Motor Piezo Buzzer
7-Segment Switch Ground
Display
How to draw a circuit?

• Need to remember our designs, show to others


• Need to clearly describe what each component is, properties of
component, which pins are connected, etc.
Electronic Symbols
Name Picture Symbol Name Picture Symbol

Electric
Resistor M
Motor

Capacitor Speaker

Voltage
Diode
Source

Transistor Switch

Electrical
Oscillator
Ground

Diagram of a basic Circuit


How to decide which components to use?

1. Think about what you want to build

2. Design a circuit that achieves that objective

3. List components that are required by the circuit and


their critical parameters
How to decide which components to use?
4. Choose components with desirable properties
• Voltage range, tolerance, resistance value, temperature
coefficient, wattage, load efficiency, etc.
• Components that reduce circuit complexity (e.g., built-in ESD
protection)
• Environmental parameters
(humidity/pressure/vibration/temperature resilience)
How to decide which components to use?
5. Choose components that fit in the circuit well
• Manufacturer with good documentation/support/tools, long-
term availability, lead-time, cost, fall-back options
• Mechanical parameters (dimensions, weight, etc.)

6. Prototype before you start production


Use Cases
Suppose you want to build…
something that lights up

• Indicator/status signals
• User interfaces and displays
• Illumination sources
• Light effects
Components that make light

Optical Audio
LED (green) TFT Display Transmitter

• What they do: Create light


• Key metrics:
• Brightness: how much light is generated (mcd/nits)
• Viewing angle: over what angle most of the light is visible (degrees)
• Color: color of emitted light (nm/kelvin)
• Voltage: voltage needed to “turn on” light (volts)
• Current: current needed to “turn on” light (mA)
How color is measured
• Option 1: Wavelength
• Color of light as function of
electromagnetic
wavelength/frequency

• Option 2: Black body


radiation
• All objects radiate light
based on their temperature
• Color of light as a function
of “blackbody” temperature
More components that make light
Colored LEDs Arranged LEDs Light Matrices Shaped LEDs Directed Light Other Light Tech Light Signaling

LED (green) Photointerruptor


Incandescent
LED (green, Bulb
Bar Graph Array flush mount)
Flexible RGB
LED (yellow) LED Matrix Electro-
luminescent
Optocoupler
Wire
LED (blue) Panel Mount LED

7-Segment
Display Laser Diode Light to
Red/Green TFT Display
Frequency
Bi-color LED Light Pipe Converter
LED Sequin

Infrared LED

4-Digit
Infrared 7-Segment LED Dot Matrix Optical Audio
Phototransistor Display Display Backlight Module LED Strip LCD Display Transmitter
Suppose you want to build…
something that needs electricity
• Operate for long periods of time without
management
• Move around without being plugged in
• Collect energy from environment
• Supply electricity to other devices
• Change voltage from one level to
another
• Protect against voltage spikes, electronic
noise, and static electricity
Electrical power sources
Energy Harvesting
Batteries

Coin cell battery Coin cell battery


(with leads) Plugging in to the Grid Solar cell [light] Solar cell [light]
(thin film)

AA battery
AA battery holder Motor/Generator Piezoelectric
[motion] generator
[vibration]

C battery
9V battery snap 9VDC 2.1mm wall
USB to TTL serial cable
adapter
Antenna/
Thermoelectric
Rectenna
generator
[radio waves]
[heat]
9V battery
9V battery holder

2.1mm connector jack Variable power


supply
USB battery Hand crank
Power: Combining Current Sources
1800mAh
6V (how long balls keep coming)
1800 mAh
- + Ball generator
Connected
1.5V 1.5V 1.5V 1.5V in Series
1800 mAh 1800 mAh 1800 mAh 1800 mAh
6V
(total
1.5V height)
7200 mAh 1.5V
(height Circuit
- + of step) (Ball Consumer)

1.5V Connected Ball generator


1800 mAh
in Parallel Ball generator
1.5V
1800 mAh Ball generator

Ball generator
1.5V
1800 mAh
Circuit
(Ball Consumer)
1.5V
1800 mAh
Components that change voltage levels

Transformer Voltage regulator Buck converter Boost converter


(steps up/down AC (keeps voltage within (steps down DC (steps up DC voltage)
voltage) range) voltage)
Power: Pulse-Width Modulation (PWM)
• Suppose you want to 25% duty cycle:
increase/ decrease
power to a
component
• E.g., vary brightness of
50% duty cycle:
LED, speed of motor
• PWM: controls power
by rapidly turning
on/off
• Cheaper, more 75% duty cycle:
efficient electronics
than varying voltage
Resistors and Potentiometers
What they do: resist the flow of
current
Resistor

Photoresistor Useful for:


• Protecting components from
getting too much current
• Increasing and decreasing
Wiper
Shaft
Shaft-wiper
attachment
voltage
• Measuring things (e.g., light
Resistance
Cam (for optional
element
on-off switch)
intensity)
Terminals
Variable resistor
(potentiometer)
Resistors and Potentiometers
Key metrics:
4 6 x100 ±5% = 4600Ω
• Resistance: how much they resist
current (Ohms)
Color Digit Multiplier Tolerance
• Tolerance: how accurate their
resistance rating is (%)
Black 0 x1

Brown 1 x10 ±1%

• Power rating: how much current


Red 2 x100 ±2%

Orange 3 x1K

they can handle (Watts)


Yellow 4 x10K

Green 5 x100K ±0.5%

• Maximum voltage: how much


Blue 6 x1M ±0.25%

Violet 7 x10M ±0.1%

Grey 8 x100M ±0.05%


voltage difference across their
input/output they can handle
White 9 x1G

Gold x0.1 ±5%

Silver x0.01 ±10%


Capacitors
What they do: store charge

Useful for:
• Temporarily holding some
–––– charge (like a tiny battery)
++++
Capacitor • Smoothing out voltage
spikes
• Measurement (humidity,
Example Circuit: Storing Charge in a Capacitor
pressure, touch sensors)
Capacitors Key metrics:
• Capacitance: how much charge it can
store (farads)
• Tolerance: how accurate their
plates capacitance rating is (%)
+ -
+ - • Maximum voltage: how much voltage
+ - they can handle (before they short out or
+ - burn up)
• Leakage current: amount of current that
leaks through dielectric
dielectric

• No “current rating” – you can’t have a


sustained current through a capacitor aside
from leakage
• Equivalent series resistance (ESR):
capacitors aren’t perfect and have tiny
amount of resistance (usually less than
Inducing Charge on a Capacitor
0.01Ω)
Diode
What it does: allows
current to go in forward
5V

direction, but not reverse


direction

Motor
Flyback

D1
Useful for:
R1
Diode
CONTROL Q1 • Reverse current protection
• “Rectifying” signals
Example Circuit: Preventing Current
(pulling out positive parts)
“Kickback” with a Flyback Diode • Converting AC to DC
• Measurement
(temperature, radiation)
Diode
Key metrics:
• Maximum forward current: how
Forward
Current much current can go through in the
forward direction (amps)
Current

• Maximum reverse voltage


(breakdown voltage): how much
Breakdown
Voltage voltage can be withstood in reverse
direction
Voltage
Forward
Voltage

• Maximum forward voltage: voltage


difference between input/output when
current going through forward
Current-Voltage Relationship of a Diode direction (ideally should be zero, no
resistance to current)
Suppose you want to build…
something that moves
• Position control surfaces,
antennas, conveyors, etc.
• Operating grippers, levers,
dispensers, belts, cutters, etc.
• With varying speed,
preciseness, torque/power, etc.
Electric Motors
• Converts electricity into
motion
• Main idea:
• Get two big magnets, one north
and one south
• Run electricity through a curved
wire
• Alternatively pushes/pulls against
magnets
• Rotates a mechanical shaft

© 2008 Abnormaal / CC BY 3.0 / https://commons.wikimedia.org/wiki/File:Electric_motor.gif


Common Types of Electric Motors

Brush Motor Brushless Motor Stepper Motor


“Brushes” (wires) touch spinning center External can is what rotates. Can has Many small internal “teeth” form
pole, alternatively flip polarity of attached permanent magnents pushed individual magnets, pulled to external
electromagnetic coils attached to pole. by electromagnents flipping polarity electromagnets, creating high-holding
attached to pole. torque.
Found in household appliances, toys, Found in fans, hobby aircrafts/cars, Found in desktop printers, robots, 3D
automobiles electric cars (Tesla Model S) printers, milling machines, etc.
Pros: Cheap, good torque at low RPM, Pros: More power, reliable, high speed, Pros: Great for position control, high
simple to control than brushed motors. reliability,
Cons: Brushes wear out over time, Cons: Requires advanced controller to Cons: Small steps limits top speed, high
Arcing from brushes create EM noise, operate, poor torque at low RPM loads/speed may cause skipped steps,
limited speed due to brush overheating continuously draws maximum current
More Types of Electric Motors

Generator Servo Torque Linear Vibration


(run brushed (like stepper, but with Can operate “Unrolled” Unbalanced
motor via position feedback indefinitely when motor, produces weight
external force mechanism to control stalled, applying straight-line attached to
to generate position – more constant torque torque (maglev pole (phones,
current) expensive, higher (force feedback trains, pen pagers, toys)
torque/speed) games, positioning) plotters)
Transistors/Relays

IBE What it does: acts like a


+ 6V
switch; when voltage applied
to one wire, forms connection
between other two wires
1k
ICE
Useful for:
Example Circuit: Controlling a • Acting like a switch
Transistor
Light with an NPN Transistor
• Amplifying a signal
Transistors/Relays
Key metrics (transistors):
• Type: does applied current turn on
connection (NPN) or turn off
connection (PNP)
• Maximum reverse voltage
Transistor on (breakdown voltage): how much
voltage can be withstood in reverse
direction
• Maximum forward voltage:
Transistor off voltage difference between
Water Analogy: Transistors/Relays
Stop/Start Flow
Formation of Channel to Make a Connection in a Transistor
input/output when current going
through forward direction (ideally
should be zero, no resistance to
current)
Suppose you want to build…
something that observes

• Listens, sees, measures


• Sound, light, temperature, humidity,
magnetic fields, rotation, acceleration, etc.
Sensors
Picture Sensor name What it detects Example Applications
Test strip reading
Detects and measures range of visible Sorting by color
Color Sensor
colors Ambient light sensing and calibration
Color matching
Measuring wheel/rotation speed
Varies output voltage in response to a
Hall Effect Sensor Proximity sensing
magnetic field. Can pair with magnet for
(magnetism) Positioning/alignment
some applications (e.g, positioning)
Current sensing

Audio recording
Microphone
Converts sound into electrical signal Speech recognition/Wake phrase
(sound)
Echolocation

Human activities: walking/running/dancing


Measures physical acceleration Fall/drop detection, Occupancy detection
Accelerometer
experienced by an object Detecting which way is down
Building/motor health monitoring
Sensors
Picture Sensor name What it detects Example Applications

Human activities: walking/running/dancing


Gyroscope/
Measures rotation (pitch/yaw/roll) 3D motion control
Tilt Sensor
Robotics

Detection of gases. Variants measure


Safety devices
Gas Sensor Carbon Monoxide, Methane,
Environmental monitoring
Alcohol/Benzine, Propane, etc.

Motion detection, entry alarm


Passive Infrared Converts infrared light into electrical
Remote control/communication
Sensor signal
Maze navigation, boundary sensing

Parking assistant systems


Measures distance to moving or
Proximity/ Speed measurement
stationary objects. Variants: ultrasonic,
Distance Sensor Robotic navigation
laser, infrared.
Interactive displays
Sensors
Picture Sensor name What it detects Example Applications

Humidity Sensor Soil monitoring


Measures humidity/water content
(hygrometer) Weather/microclimate monitoring

Detects and measures anything that is


Touchscreens
Touch Sensor conductive or has a dielectric different
Fingerprint-based identification
from air

Sleep mode activation


Photoresistor Light intensity
Smart building light controls

Presence/arrival detection
Weight measurement
Load Cell Measures force/weight Impact measurement
Mechanical strain detection
Sensors
Picture Sensor name What it detects Example Applications
Industrial process monitoring
Measure flow rate (and thereby volume) Farming (eg. water/pesticide applications)
Flow Sensor
of gas or fluids Water/gas meters
“Green building” resource usage

Measure wind speed. Can pair with vane


Weather/microclimate monitoring
Anemometer to measure wind direction. Also see
Structural safety monitoring (bridge, cranes etc)
pitot tube.

Temperature Plant health monitoring


Sensor Measures temperature Industrial machine health monitoring
Circuit overheat protection

Captures video or pictures. Can be Customer identification


paired with computer vision to Crop Analysis
Camera
recognize objects, faces, track motion, 3D Object recognition
etc. “Go home” function
Emerging Sensors
Recently emerging sensor types make IoT more powerful

Picture Sensor name What it detects Example Applications

Early detection of health problems (eg COPD)


Measures chemical concentrations behind
Electronic Nose Counter-terrorism
scents/smells
Computer smell

Determining texture, stiffness, coefficient Robotics


Tactile Sensor
of friction, thermal conductivity Object recognition

Measures composition of blood, including Smart clothes


Blood Gas/Sugar
amount of arterial gases (eg oxygen, Home health checkup
Sensor
carbon dioxide), pH, sugar, etc. Early asthma detection

Mental control over objects


Measures electrical activity of brain. Can
Brainwave Diagnose brain faults and mental disorders
pinpoint activity to 3-D location inside
Sensors Understanding user intent
brain.
Reading innermost thoughts and desires
Making a Circuit

• Can put components together to build circuits that do things


How to Build Circuits
• Like algorithms, common circuits are known
• Can learn the common ones

• You don’t need to memorize a lot of circuits to do IoT


• More complicated circuits tend to be componentized anyway
• Can buy pre-created chips and PCBs
• Can also look up advanced ones when needed

• Next, we will go through some that are helpful to know for IoT
projects
• Build intuition, use these when you need them
Six Useful Circuits to Know About
Widely used, demonstrate useful concepts:
1. Current-Limiting Resistor
2. Voltage Shifter
3. Filter Capacitor
4. Pull-Down Resistor
5. Signal Amplifier
6. Transistor Switch
1. Protecting against Current Overload
(Resistors)
Current 100
Forward

If - Forward current - mA
Current
80
R1
60 Vs
Breakdown
Voltage 40 Vf
Voltage
Forward
Voltage
20 LED

0 1.0 2.0 3.0 4.0 5.0 6.0


Vf - Forward voltage - V
LEDs have Resistors have Current-limiting
non-linear resistance linear resistance resistor

• Components can accidentally draw too much current


• Resistors: current increases linearly with voltage
• LEDs: if you overshoot voltage a little bit, suddenly LOTS of current
• Current-limiting resistors protect your components
• Prevent too much current from going though your circuit
2. Protecting against Spikes (Filter
Capacitors)
a b c d e f g h i j +9V LM7805
1 1

VI VO Vout
0.33µF 0.1 µF

GND
5

U1
C C
10 10

GND

• Place capacitor between terminal and ground to smooth noise at the


terminal
• Choose capacitor value based on noise you expect from the system
• Rule of thumb: 0.1μF-10μF is pretty safe if you’re just doing low voltage logic
3. Eliminating Noise from Disconnection
(Pull-Down Resistors)
Vin
Vin
Switch

Switch
Vout
Logic Gate
Vout (buffer)

Logic Gate Pulldown


(buffer) Resistor

Ground

If an input pin is disconnected, its Solution – attach to ground, but


voltage is nondeterministic add a resistor so you don’t short-
circuit
4. Getting the Voltage You Want
(Voltage Divider/Regulator/Level Shifter)
5V

R1 5.6kΩ C1

Vin
5V pin 22 pF 3.3V pin

Vout
R1
1 kΩ

R2
R2
2 kΩ

Voltage Divider Reading Resistive Level Shifter


Sensor
• May need different voltage from your supply
• Resistors can be used to change voltage
• Transistors can be used to “switch in”
5. Amplifying What You Want to Hear
(Operational Amplifiers)
Inverting Op-amp Non-inverting Op-amp Differential Op-amp Summing Op-amp
R1 Rf
Rf Rin Rf
If V1
V1
Rin Iin R2
V2
Vin Iin A Vin A A Vout R3 A – Vout
- Vout Vout
If V3

V2
Rf Rin Rf
Rin

Vout Rf Vout Rf Rf Rf Rf Rf
A= = A= = 1+ Vout = (V2 – V1) Vout = — V1 + V2 + V3
Vin Rin Vin Rin Rin Rin R2 R3

• Two inputs, one output; amplifies difference between inputs


• Good Op-amps reject noise (common-mode voltages)
• Widely used to amplify inputs: audio amplifiers, sensors, radio NICs
6. Transistor Switches (Transistors, Relays)
MC
VCC PMotor Power
SS
D1
D0
A
M MDC Motor RES
DDiode
GND
D2
B
TNPN Transistor D3
D4
A×B
D5
D6
R1kΩ D7
D8
D9
GND D10

Logic Gates Controlling Voltage


• Allow an input to be controlled by another input
• Useful when we need to do conditional logic
• Useful when using logic to drive much larger voltage/current source
Integrated Circuits
• “Discrete” circuits are great, but limits to how small/cheap you
can build them

• Discovery in 1960s: you can actually “draw” circuits


• Cost is low because they are printed en masse
• Small size and tight proximity  they can switch quickly and use little
power

• However, high initial cost to design and fabricate required


“photomasks”
• Practical only for high production volumes
Underlying Technology Behind ICs:
Semiconductors
• Want a material you can “draw” on
• Semiconductor: poor insulator
• Can “dope” it to become conductor
• Can selectively dope it in certain areas
• Etch tiny wires, components
• Side benefits:
• Excited electrons can emit light instead of head (LEDs)
• Resistivity can change with temperature, light, exposure to gas (sensors)
• High thermal conductivity (good heat dissipation)
1
1
8 2
1

4 7 Si 3 2

2
6 4
5
3
Si
Si Si
Undoped Semiconductors
Are Insulators B
Si Si P
Si

Si Si Si Si Si

Si Si Si Si Si

Si Si Si Si Si
Doping with Boron
B
Si Si P
Si

Si Si Si B Si

Si B Si Si Si

Si Si B Si B
Doping with Phosphorus
B
Si Si P
Si

Si Si P P Si

Si P Si Si Si

P Si P Si P
How to “Print” Components
base +

p-type n-type n-type p-type n-type


p-type silicon
anode silicon silicon cathode emitter silicon silicon silicon collector

Diode Transistor Capacitor Resistor

• Can “draw” (etch) tiny components using “doping”


1. Lithography: draw your design onto photomask, apply to surface of
silicon wafer
2. Etching: “carve” your design into the silicon
3. Deposit metal for connections
How ICs Are Made
UV beam
Ion Light
(phosphorus)
(boron)

Glass
Mask
emitter base collector emitter base collector
Photoresist
Silicon dioxide
n+ n+ p+ p+
P-type silicon n-well

NMOS gate PMOS gate

CMOS (technology)
Integrated Circuit Packaging

Dual-Inline Package (DIP)

Small-Outline IC (SOIC)

Quad-Flat Package (QFP)

Surface-Mount Device (SMD)


Example IC: Texas Instruments SN74S08N
(Quad AND Logic Gates)
notch

SN74S08N (DIP)
Pinouts
Logic Diagram
Schematic (each AND gate)

• Datasheet: https://www.ti.com/lit/ds/symlink/sn74ls08.pdf
• Google “SN74S08N datasheet”
• Price: $1.61 for one, $0.65 each for 5000 (Digikey.com, January 2019)
Popular IC Types
IC Alternatives/
Type Pinout Logic diagram What it does
family Variants

Can configure time and mode. Sends pulse after


XR-2206 (also generates
time period (monostable config) or at regular
555 Timer sine/sawtooth waves), 8038,
intervals (astable config).
CD4046
Most popular IC. >1 Billion sold every year.

LM324 (has four op-amps in


one 14-pin DIP package,
Operational
Produces output voltage much higher than doesn’t require separate
741 Amplifier
voltage difference between input terminals pos/neg power supplies),
(Op-Amp)
LM358, TLC272; TL0XX (eg,
TL081, TL082, TL084)

Accepts input voltage within a certain range and 78xxSR, 78xxC, 78xxS, 79xx,
Voltage produces a constant output voltage. xx represents LM317, LM2575T-ADJ
78xx
Regulator voltage regulated by chip (e.g., 7805 produces a (output adjustable 1.23V to
5-volt output) 37V), MC34063A, XL6009

7408 (AND), 7404 (NOT),


Digital logic operations. Includes logic gates, flip- 7486 (XOR), 7402 (NOR),
74xx Logic Circuits
flops, counters, buffers, and more. 7400 (NAND), 7474 (Flip-
flops)
Popular IC Types
Alternatives/
IC family Type Pinout Logic diagram What it does
Variants
Stores an array of bits. Can “shift” bits up, 74LS195 (4 bits), 4006
Shift losing (or wrapping) bits off the end. Used to (18 bits), 4014 (8 bit
74HC595
Register allow many pins to be controlled by 1-2 pins, static), 74LS194
to multiply by two, etc. (bidirectional 4-bit)

Converts analog to digital; takes an analog


A/D voltage level on one pin, outputs across a set
MCP3008 MCP3002. PCF8591,
Converter of pins a binary number representing the level
of that voltage.

Opposite of an A/D converter: takes a binary MCP4725 (12-bit),


D/A
MCP4822 input across a set of pins, and outputs a MCP4728, MCP4921,
Converter
voltage corresponding to that number. AD7390

Compares two input voltages and outputs a


digital signal indicating which is larger (output
is 1 if V+>V-, 0 otherwise. Can be used to LM312, LM393,
LM311 Comparator
create null detectors (whether input is 0 volts), LM339
to generate triangle/square waves (eg car turn
signal), etc.
Popular IC Types
Alternatives/
IC family Type Pinout Logic diagram What it does
Variants
Accepts standard TTL logic level voltages, and
Motor drives big inductive loads such as
L298D L298N, L293
Driver electromagnets, stepping motors, valves,
pumps, etc.
16 channels, each has 4096-step PWM
brightness control. Brightness controlled by
TLC5947, LT3741,
TLC5940 LED Driver programmable on-chip EEPROM. Reports
ADP8861
error information: broken/disconnected LED,
overtemperature condition.

MCP23017, MCP
I/O Change one serial input to 8 pins of parallel
MCP23008 23016 (16-bit),
Expander output. Adds 8 pins to your microcontroller.
SX1509, TCA9535

802.11 b/g/n WiFi with WEP/WPA/WPA2


ESP8285 (has 1MB
WiFi authentication (or open networks) and full
ESP8266 built-in flash), ESP32
module TCP/IP stack. Also contains embedded
(successor)
microprocessor core
So, can we just make everything an IC?
• ICs are great
• “Componentize” circuits – don’t need to understand insides so much
• Reduced cost

• But can’t do everything as an IC


• High current/voltage – exceeds logic levels
• Low volume or too new – no ICs exist for it

• Can we componentize non-IC circuits?


Breakout Boards

• Standalone board that componentizes a circuit


• “Breaks out” key pins to simplify prototyping
• Deals with complicated EE stuff, lets you focus on using the circuit
• Incorporates collection of components onto a single PC
• Example: Adafruit 9-DOF Absolute Orientation IMU Fusion Breakout –
BNO055 = $34.95 (January 2019) (Source: https://www.adafruit.com/product/2472)
Breakout Boards
• Benefits: reduces costs, saves space, improves
efficiency/reliability, simplifies reuse, clear pinouts, good
documentation
• Lets you do a lot with less domain knowledge
• Speeds prototyping
• Saves you soldering work

• Challenges: may not be interchangeable/compatible (e.g., may


target a specific platform like Arduino), may need to solder or
install header pins, need to be careful about supply voltage and
other inputs
Example: Adafruit AMG8833 IR Thermal
Camera Breakout
• 8x8 array of thermal IR
sensors
• Can detect human 23 feet
away
• 10 Hz frame rate
• Uses: human detector,
thermal camera, intruder
alert
• Incorporates: Panasonic
AMG8833 thermal IR sensor,
3.3V regulator, misc.
resistors/capacitors
Example: Adafruit AMG8833 IR Thermal
Camera Breakout
• Pinout:
• Input voltage (Vin)
• Output voltage in case you
can use it (3Vo)
• Ground (GND)
• Serial clock – output (SCL)
• Serial data – output (SDA)
• Interrupt output – when
SCL something changes in vision
path (INT)
SDA
GND • (Pins at top for stability,
Vcc unused)
Example: Adafruit TB6612 1.2A
DC/Stepper Motor Driver Breakout Board
• Driver for stepper motor
• Can drive 1.2A sustained, 3A peak
(20ms)
• Control direction and speed,
stop/brake
• Motor voltage isolated from logic
voltage
• Uses: robot, pan/tilt housing,
automotive gauge/dial, toy car
• Incorporates: a Toshiba
TB6612 motor driver IC, two H-
bridges, polarity protection FET,
pullup resistor for inputs, kick-
back diodes
Example: Adafruit TB6612 1.2A
DC/Stepper Motor Driver Breakout Board
Vcc • Pinout:
GND
Vmotor • Input voltage for logic
STBY levels (Vcc)
• Voltage to drive motor
(Vmotor)
• Ground (GND)
• Motor control outputs:
Motor B • INA1, INA2, PWMA: outputs
control for motor A’s H-bridge
Motor A • INB1, INB2, PWMB: outputs
for motor B’s H-bridge
control • STBY: quickly disable both
motors
Example: Adafruit Capacitive Touch HAT
for Raspberry Pi – Mini Kit – MPR121
• Driver for detecting touch
• Attach pins to something
conductive (metal, something
containing water)
• “HAT” simplifies connecting to
Raspberry Pi platform
• Comes with python library
• Uses: touch-reactive tablets,
control panels, and other
objects
• Incorporates: a MPR121 12-
key touch sense
microcontroller
Example: Adafruit Capacitive Touch HAT
for Raspberry Pi – Mini Kit – MPR121
SCL Touch Pins
• Pinout: (look familiar?)
• Input voltage (Vin)
• Ground (GND)
SDA • Serial clock – output
Vin (SCL)
GND • Serial data – output
(SDA)
• Touch-capacitive pins (#)
Example: Adafruit 15x7 CharliePlex LED
Matrix FeatherWing – Cool White
• Drives matrix of LEDs
• Tell chip which LEDs you want lit
and their brightness, and it will
PWM them for you
• RAM for eight separate frames,
can animate through them with
single command
• Comes with python graphics
library
• Uses: displays, status
indicators, human-
machine interfaces
• Incorporates: a
IS31FL3731 I2C LED
driver chip
Example: Adafruit 15x7 CharliePlex LED
Matrix FeatherWing – Cool White
LED Matrix Output
SCL SDA
• Pinout: (look
familiar?)
• Input voltage (Vin)
• Output voltage in case
you can use it (3Vo)
• Ground (GND)
• Serial clock – input (SCL)
• Serial data – input (SDA)
• LED matrix output pins
Vin (3.3V) GND
Encoding
Sending Bits on Wires
• Sometimes we need to take data and send it on wires
• Between chips on a PCB, between different PCBs within a
device, between devices in a home, between devices in
different buildings

• Need some way to “encode” bits

• Idea: change some properties of the wire that can be


read by the other side
What Properties to Change?

• Really only two options: current and voltage

• Voltage turns out to be much more efficient


• Current changes over wire length, requires more
electricity
What Voltage Levels Should We Use?
• Lower levels reduce power consumption, improve safety

• Higher levels reduce sensitivity to noise, loss over


distances

• Specific values (15V, 12V, 5V, 3.3V) are common for


historical reasons
• Large existing market reduces component cost
Two Chips Can Vary Voltage to Send Data
Wait a second,
this doesn’t look right
0 1 0 0 1 0 1 1 0 0 0 1
+5V

0V
Cycle 1 2 3 4 5 6 7 8 9 10 11 12 13

Data

• One approach: raise voltage for a 1, lower it for a 0


• Other side decodes: periodically sample voltage on wire
• Problem: clock synchronization
Two Chips Can Vary Voltage to Send Data
0 1 0 0 1 0 1 1 0 0 0 0 1
+5V
DATA
0V
+5V
CLOCK
0V

Wait a bit for the bit to arrive, Hold line high long enough
then send clock pulse to distinguish it from noise

Data

Clock
Sender Receiver
clock clock
Phase Locked Loop

• Another approach: have a • Problems: need additional wire


separate clock line (increases costs, increases faults because
faults/noise in *either* wire cause loss)
• Use pulses to signal when receiver • Also need faster components (if clock
should sample line transition rate exceeds that of data)
A Few Other Issues:
DC Balance
Level Slicer

It’s a 1
Undetermined

It’s a 0

Unequal numbers of 0s and 1s can introduce bias in level detection circuitry


• In unbalanced channel, DC component shifts cause slicer to respond at level different
to data average
• Also makes it hard to galvanically isolate (separating two circuits due to
noise/safety, e.g., with capacitance, EM waves, etc.)
• Also requires more transmission power (need to send DC to receiver)
A Few Other Issues:
Electronic Noise
0 1 0 0 1 0 1 1 0 1 0 0 1 Level Slicer

It’s a 1
Undetermined

It’s a 0

• May introduce false readings


• Sources:
• Thermal noise: free electrons vibrate more at higher temperatures
• Shot/flicker/burst/transit-time noise: noise from electrons traversing components
• Coupled noise: noise leaked from adjacent wires/atmosphere/cosmic
• Leakage noise: motors/speakers/bulbs/etc. induce voltage spikes), etc.
A Few Other Issues:
Loss/Attenuation

• Wires/components have resistance (impedance)


• Reduces current and voltage. Amount proportional to length of wire
• Larger-diameter cables/wires have less resistance per foot
• Components also have impedance, more you traverse the worse it gets
• Impedances sum when connected in series, inversely sum with
inverses when connected in parallel
A Few Other Issues:
Dispersion

• Not all electrons in the pulse go the same speed


• Bits melt into each other, making them hard to distinguish
• Some components have more dispersion than others (e.g., low-
pass filters)
Ok, so can we at least get rid of the extra
wire? 0 1 0 0 1 0 1 1 0 0 0 0 1
+5V
DATA
0V
+5V
CLOCK
0V

Data

Clock
Sender Receiver
clock clock
Phase Locked Loop

• Idea: receiver can sync clock • Problem: What if not enough


transitions?
off transitions • Long runs of 1s or 0s
• Clocks could get out of sync
Idea: Re-sync on Each Short Message
(Asynchronous Communication)
0 1 0 0 1 0 1 1 0 0 0 0 1
V+

0V
idle start stop idle

• Start and stop signals appended before/after each unit of


transmission
• Start signal used to set receivers’ clock
• Need to agree on parameters in advance (full vs. half-duplex, # bits per
character, endianness, baud rate, whether to use parity, odd vs. even
parity, # of stop bits)
Idea: Re-sync on Each Short Message
(Asynchronous Communication)
0 1 0 0 1 0 1 1 0 0 0 0 1
V+

0V
idle start stop idle

• Advantages: doesn’t require continuous synchronization 


cheaper hardware, faster session setup
• Good for applications where messages are generated at irregular
intervals: user input (e.g., keyboards), sensors, etc.
• Downsides: large overhead (many bits just used for control)
• Used in: RS-232/UART/PPP/etc.
Another Idea: Force There to Be More
Transitions 0 1 0 0 1 0 1 1 0 0 0 0 1
NRZ [Non-Return to Zero]: V+
High voltage for 1, low voltage for 0
(what we’ve been seeing) 0V

NRZI [Non-Return to Zero Inverted]:


Transition for 1, no transition for 0. NRZI V+
is a “differential encoding,” as value
depends on preceding bits (increases 0V
transition density)

Manchester (IEEE 802.3): V+


Up transition for 1, down transition for
0 (further increases transition density,
but requires faster clock) 0V

• Use transitions rather than voltage levels to encode data


• Cause more cycles  improve clock synchronization
• Transitions are also easier to detect than levels
A Few Other Approaches
0 1 0 0 1 0 1 1 0 0 0 0 1
Differential Manchester:
V+
Transition either up or down each
cycle. Repeat previous transition if 0,
invert if 1. Unlike Manchester, works 0V
the same if lines swapped
Bipolar Alternate Mark Inversion (AMI): V+
Three levels; 0 is no voltage, 1s alternate
between positive and negative voltage 0V
levels. (doesn’t require faster clock, but V-
“wastes” levels)
Pseudoternary: V+
Opposite of Bipolar AMI; 1 is no
voltage, 0s alternate between positive 0V
and negative voltage levels V-

• These are pretty good but can we do better?


• Manchester/Differential Manchester requires 2x clock
• Bipolar AMI/Pseudoternary requires more levels
Idea: Map onto Codewords with Nice
Properties Why do these long sequences happen?

0101110010100000000000000000000000000001110101100110
What if we disallow 0000?

0101 1100 1010 0000 0000 0000 0000 0000 0000 0001 1101 0110 0110

01011 11001 10101 00001 00001 00001 00001 00001 00001 00011 11011 01101 01101

01011110011010100001000010000100001000010000100011110110110101101

Idea: translate into 5-bit • Problems: efficiency (entirely lose


codewords; add an extra Then perform the reverse 1/5 bits of capacity); still can have
bit to the end and make it
always be 1
translation (just discard those long sequences of 1s
extra bits) at the receiver
Better Approach: 4B/5B
(Choose Codewords Smarter)

• Encode every 4 consecutive bits as a 5-bit word

• Codewords
• At most one leading 0, at most two trailing 0s
• Never more than three consecutive 0s
• Transmit with NRZI
Better Approach: 4B/5B
(Choose Codewords Smarter)
• 16 of 32 possible codes used for data, others used for
command characters
• Ensures at least two transitions for each code

• Variants
• 8B/10B (used in digital audio – compact discs, DAT tapes,
etc.)
• 64B/66B (used in 10Gig Ethernet)
• 128B/130B, 128B/132B (used in PCI Express 3.0 and USB 3.1)
4B/5B Encoding Table At most two trailing zeros

0000 ⇨ 11110 1000 ⇨ 10010


0001 ⇨ 01001 1001 ⇨ 10011
0010 ⇨ 10100 1010 ⇨ 10110
0011 ⇨ 10101 1011 ⇨ 10111
0100 ⇨ 01010 1100 ⇨ 11010
0101 ⇨ 01011 1101 ⇨ 11011
0110 ⇨ 01110 1110 ⇨ 11100
0111 ⇨ 01111 1111 ⇨ 11101

At most one leading zero


Where is this stuff used?
• Different encoding schemes are used in different settings

• Advanced/Complex encodings used for high-speed links


between computers
• Where it’s worth investing in more complex circuitry
• See more Manchester, 64B/66B, etc.

• Between chips on a PCB you care more about low power and
cost
• Simpler techniques, easier to run shared clock lines everywhere
• See more asynchronous, clocked encodings, etc.
Connecting ICs with the I2C Protocol
Vcc

SDA
SCL

Microcontroller ADC LED Driver Speaker Driver


(Master) (Slave) (Slave) (Slave)

• Easy to use, very expandable, serial bus widely used to connect ICs
• Reduces pinouts, transfers data/commands
• Address-oriented scheme, where addresses are part of packets that you send
• Handles many devices; each device has an address (can solder jumpers to change address)
• Message-based communication (unlimited length), 0.1-5Mbps, synchronous
• Multi-master/Multi-slave architecture: master generates clock, initiates
communications
Other Kinds of Buses
• Serial Peripheral Interface (SPI)
• Max # devices very limited (chip-select for each chip on the bus)
• Significantly faster than I2C (25Mbps), works over longer cable runs
• Used for, eg. Connecting microcontroller to SD/microSD card
• UART (RS-232/422/485/etc., aka Serial Port)
• Asynchronous (no shared clock)
• Parameters: baudRate, parity, stopBits, dataBits (e.g., 115200, none, 1, 8)
• Max speed 8Mbps
• GPIO
• Not really a protocol – turning pins on and off, defines threshold voltages
• Used for switches, buttons, motion detectors, LEDs, turning on/off appliances
• Max speed 1kHz
Example Breakout Boards
Internal Other boards in this
Type Name Picture What it does
Components category
Takes in logic input and uses that to control a higher-
Allegro amp input for driving a stepper motor. Includes
A4988 current limiting, short-circuit/over-current/over- Clock generators, Audio FX
Actuator Stepper temperature protection. Operates from 8-35V and A4988 IC sound boards,
Motor supports up to 1A without cooling (2A with sufficient storage/microSD, NVRAM
Driver additional cooling). Five different resolutions (full, half,
quarter, 1/8, 1/16).
Nokia 6100 color LCD,
SparkFun
Uses logic input to write graphics onto and control Philips PCF8833 LED matrix backpacks, LED
Color LCD
Display backlight of color LCD display. Display is 132x132 graphics controller, strip controllers, LCD displays,
Breakout
pixels @12 bit color, same display from cell phones. status LEDs, two touchscreen controllers
Board
pushbuttons.
Other types of USB (microB,
SparkFun Splits out female USB type A connector’s VCC, D-, D+,
C, etc), audio connectors,
USB Type A and GND pins to a standard 0.1”-width header. Good USB Type A female
Connector HDMI/DVI coders, USB
Female if you need USB but don’t want to deal with soldering connector
mouse/keyboard controller
Breakout tiny connectors.
Wireless 802.11/LoRA/etc.
Adafruit
MEMS sensor breakout to monitor levels of various Sensors for Oxygen, CO2,
MiCS5524
sorts of gases. Useful for indoor carbon monoxide methane, PM2.5/PM10,
CO, Alcohol SGX NICS-5524 gas
Sensor and natural gas leakage, alcohol breath checker, early humidity, barometric/altitude,
and VOC sensor
fire detection. Sensitive to 1-1000ppm. Can’t tell you windspeed, temperature,
Gas Sensor
which gas it has detected. human breath analysis
Breakout
What if we want to build something
flexible?
• Circuits are good for very specific, single-purpose
functions
• Increase voltage from 3.3V to 5V, drive a motor, etc.

• But what about


• A car that recognizes human shapes?
• A drone that flies a programmable path?
• A thermostat that displays updatable pictures?

• Problem: need to deal with many contingencies


Idea: A “Programmable IC”
0010 1011
Please become a
circuit that adds Input Pins
pins 1-4 and 5-8
Control

I3

I2

I0
I1
I4
I7

I5
I6
Please become a Pins
C0
circuit that raises C1 Amplify
Add pinspin
1-47,
Raise/lower pin 5
and lowers pin 5 C2 send to
and a5-8
20x pin 4
second
twenty times a C3
second

O3

O2

O0
O1
O4
O7

O5
O6
Please become a
circuit that amplifies Output Pins
the signal on pin 7
1101
and sends it to pin 4
VCC
CPU

D0

D1

D2
a
D3 a e

D4 b f
f b

D5 c g g
d dp
D6

D7
Gnd e c Vcc

D8 d

dp
D9

D10

D11

D13

D13
GND
VCC
CPU

D0

D1

D2
a
Program Counter 1. Write D, 00000000 D3 a e

2. Write D, 01101110 D4 b f
f b

3. Write D, 10011110 D5 c g g
d dp
4. Write D, 10001100 D6

D7
Gnd e c Vcc
5. Write D, 01101110
D8 d
6. Write D, 11111100
dp
D9
7. Write D, 00000000
D10

D11

D13

OSC1 D13
GND
Opcode [Operand] Instruction Memory
0001 [address] add Instruction memory
0010 [address] subtract Address Value

0011 [address] store 0000 0111


0101 0101

0101 [address] load 0001 0001 0110

CPU 0010 0011 0111

Status Address Bus


Decode Arithmetic/Logic
Fetch Unit Unit Data memory
Decode
Address Value
Execute Data Bus
Instruction Register 0101 0111 0111 0000 0011
Memory Address Register 0111
0000 1000 0001 0110

Memory Data Register 0000 0111


0101 0011 Control Bus 1001 0011 0111
Control
Accumulator 0000 0011 Unit “memory
read”
Program Counter 0001
0000
Benefits of CPUs
• Programmable circuits allow highly customizable logic in
hardware
• Enables explosion of sophistication

• Focused on digital applications


• Easier to consolidate into a compact unit

• CPUs are great for many applications


• Extremely flexible, high-speed
• Can run operating systems, machine vision, NLP, etc.
Downsides of CPUs
• However, hard to make them very cheaply
• Hard to make general, powerful platforms also cheap
• What do we do for ultra-cheap applications?

• Idea: make special-purpose CPUs


• Architectures targeted toward specific uses
• Only the capabilities you need  reduced costs
Microcontrollers
A microcontroller is like a CPU, but:
(a) Microprocessor
1. Lower-end design
• Lower-performance (lower power
Microprocessor usage/clockspeed)
• Simpler (limited instruction set)
Output Input Memory

2. Consolidated design
• Memory, oscillator, I/O controllers,
watchdog timers, are within chipset
3. Special on-chip functions
(peripherals)
(b) Microcontroller

• Onboard DAC/ADC, PWM, NCO,


programmable logic
Output Input Memory
How to Choose a Microcontroller
• Core design: vendor-proprietary vs. third-party
• 32-bit ARM core becoming ubiquitous, Intel 8051 also used

• High- vs. low-end:


• Microcontrollers come in “families”: some have hundreds of models to
choose from, some have much fewer. Smaller: economy of scale; larger:
select what you need
• Sunken cost in choosing a family

• Package availability
• Wafer-level CSP package that’s 2x2mm? Larger DIP package?
How to Choose a Microcontroller
• Peripherals: multiple interrupt channels, DMA, internal clocks,
power configuration control options, etc.

• Development experience:
• What kinds of IDEs/SDKs/compilers/emulators/dev boards/debuggers
are available? How much do they cost? Are they cross-platform?

• Performance: power efficiency, clock cycle efficiency, code size


Popular Microcontroller Cores
ATMEL AVR
• RISC design. many single-cycle operations, 2-cycle multiply
• Strengths: many registers (32), good cycle efficiency
• Downsides: only one interrupt priority, slow clock speed
ATMEL TINYAVR ATMEL MEGAAVR compared to competition (up to 32 Mhz)
(low-end) (high-end) • Example chips: ATtiny85 (Arduino), ATtiny1616, ATmega328

MICROCHIP PIC
• RISC design. 4T machine - 4 cycles fetch (plus 4 cycles execute)
• Strengths: many peripherals, historically very popular
• Downsides: only one register, no stack, lower-end chips have no on-
chip debugging support, slow flash-load times. Falling out of favor for
Microchip PIC16 Microchip PIC24 students/hobbyists.
(lower-end) (higher-end) • PIC32 uses 3rd party core (MIPS M4K)
• Example chips: PIC10, PIC12, PIC16, PIC18, PIC24, PIC32
Popular Microcontroller Cores
ARM Cortex-M0
• 32-bit RISC. Entry level to ARM architecture. Rapidly gaining market
share in <$1 market
• Strengths: 32 interrupt vectors, 4 interrupt priorities, full support for
runtime exceptions. 13 registers.
• Downsides: low code density, lack of compatibility across vendor
peripherals, complex peripherals, slow (12 cycle) interrupt latency
ATMEL SAM D10 Infineon XMC
• Example chips: Infineon XMC-1100, Cypress PSOC 4000S

INTEL 8051
• Variable-length CISC instruction set, 32 registers, 2 interrupt
priorities, 64KB program/RAM addressability. Widely-cloned architecture.
• Strengths: fast interrupts (good for real-time eg USB webcams and audio
DSPs), fast clock speeds, historicallyextremely popular
• Downsides: only 8-bits, hard to compete with cheap 32-bit controllers.
Simplicity can be a detriment with modern compilers. Falling out of favor.
Nuvoton 8051 Infineon XC8XX • PIC32 uses 3rd party core (MIPS M4K)
• Example chips: STCmicro STC8, Silicon Labs EFM8, Nuvoton N76
Other Kinds of Programmable Circuits

CPUs Microcontrollers FPGAs

ASICs GPUs System on Chip (SoC)


FPGAs (Field-Programmable Gate Arrays)

• FPGAs consist of a bunch of:


• Programmable logic blocks – can be configured into logic gates
(AND/XOR/NOT/etc.) or complex combinatorial functions
• Interconnects to hook them together

• Many FPGAs can be reprogrammed after deployment (in the


“field”)
• Enables flexible “reconfigurable computing”
• Can fix vulnerabilities/bugs post-deployment
FPGAs (Field-Programmable Gate Arrays)

• Can write whatever circuits you want  parallel execution


• Can be more power efficient than single-threaded microcontrollers for
some applications (ML/AI/data processing)

• However, current tech targets high end market  expensive


(>$500)

• Key players: Xilinx (49% of market), Altera (40% of market)


• Intel (see Cyclone 10)
Programmable Circuits

CPUs Microcontrollers FPGAs

ASICs GPUs System on Chip (SoC)


ASICs (Application-Specific Integrated Circuit)

• Burn your design into silicon


• 100s of millions of logic gates
• Can include ROM, RAM, EEPROM, flash memory, and other
large building blocks

• Core logic not field-programmable, hard to update


designs
• May contain some reconfigurable logic
ASICs (Application-Specific Integrated Circuit)

• ASICs (and FPGAs) used to implement


CPUs/microcontrollers/etc.
• Typical design: IP core CPU, digital signal processor, communication
interfaces, memory

• Non-recurring engineering (NRE) of millions of dollars


• Best for large production volumes, shared functionalities

• Key players: TSMC, GlobalFoundries, Samsung Semiconductor,


Texas Instruments
GPUs (Graphics Processing Unit)

• Designed to rapidly manipulate and process images and


video
• Many threads, like a highly parallel CPU (e.g., 480-1536
stream processors)

• Commonly used in mobile phones, personal computers,


game consoles, self-driving cars, drones, automated
surveillance, etc.
GPUs (Graphics Processing Unit)

• Contains hardware implementations of important graphics


functions
• Texture mapping, rendering polygons, rotation/translation of vertices,
shading, special effects (chroma keying, bokeh, volumetric lighting)

• Non-graphics applications
• Applications that can be parallelized work well: processing hashes
(bitcoin mining), matrix operations, audio processing, machine learning

• Key players: NVIDIA, Intel, AMD


SoCs (System on Chip)

• SoC=system on chip

• Basically pairs a CPU/microcontroller with other functions,


on one chip
• Tighter integration  better reliability, power savings, lower cost

• Paired functions: AI acceleration, machine vision, wireless


communications, digital camera hardware/firmware, etc.
Emerging Programmable Circuits
• Vision Processing Unit (VPU) – accelerates computer vision –
Microsoft HoloLens, Movidius Myriad X, NVIDIA VLIW Vision
Processor

• Neural Network Processor (NNP) – accelerates neural network


machine learning – Google (Tensor Processing Unit), Intel
(Nervana), AWS (Inferentia), Apple (Neural Engine)

• Machine Learning Processor (MLP) – general programmable


platform for machine learning – ARM (Trillium), IBM (Power9)
Open-Source Hardware Logic
• Don’t create complex hardware designs from scratch!

• Highly advanced complexity in hardware  takes a lot


of time and investment to create
• Re-use cuts product development times and creates better
products
• Open-source organizations provide free IP cores
• E.g., www.opencores.org
Open-Source Hardware Logic
• Cell libraries: libraries of logical sub-components that
can be plugged together

• IP cores: primitives purchased from a third-party


• May be provided as hardware-description language (“soft
macro”)
• May be provided as a fully routed design (“hard macro”)
• ARM only sells IP cores (“fabless manufacturer”)
How to decide which to use?
Technology When to use Example applications
When you need to get really small, really power- Main compute for Apple Watch Series
Microcontrollers efficient, or really low-cost, and don’t need much 3 (ST Microelectronics ST33G1M2 32
compute power. bit MCU)
When you need to run diverse applications or deal Nest thermostat (Arm Cortex A8),
CPUs
with larger memory or compute challenges. Amazon Echo Show (Intel Atom x5)
When you benefit from parallelism or have need to Many (proprietary); smart automotive
FPGAs reprogram logic in the field, and are at low (eg plug-in hybrid), aerospace
production volumes. More expensive than ASICs. applications, prototyping ASICs.
When you need and can afford to pay millions to Many (proprietary); edge devices,
ASICs
fabricate your own chip. High production volumes. sensor/actuator control, etc.
When your application is data-intense, and Tesla Autopilot 2.0 ECU (Nvidia PX2
GPUs graphics-oriented, or can be transformed into a platform, which uses NVIDIA GP106
highly-parallel many-core problem (ML/AI). GPU)
When you need general and application-specific Samsung Galaxy smartphone (Exnyos
SoC compute but also a compact size, your domain is 8 Octa SoC), Apple iPhone XS (Apple
one where there is an SoC and prices are low. A12 Bionic ARM-Based)
Example Products

CPUs
Nike Hyperadapt LG E8 Amazon Echo Show Moverio BT-300
(smart speaker with screen) Fitbit Ionic
(self-lacing bluetooth shoes) (55-65” OLED TV) (smart glasses)
ARM Cortex A8 CPU (GPS smartwatch)
ARM Cortex M4 CPU LG α9 CPU Intel Atom x5 CPU
ARM Cortex A8 CPU

Microcontrollers
HTC Vive Parrot AR.Drone 2.0 Honeywell Water Alarm Pleo Smart Dinosaur Amazon Fire TV
(VR Goggles) (Drone) (Freeze/Leak detector) (AI Toy) (digital media player)
ARM Cortex M0 Microchip PIC24 Microchip PIC12 Toshiba TMP86FH47 8-bit TI MSP430F5435A
Memory/Storage
• No “universal memory” (yet)
• So best way to build something is use a mix of technologies

• Usage characteristics of memories:


• May be easily writeable (RAM) or hard to write more than once (ROM)
• May lose contents when not powered (volatile), or may retain contents
when powered off (non-volatile)

• Performance characteristics of memories:


• Max erase cycles, cost per byte, speed, density, heat, energy efficiency
Memory Technologies
Type Volatile? Writeable? Speed Cost per Notes
byte
Static random-access Yes Yes Fast Expensive Commonly used in CPU caches. Can reduce
memory (SRAM) power consumption when idle.
Dynamic random- Yes Yes Moderate Moderate Requires constant power to for external
access memory memory refresh circuit.
(DRAM)
Masked ROM No No Fast Cheap Contents programmed by IC manufacturer
(Masked read-only during lithography process. More compact
memory) than any other kind of memory, but very
high 1-time masking cost.
Electrically-Erasable No Yes Fast to Expensive Commonly used as firmware. Common to
programmable ROM read, slow use EEPROM during development and switch
(EEPROM) to write to Mask ROM when design is finalized.
Flash memory No Yes Fast to Moderate Type of NVRAM/EEPROM. Found in memory
read, slow cards, flash drives, SSDs. Limited write cycles.
to write
NVRAM No Yes Fast Expensive Ferroelectric RAM is main type to enter
production.
IoT Platform Design
How can we design things out of these
components?
• You now know many components you can use

• You now know how to connect them together with wires

• But how do you build actual physical things?

• Next: let’s study some real platforms to get a sense of that


• Let’s start with the Arduino platform
Arduino Platform
• Hobbyist prototyping platform for IoT devices
• Simplifies some aspects of programming and circuit development

• You can do so many things with it


• Can plug in virtually unlimited sensors/indicators/displays/motors/etc.

• Started as a research project at Interaction Design Institute in


Ivrea, Italy
• Name comes from a bar in Italy where founders used to meet
• Project goal: develop a cheap and easy way for novices to create
devices that interact with their environment using sensors/actuators
Arduino Technical Components
• Arduino provides software to simplify development
• Interactive development environment
• Collection of libraries to simplify code

• Code written in C++


• Program is called a “sketch,” saved with extension “.ino”

• Multiple board designs, using various


microprocessors/controllers
• Both hardware (Creative Commons) and software (GPL) is open-source
I2C Communication
In-Circuit Serial Analog Reference
Programming Header Voltage Digital Pins
For ATmega16 Ground
Serial Communications
Reset Button

Transmit/Receive LEDs PWM Pins (output)


5V On Indication LED
USB Port

ATmega16 In-Circuit Serial


Programming Header
16.000 MHz Crystal Oscillator For ATmega328
Voltage
Regulator
ATmega328
(main processor)

DC Power Jack

Diode (protects
Power against reverse
Communication polarity on DC Power Source Analog Pins
Compute input)
I2C Communication
In-Circuit Serial Analog Reference
Programming Header Voltage Digital Pins
For ATmega16 Ground
Serial Communications
Reset Button

Transmit/Receive LEDs PWM Pins (output)


5V On Indication LED
USB Port

ATmega16 In-Circuit Serial


Programming Header
16.000 MHz Crystal Oscillator For ATmega328
Voltage
Regulator
ATmega328
(main processor)

DC Power Jack

Diode (protects
Power against reverse
Communication polarity on DC
Compute Power Source Analog Pins
input)
Power
Debugging/
Emulation
Timing
Computation
(CPU/Core)
Memory

I/O and
Communication
Official Arduino Boards

Arduino Uno Rev3 Arduino Uno Wi-Fi Rev2 Arduino Nano Arduino Mega
(most popular Arduino board) (Similar to Uno, but has Wi-Fi) (smaller Arduino board) (larger Arduino board)

ATmega328P@16MHz ATmega4809@16MHz ATmega328 ATmega2560


ECC608 crypto co-processor
14 digital I/O pins (6 PWM), 6 analog inputs 22 digital I/O pins (6 PWM), 8 analog 54 digital I/O pins (15 PWM), 16 analog
14 digital I/O pins (5 PWM), 6 analog inputs inputs inputs
USB, power jack, ICSP header
USB, power jack, ICSP header USB, ICSP header 256KB Flash, 8KB SRAM, 4KB EEPROM
32KB Flash, 2KB SRAM, 1KB EEPROM
48KB Flash, 6KB SRAM, 0.25KB EEPROM 32KB Flash, 2KB SRAM, 1KB EEPROM USB, power jack, ICSP header
2.7”x2.1”, 25 grams
2.7”x2.1”, 25 grams 0.7”x1.7”, 7 grams 4”x2.1”, 37 grams
Third-Party Arduino-Compatible Boards

Ardusat
Elegoo Uno Adafruit Trinket FlyDuino KISS FC (domain-specific Arduino)
(lower-cost Arduino) (small Arduino) (domain-specific Arduino)
Nanosatellite based on CubeSat standard
Fully compatible; uses faster control Small (1.2”x0.6”), light (1.85 grams). Arduino-compatible board designed for
processor (ATMega16U2) Good for wearables (e.g., necklaces), dog autonomous navigation and auto- Public allowed to use platform via
tracking, covert computing, etc. piloting of aircraft. ArduSatSDK while in space
Other boards exist at <$3
Attiny85@16MHz, 8KB Flash, 512bytes Flight control firmware monitors and Includes a 3-axis magnetometer, a 3-axis
SRAM, 512bytes EEPROM performs telemetry of motor speed gyroscope, a 3-axis accelerometer, an
(ESCs). Stabilizes flight and automates infrared temperature sensor, four
movement and tracking. temperature sensors, two luminosity
sensors (infrared and vis light), two
Geiger counters, one optical spectrometer
one 1.3MP camera
Arduino Shields

Arduino Uno + Xbee Module + SD Card Storage


Many shields are out there:
Motor drivers, cellular (e.g., GSM GPRS), data logging, GPS, blank (for prototyping), LCD/Displays, Cameras,
Speakers/buzzers, sensors (e.g., temperature/humidity), pushbuttons, capacitive touchpads, IR receivers, medical sensors,
biometrics, wired ethernet, relays (high voltage), lasers, smoke detectors, joystick/game controller, MP3 players, etc.
How do we program an Arduino?

• Usually people program microcontrollers in high-level


languages

• Arduino platform makes this process even easier


• Simple IDE
• Libraries, objects (some from Arduino, some from Atmel/AVR)
How do we program an Arduino?
• Arduino sketches are C++ programs calling some extra
supporting libraries

• Arduino programming is similar to other kinds of


embedded programming
• Approaches very generalizable to other microcontrollers,
platforms, etc.
What the IDE Looks Like
Setting up Arduino:
Upload
1. To tell IDE how to reach the
Compile Arduino, choose Tools::Port:
Select COM1 or whatever
port your Arduino is
plugged into
• Windows: Device manager,
expand Ports, see where
Arduino is
• Mac: type “ls /dev/*“ in
terminal, use port number listed
for /dev/tty.usbmodem* or
/dev/tty.usbserial*
• Linux: type “ls /dev/ttyUSB*“
or “/dev/ttyACM*“
2. To tell IDE how to talk to the
Arduino, tell it the type of
board under Tools:Board
• For Uno or Uno-compatible
board select Arduino/Genuino
Message window Uno
Where you write
(compilation errors etc.)
your program
Writing an Arduino Program
• Two main functions, executed
by bootloader
• setup() – executed once on
startup
• loop() – run repeatedly, forever
• Functions you can call (digital
I/O):
• pinMode(<pin>,<type>) –
configures pin as detecting an
input signal (INPUT) or
outputting a signal (OUTPUT).
Can also enable an internal
pullup resistor (INPUT_PULLUP)
• digitalWrite(<pin>,<value>) –
sets pin state (HIGH or LOW)
• <int> = digitalRead() – reads
pin state (HIGH or LOW)
Uploading/Running an Arduino Program
Three key steps:
1. Verify/Compile your code
• Sketch::Verify/Compile, or hit the check mark button
2. Upload bootloader to board
• Code that runs before main program
• Arduino bootloader enables re-programming flash memory over serial
port
• Previous step takes care of this for you
3. Upload your code to board
• Sketch::Upload, or hit right-arrow button
Uploading/Running an Arduino Program
• Program will just start running automatically
• Troubleshooting ideas:
• Make sure you have right board type and port selected
• Check for short circuits, hot components, smoky smells
• Use a multimeter to check output values and current
loads
• Use serial monitor (Serial.println()) to log progress
• Use a simulator/emulator
A Few More Example Sketches
Suppose you…
• Need to debug an Arduino
• How do you know what’s going on inside?
• Can use LEDs but that’s kind of hard
• May need to log and collect data

• Want to measure/send non-digital (analog)


values?
• E.g., read output from a sensor, control speed of
motor
Serial Programming, Analog I/O
• Serial functions:
• begin(<speed>) – sets
data rate (baud)
• println(<value>) – outputs
data as ASCII text to serial
port
• <int>=read() – reads one
byte from serial port,
returns -1 if no data to
read
• Warning: data is written to
USB *and* pins 0/1 – will
clash with other uses of
pins 0/1
• Also see: hardware
debugging (debugWire)
Serial Programming, Analog I/O
• Analog I/O functions:
• <int>=analogRead(<pin>)
reads voltage from specified
input pin as value between
[0,1023]
• analogWrite(<level>) – sends
voltage level (PWM) to pin,
specified as range from 0
(always off) to 255 (always on)
• analogReference() – sets what
1023 corresponds to for analog
input – DEFAULT (5V),
INTERNAL (1.1V), EXTERNAL
(voltage applied to AREF pin),
etc.
Suppose You…
• Want to send or read digital data
• E.g., you have an external component with a
microcontroller

• Measure pulses
• Measure how long user holds down a button, how
long car was blocking highway laser sensor

• Generate tones
• Alarm sounds when burglar steps on smart floor,
make music play when you walk into a room
Digital Streaming I/O Functions
• Functions for shifting data in/out:
Diagram Function name(s) What it does Notes

tone(pin, frequency, Generates a square wave of the Also see: noTone(pin) – stops
Frequency
[duration]) specified frequency in Hz (with generation of square wave on
50% duty cycle). Can connect to specified pin.
Example: piezo buzzer or speaker to play
tone(8,500) tones.

pulseIn(pin, value, [timeout]) Measures duration of next received Returns 0 if no complete pulse was
pulse. E.g. If value is HIGH, received before timeout. Works on
Example: pulseIn() waits for pin to transition pulses from 10µs → 3 minutes.
unsigned long duration = LOWHIGH, starts timer, and ends
Times To pulseIn(3,HIGH) on transition HIGHLOW.
from here here

byte incoming = Shifts a byte of data in from data Also see: shiftOut(dataPin,
Data shiftIn(dataPin, clockPin, pin, with values read on rising clockPin, bitOrder, value) – shifts
bitOrder) edges of clock pin. out the byte value, driving both
data and clock pins appropriately.
Example:
Clock byte value =
shiftIn(6,7,MSBFIRST)

Read Read Read


Suppose You…
• Want to do multiple things at once
• Run autopilot for drone, but user gives you a new
command
• Display camera feed, but pop up character pad
when user touches screen
Interrupts
• attachInterrupt(pin,
function, mode) – associates
function pointer to be called
on pin level change
• Modes: LOW, CHANGE, RISING,
FALLING
• digitalPinToInterrupt(pin) –
converts pin # to interrupit #
• noInterrupts()/interrupts() –
enables/disables interrupts
• Notes:
• Only one ISR can run at a time
• Next ISR to run selected
according to priority
• Shared variables must be
declared volatile
What if something goes wrong?
• Program crashes or hangs in the field
• It is 10,000 feet in the air or floating in the
arctic
• Your plant watering system locks up when
you’re on vacation
• You can’t get out there to help it
Watchdog Timer
• “Deadman’s switch” hardware-
supported timer
• Counter counts up continuously in
hardware
• If not reset within timeout, board
is rebooted
• wdt_enable(time) – sets timeout
• wdt_reset() – resets timer
• Levels supported by ATmega328:
15ms, 30ms, 60ms, 120ms,
250ms, 500ms, 1s, 2s, 4s, 8s
What if you are running out of power?
• May need to operate for long
times on low battery
• May be reaching end of battery
life
• May not be able to replace
battery
• May not even have a battery –
energy harvesting and sources
drying up
Sleep Mode
• Can be woken up by timer, pin
level change
• set_sleep_mode(mode) – sets
how deeply to sleep
• Sleep modes:
SLEEP_MODE_PWR_DOWN (most
savings), SLEEP_MODE_STANDBY,
SLEEP_MODE_PWR_SAVE,
SLEEP_MODE_ADC,
SLEEP_MODE_IDLE (least savings)
• Disables brown-out detection,
timers, analog-digital conversion
• sleep_enable()/sleep_disable() –
enables/disables safety “sleep” bit
on microcontroller
• sleep_mode() – triggers sleep
Sleep Mode
• Can replace delay() calls, use
when not doing anything
important
• Doesn’t actually save much
power on some Arduinos
because of voltage regulator
• However you can use this
concept when programming
other platforms
• Other ways to save power:
avoid linear regulator, lower
voltage (5V to 3.3V reduces
~4mA to ~1mA), reduce clock
speed
What if you need to store some
information?
• May need to log data
• Could send to Serial, but what if not
attached to a computer?
• Could send to Wi-Fi, but what if no
clearance to send?
• Need to retain state across power
outages/resets
• Storing configurations and user
preferences
Arduino Storage
EEPROM SD Card
• Can access memory
and storage. Examples:
• Write to EEPROM
(byte-addressable):
• read()/write()
• clear() – clear entire
EEPROM
• crc() – calculates CRC of
entire EEPROM
contents
• Write to SD card (file-
based storage):
• Similar to POSIX:
open()/close()/println()/
read()/write()/mkdir()/re
move()/rmdir()
References
• Mouser Electronic / EasyEDA
• BatteryJunction.com
• Uxcell
• E-Projects
• NTE Electronics / https://www.ntepartsdirect.com/
• Jameco Electronics / https://www.jameco.com/
• Digi-Key Electronics / https://www.digikey.com/
• Dilson Enterprises
• Regency Semiconductors
References
• Nest
• TickPlant
• Amazon
• Adafruit
• FilipeFlop Componentes Eletrônicos
• Anker
• Transfer Multisort Elektronik
• SparkFun Electronics / https://www.sparkfun.com/
• DJI
• Yale Security
• Open Bionics
References
• Banggood.com
• Active Robots / https://www.active-robots.com/
• Davis Instruments / https://www.davisinstruments.com/
• Honda
• Anki
• Parallax Inc. / https://www.parallax.com/
• HT Sensor / http://htc-sensor.com/
• AIRSENSE Analytics GmbH / http://airsense.com/en
• Integrated Device Technology, Inc. / https://www.idt.com/
References
• Texas Instruments
• National Semiconductor
• SeekIC
• Microchip
• Espressif Systems
• Adafruit / https://www.adafruit.com/
• NikeLG Electronics
• Moverio
• Fitbit
• HTC Vive
References
• Parrot http://www.parrot.com
• Honeywell
• Pleo
• ElectronicSurplus.ca
• Arduino.cc

You might also like