EEM336 Week10 Sensors ADC
EEM336 Week10 Sensors ADC
EEM336 Week10 Sensors ADC
and
Analog to Digital Conversion
TODO: Motors and Relays
Week 6: Sensors 1
Introduction
• Microprocessor systems must interact with their
environment. They use sensors and actuators in
order to do this.
• Sensors and actuators are actually transducers
A transducer is a device that converts
one physical quantity into another
– examples include:
• a mercury-in-glass thermometer (converts temperature
into displacement of a column of mercury)
• a microphone (converts sound into an electrical signal).
• a motor converts electrical energy to mechanical energy.
• We will look at sensors and actuators in this
lecture.
Week 6: Sensors 2
Terminology
• Transducers convert one form of energy into another
• Sensors/Actuators are input/output transducers
• Sensors can be passive (e.g. change in resistance) or active
(output is a voltage or current level)
• Sensors can be analog (e.g. thermocouples) or digital (e.g.
digital tachometer)
Amplifier Speaker
Microphone
Sensor Actuator
3
Sensors
• Almost any physical property of a material that
changes in response to some excitation can be
used to produce a sensor
• Widely used sensors include those that are:
– resistive
– inductive
– capacitive
– piezoelectric
– photoresistive
– elastic
– thermal
Week 6: Sensors 4
Transducer types
Quantity being Input Device Output Device
Measured (Sensor) (Actuator)
pn-junction sensor
Week 6: Sensors 8
Temperature Sensors
• Bimetallic switch (electro-mechanical) – used in
thermostats. Can be “creep” or “snap” action.
Creep-action: coil or spiral that unwinds or coils with changing
temperature
9
Thermocouples
• Two dissimilar metals induce voltage difference (few mV
per 10K) – electro-thermal or Seebeck effect
10
11
Light Sensors
• Photovoltaic
– light falling on a pn-junction A typical photodiode
Week 6: Sensors 12
Light Sensors
• Photoconductive
– such devices do not produce
electricity, but simply change A light-dependent resistor (LDR)
their resistance
– photodiode (as described
earlier) can be used in this
way to produce a linear
device
– phototransistors act like
photodiodes but with greater
sensitivity
– light-dependent resistors
(LDRs) are slow, but
respond like the human eye
Week 6: Sensors 13
Light sensors: photoconductive cells
• Light dependent resistor (LDR) cell
14
Light level sensitive switch
15
Photojunction devices
phototransistor
photodiode
16
Photovoltaic Solar Cells
• Can convert about 20% of light power into electricity
• Voltage is low (diode drop, ~0.6V)
17
Photomultiplier tubes (PMT)
• Most sensitive of light sensors (can detect individual
photons)
• Acts as a current source
electrons
18
Force Sensors
Direction of sensitivity
• Strain gauge
– stretching in one
direction increases
the resistance of the A strain gauge
device, while
stretching in the
other direction has
little effect
– can be bonded to a
surface to measure
strain
– used within load
cells and pressure
sensors
Week 6: Sensors 19
Displacement Sensors
• Potentiometers
– resistive potentiometers are one of the most widely
used forms of position sensor
– can be angular or linear
– consists of a length of resistive material with a
sliding contact onto the resistive track
– when used as a position transducer a potential is
placed across the two end terminals, the voltage on
the sliding contact is then proportional to its
position
– an inexpensive and easy to use sensor
Week 6: Sensors 20
Displacement Sensors
• Inductive proximity sensors
I. coil inductance is greatly
affected by the presence of
ferromagnetic materials
II. here the proximity of a
ferromagnetic plate is
determined by measuring
the inductance of a coil
III. we will look at inductance Inductive proximity sensors
in later lectures
Week 6: Sensors 21
Displacement Sensors
• Switches
– simplest form of digital displacement sensor
• many forms: lever or push-rod operated
microswitches; float switches; pressure switches;
etc.
22
• Absolute position encoders
– a pattern of light and dark strips is printed on to a
strip and is detected by a sensor that moves along
it
• the pattern takes the form of a series of lines as shown
below
• it is arranged so that the combination is unique at each
point
• sensor is an array of photodiodes
Week 6: Sensors 23
Displacement Sensors
• Incremental position encoder
– uses a single line that alternates black/white
• two slightly offset sensors produce outputs as shown
below
• detects motion in either direction, pulses are counted
to determine absolute position (which must be
initially reset)
Week 6: Sensors 24
Displacement Sensors
Week 6: Sensors 25
Positional Sensors: potentiometer
Can be Linear or Rotational
Processing circuit
26
Positional Sensors: LVDT
Linear Variable
Differential
Transformer
27
Positional Sensors: Inductive Proximity Switch
• Detects the presence of metallic objects (non-contact) via changing
inductance
• Sensor has 4 main parts: field producing Oscillator via a Coil;
Detection Circuit which detects change in the field; and Output
Circuit generating a signal (NO or NC)
Used in traffic lights (inductive loop buried under the road). Sense objects in dirty
environment. Does not work for non-metallic objects. Omni-directional.
28
Positional Sensors: Rotary Encoders
• Incremental and absolute types
• Incremental encoder needs a counter, loses absolute
position between power glitches, must be re-homed
• Absolute encoders common in CD/DVD drives
29
Motion Sensors
• Motion sensors measure quantities such as
velocity and acceleration
– can be obtained by differentiating displacement
– differentiation tends to amplify high-frequency noise
• Alternatively can be measured directly
– some sensors give velocity directly
• e.g. measuring frequency of pulses in the counting
techniques described earlier gives speed rather than
position
– some sensors give acceleration directly
• e.g. accelerometers usually measure the force on a mass
Week 6: Sensors 30
Motion sensors/transducers
• Switches, solenoids, relays, motors, etc.
• Motors
• DC
• Brushed/brushless Stepper motor
• Servo
• Stepper motors
• AC
32
Sound Sensors
• Microphones
– a number of forms are available
• e.g. carbon (resistive), capacitive, piezoelectric and
moving-coil microphones
• moving-coil devices use a magnet and a coil
attached to a diaphragm – we will discuss
electromagnetism later
Week 6: Sensors 33
Sound transducers
speaker
microphone
34
Acceloremeter and
Gyroscope Basics
MEMS
Week 6: Sensors 35
Acceleration Fundamentals
• What is Acceleration?
– Definition: the time rate of change of velocity. A.K.A.: the
time rate of change of the time rate of change of distance
• What are the units?
– Acceleration is measured in (m/s)/s
• What is a “g”?
– A “g” is a unit of acceleration equal to Earth’s gravity at sea
level (1 g = 9.81 m/s2)
• What is the time rate of change of velocity?
– When plotted on a graph, velocity is the slope of
distance versus time
– Acceleration is the slope of velocity versus time
TI/RTOS 36
How to find velocity from distance traveled
1,200
V(t=1.160) = 0 m/s
1,000
Distance Traveled (meters)
0,800
0,600
0,400
0,000
0,000 0,200 0,400 0,600 0,800 1,000 1,200 1,400
-0,200
Time (seconds)
TI/RTOS 37
TI/RTOS 38
TI/RTOS 39
Acceleration in Human terms
TI/RTOS 41
Sensor Types
• Capacitive
– -Metal beam or micromachined feature produces
capacitance; change in capacitance related to
acceleration
• Piezoelectric
– -Piezoelectric crystal mounted to mass –
voltage output converted to acceleration
• Piezoresistive
– Beam or micromachined feature whose resistance
changes with acceleration
TI/RTOS 42
Sensor Types
• Hall Effect
– Motion converted to electrical signal by sensing of
changing magnetic fields
• Magnetoresistive
– Material resistivity changes in presence of
magnetic field
• Heat Transfer
– Location of heated mass tracked during
acceleration by sensing temperature
TI/RTOS 43
MEMS sensors
• Microelectromechanical systems (MEMS, also written
as micro-electro-mechanical, MicroElectroMechanical
or microelectronic and microelectromechanical systems
and the related micromechatronics) is the technology of
microscopic devices, particularly those with moving
parts.
Week 6: Sensors 44
MEMS accelerometer
• A MEMS accelerometer differs from integrated circuits in that a “proof
mass” is machined into the silicon. Any displacement of the component
causes this mass to move slightly according to Newton’s second law,
and that change is detected by sensors. Usually the proof mass disturbs
the capacitance of a nearby node; that change is measured and filtered.
https://howtomechatronics.com/how-it-works/electrical-engineering/mems-accelerometer-gyrocope-magnetometer-arduino/
Week 6: Sensors 45
MEMS Gyroscope
• The gyroscope measures angular rate using the Coriolis Effect.
When a mass is moving in a particular direction with a particular
velocity and when an external angular rate will be applied as
show with the green arrow a force will occur, as show with the
blue red arrow, which will cause perpendicular displacement of
the mass. So similar to the accelerometer, this displacement will
cause change in capacitance which will be measured, processed
and it will correspond to a particular angular rate.
https://howtomechatronics.com/how-it-works/electrical-engineering/mems-accelerometer-gyrocope-magnetometer-arduino/
Week 6: Sensors 46
Typical Applications
• Tilt / Roll
• Vibration / “Rough-road” detection
– Can be used to isolate vibration of mechanical system from
outside sources
• Vehicle skid detection
– Often used with systems that deploy “smart” braking to
regain control of vehicle
• Impact detection
– To determine the severity of impact, or to log when an
impact has occurred
• Input / feedback for active suspension control systems
– Keeps vehicle level
TI/RTOS 47
Important Setup Rules
• Rigid Mounting
– Bees Wax
– Double Sided tape
– Bolt(s)
• No Loose Wires
– Loose wires can create false signals
– Secure wires firmly to mounting body
• Weight of Sensor
– Should be approximately an order of magnitude less than
object being measured
• Example: CAS = 47g; accelerating object should be more than 470g
• Don’t drop the sensor!
– Extreme jarring accelerations can cause permanent errors in
device output TI/RTOS 48
MPU6050
• MPU6050: Gyroscope +
Accelerometer
– ±2g, ±4g, ±8g and ±16g
– ±250, ±500, ±1000, and
±2000°/sec
• VCC and GND for power
supply:3-5v
• SCL and SDA for I2C
communication with MCU
• XCL and XDA to connect
magnetic sensor
TI/RTOS 49
SENSOR
INTERFACING
Week 6: Sensors 50
Sensor Interfacing
• Switches
– switch interfacing is also simple
• can use a single resistor as below to produce a
voltage output
• all mechanical switches suffer from switch bounce
Week 6: Sensors 51
Sensor Interfacing
• Resistive devices
– can be very simple
• e.g. in a potentiometer, with a fixed
voltage across the outer terminals, the
voltage on the third is directly related
to position
• where the resistance of the device
changes with the quantity being
measured, this change can be converted
into a voltage signal using a potential
divider – as shown
• the output of this arrangement is not
linearly related to the change in
resistance
Week 6: Sensors 52
Sensor Interfacing
• Whetstone bridge
– The Wheatstone bridge
illustrates the concept of a
difference measurement, which
can be extremely accurate.
– Although today digital
multimeters provide the
simplest way to measure a
resistance. The Wheatstone
Bridge can still be used to
measure very low values of
resistances down in the milli-
Ohms range.
– we can use the Wheatstone
Bridge Circuit to interface
various transducers and sensors
to these amplifier circuits.
Week 6: Sensors 53
Sensor Interfacing
• In the figure Rx is the
resistor to be measured if If
all four resistor values and the
supply voltage (Vs) are
known.
Week 6: Sensors 54
Capacitance and Inductance
Measurements
Week 6: Sensors 55
Describing Sensor Performance
• Range
– maximum and minimum values that can be measured
• Resolution or discrimination
– smallest discernible change in the measured value
• Error
– difference between the measured and actual values
• random errors
• systematic errors
• Accuracy, inaccuracy, uncertainty
– accuracy is a measure of the maximum expected
error
Week 6: Sensors 56
Describing Sensor Performance
• Precision
– a measure of the lack of random errors (scatter)
Week 6: Sensors 57
Describing Sensor Performance
• Linearity
– maximum deviation from a ‘straight-line’
response
– normally expressed as a percentage of the full-
scale value
• Sensitivity
– a measure of the change produced at the output
for a given change in the quantity being
measured
Week 6: Sensors 58
Key Points
• A wide range of sensors is available
• Some sensors produce an output voltage related to
the measured quantity and therefore supply power
• Other devices simply change their physical
properties
• Some sensors produce an output that is linearly
related to the quantity being measured, others do
not
• Interfacing may be required to produce signals in
the correct form
59
Instrumentation Resources
• https://www.youtube.com/watch?v=hijgA8
A-O64
• https://www.youtube.com/watch?v=9opuvL
XAetI
• Book: «Capacitive Sensors: Design and
Applications», Writer: Larry K. Baxter,
John Wiley & Sons, 3 September 1996.
Week 6: Sensors 60
Actuators
Motors, Relays, etc
Week 6: Sensors 61
Motors
• When moving or rotating objects with
microcontrollers, three kinds of motors are
generally used:
– DC motors,
– RC servomotors
– Stepper motors.
• Motors are used to convert electrical energy
to mechanical energy. Induction is basic
principle behind the operation of motors.
Week 6: Sensors 62
Motors
• If magnets are mounted on a rotating shaft
surrounded by the wire with a current flowing
on it, you obtain a motor. When the magnets are
alternately attracted to one magnet and repulsed
by the other, the shaft rotates and a circular
motion is obtained.
https://itp.nyu.edu/physcomp/lessons/dc-motors/dc-motors-the-basics/
Week 6: Sensors 63
Analog To Digital
Convertors
Analog signals
• A signal representing
continuous signal that
contains time-varying
quantities, for example
– Pressure of sound waves
induce voltage on
microphones
– Temperature of the air
– Voltage across an analog
circuit element, resistor,
capacitor, transistor, etc
Sound generated by vibrating membrane (wikipedia)
Week 6: Sensors 65
What is Analog to Digital Conversion?
• Analog to Digital conversion is to convert
an analog quantity into a digital number.
• Analog input is typically sampled regularly
at intervals of T or at irregular time
intervals, so the result is a sequence digital
numbers.
Week 6: Sensors 66
Analog to Digital Conversion
• Have an input you wish to measure and input in digital
form
–Measure voltage/current
–Indirectly measure other properties such as pressure,
temperature
–Value bounded between minimum and maximum
–The output is a digital number that represents the input value
• MSP430 has a built in A/D sub-system.
Analog Voltage
A/D 8/10 bit
V(t)
Convertor number
Quantization
• Let 0 £ V(t) < 5V
• Assume that ADC does 3 bits of conversion, in
other words, 23 = 8 intervals.
• Each voltage interval is assigned a quantization
code Any voltage
between 0V and
0.625V maps to bit
sequence 000
VINT
Time TINT
Dual Slope Integrating ADC
VIN = VREF
TINT TDE-INT
VINT TINT = fixed
TDE-INT α VIN
VREF
TINT TDE-INT Time
R + L10
-- Digital
Precision Thermometer Decoder D1
R + L01 code D0
Resistor --
Divider Conversion
R + L00 output
Network --
R
Comparators
Notes
+ L111
0
• Digital thermometer code --
+ L110
resembles to the mercury --
0
thermometer. If there is a 1 + L101
1
--
in the code, all of the L100
+
1
inputs below should be 1. --
+ L011
• Decoder determines the --
1
uppermost 1 and outputs its + L010
1
--
code as the result of the L001
+
AD convertor --
1
+ L000
--
1
Notes
• The comparators are typically a cascade of wideband
low gain stages. They are low gain because at high
frequencies it's difficult to obtain both wide bandwidth
and high gain.
• They are designed for low voltage offset, such that the
input offset of each comparator is smaller than a LSB
of the ADC. Otherwise, the comparator's offset could
falsely trip the comparator, resulting in a digital output
code not representative of a thermometer code.
• A regenerative latch at each comparator output stores
the result. The latch has positive feedback, so that the
end state is forced to either a "1" or a "0".
Notes
• When the input signal changes before all the
comparators have completed their decision, the ADC
performance is adversely impacted.
• Measuring spurious free dynamic range (SFDR) is
another good way to observe converter performance.
SFDR is the ratio of the power of the maximum signal
component and the power of the noise component.
• The most serious impact is a drop in signal-to-noise
ratio plus distortion (SINAD) as the frequency of the
analog input frequency increases. It is the ratio of total
received power of the signal to the noise-plus-
distortion power.
• The sampling frequency can be improved by adding a
track-and-hold (T/H) circuit in front of the ADC.
Notes
• The sampling frequency can be improved by adding a
track-and-hold (T/H) circuit in front of the ADC.
Pipelined ADC
• They can provide sampling rates from a few
megasamples per second (MS/s) up to
100MS/s+, with resolutions from 8 to 16 bits.
• They offer the resolution and sampling rate to
cover a wide range of applications.
• Popular areas of application are CCD imaging,
ultrasonic medical imaging, digital receiver, base
station, digital video (for example, HDTV),
xDSL, cable modem, and fast Ethernet.
4 bit
Vin Stage 1 Stage 2 Stage 3 Stage 4 flash ADC
3 3 3 3 4
Time alignment and digital error correction
• The analog input is first
sampled and held steady by a
12 bit result sample-and-hold (S&H),
while the flash ADC in stage
one quantizes it to three bits.
STAGE • The 3-bit output is then fed to
+ a 3-bit DAC and the analog
V Sample &
Σ x4 output is subtracted from the
Hold
- input.
• This "residue" is amplified by
3 bit 3 bit four and sent to the next
flash ADC flash DAC
stage.
• This residue moves through
3 bits the pipeline, providing three
bits per stage
• The last stage resolves the
last 4LSB bits.
Ramp Counter A/D Conversion
• Ramp/Counter with analog comparator and D/A
Start
Conversion
Reset
- End of
Conversion
8bit D/A
Counter Converter +
Vin
CLOCK
Track&Hold
tAD
tAD : Aperture delay is the time defined between the falling edge of the sampling
clock and the instant when an actual sample is taken
tAJ : Aperture jitter is the sample to sample variation in the aperture delay
4 bit Conversion Timing
As the time passes, SAR ADC pin points the input voltage
and determines a closer match to the input
Vref
3Vref/4
Vin
Vref/2
Vref/4
http://www.maxim-ic.com/appnotes.cfm/an_pk/2094/
Preference Guide
• Flash: Ultra-High Speed, high power consumption
• SAR: Medium-to-High Resolution (8-16 bits), lower
than 5Msps, low power, small form factor
• Integrating: Monitoring DC signals, high resolution,
low power consumption, good noise performance.
• Pipeline: High speed, 100+ Msps, 8-16 bits, lower
power consumption than flash ADCs.
• Sigma-Delta: High resolution, low to medium speed,
no precision external components, simultaneous
50/60Hz rejection, digital filter for reducing anti-
aliasing.
Disadvantages
• Flash: Sparkle codes / metastability, high power
consumption, large size, expensive.
• SAR: Speed limited to ~5Msps. May require
anti-aliasing filter.
• Integrating: Slow Conversion rate. High
precision external components required to
achieve accuracy.
• Pipeline: Parallelism increases throughput at the
expense of power and latency.
• Sigma-Delta: Higher order (4th order or higher)
- multibit ADC and multibit feedback DAC.
Conversion Times
• Flash: Conversion Time does not change with
increased resolution.
• SAR: Increases linearly with increased
resolution.
• Integrating: Conversion time doubles with
every bit increase in resolution.
• Pipeline: Increases linearly with increased
resolution.
• Sigma-Delta: Tradeoff between data output
rate and noise free resolution.
Resolution
• Flash: Component matching typically limits
resolution to 8 bits.
• SAR: Component matching requirements double
with every bit increase in resolution.
• Integrating: Component matching does not
increase with increase in resolution.
• Pipeline: Component matching requirements
double with every bit increase in resolution.
• Sigma-Delta: Component matching requirements
double with every bit increase in resolution.
Size
• Flash: 2N-1 comparators, die size and power
increases exponentially with resolution.
• SAR: Die increases linearly with increase in
resolution.
• Integrating: Core die size will not materially
change with increase in resolution.
• Pipeline: Die increases linearly with increase
in resolution.
• Sigma-Delta: Core die size will not materially
change with increase in resolution.
MSP430 ADC12_B
Analog to Digital
Convertor
Week 6: Sensors 96
ADC12_B | Overview
• Up to 200ksps The reference voltage is the
• Ultra Low Power maximum value that the
Operation
ADC can convert.
– 63µA in single ended
mode
– 95µA in differential
mode
REF Voltage Select
• Works down to 1.8V I
/
• 8 differential/ 16 single- P
ended inputs M
u
• Internal Battery and l Sam
Temperature Sensor t ple / A/D
i Clock
• Specialized Window p
Hold Converter
97
MSP430 ADC12_B
• The ADC12_B module supports fast 12-bit
analog-to-digital conversions. The module
implements a 12-bit SAR core, sample select
control, and up to 32 independent conversion-
and-control buffers.
• The conversion-and-control buffer allows up to
32 independent analog-to-digital converter
(ADC) samples to be converted and stored
without any CPU intervention.
Week 6: Sensors 98
MSP430 ADC12_B
• ADC12_B features include:
– 200-ksps maximum conversion rate at max resolution of 12
bits
– Monotonic 12-bit converter with no missing codes
– Sample-and-hold with programmable sampling periods
controlled by software or timers
– Conversion initiation by software or timers
– Software-selectable on-chip reference voltage generation (1.2
V, 2.0 V, or 2.5 V) with option to make available externally
– Software-selectable internal or external reference
– Up to 32 individually configurable external input channels
with single-ended or differential input selection available
Week 6: Sensors 99
ADC12_B
– Internal conversion channels for internal temperature sensor
and 1/2 × AVCC and four more internal channels available on
select devices (see the device-specific data sheet for
availability and function)
– Independent channel-selectable reference sources for both
positive and negative references
– Selectable conversion clock source Single-channel, repeat-
single-channel, sequence (autoscan), and repeat-sequence
(repeated autoscan) conversion modes
– Interrupt vector register for fast decoding of 38 ADC interrupts
32 conversion-result storage registers
– Window comparator for low-power monitoring of input signals
of conversion-result registers
ADC12MSC: ADC12_B multiple sample and ADC12ON: ADC12_B on. Can be modified only
conversion. Valid only for sequence or repeated when ADC12ENC = 0.
modes. Can be modified only when ADC12ENC 0b = ADC12_B off
= 0. 1b = ADC12_B on
ADC12ENC: ADC12_B enable conversion.
0b = The sampling timer requires a rising edge 0b = ADC12_B disabled
of the SHI signal to trigger each 1b = ADC12_B enabled
sample-and-convert. ADC12SC: ADC12_B start conversion.
Software-controlled sample-and-conversion start.
1b = The incidence of the first rising edge of the ADC12SC and ADC12ENC may be set together
SHI signal triggers the sampling with one instruction. ADC12SC
timer, but further sample-and-conversions are is reset automatically.
performed automatically as soon 0b = No sample-and-conversion-start
as the prior conversion is completed. 1b = Start sample-and-conversion
ADC12PDIV: ADC12_B predivider. This bit ADC12ISSH: ADC12_B invert signal sample-
predivides the selected ADC12_B clock source. and-hold.
00b = Predivide by 1 0b = The sample-input signal is not inverted.
01b = Predivide by 4 1b = The sample-input signal is inverted.
10b = Predivide by 32
11b = Predivide by 64 ADC12DIVx: ADC12_B clock divider
ADC12SHSx: ADC12_B sample-and-hold 000b = /1, 001b = /2, 010b = /3
source select (000b = ADC12SC bit) 011b = /4, 100b = /5, 101b = /6
ADC12SHP: ADC12_B sample-and-hold pulse- 110b = /7, 111b = /8
mode select. This bit selects the source of the
sampling signal (SAMPCON) to be either the ADC12SSELx: ADC12_B clock source select
output of the sampling timer or the sample - input 00b = ADC12OSC (MODOSC), 01b = ACLK,
signal directly. 0b = SAMPCON signal is sourced 10b = MCLK, 11b = SMCLK
from the sample-input signal. 1b = SAMPCON
signal is sourced from the sampling timer.
slau367o.pdf page 892 108
ADC12CTL1 ADC Ctrl Register 1
15 14 13 12 11 10 9 8
RTC RTC
ADC12CTL0_H rsvd ADC12PDIV ADC12SHSx
AIFG RDYIFG
RESET R-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
7 6 5 4 3 2 1 0
ADC12
ADC12CTL0_L ADC12DIVx ADC12SSELx ADC12CONSEQx
BUSY
RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 R-0
ADC12CONSEQx: ADC12_B conversion sequence mode select. This bit should only be
modified when ADC12ENC = 0 except to stop a conversion immediately by setting
ADC12CONSEQx = 00 when ADC12ENC = 1.
00b = Single-channel, single-conversion
01b = Sequence-of-channels
10b = Repeat-single-channel
11b = Repeat-sequence-of-channels
ADC12BUSY: ADC12_B busy. This bit indicates an active sample or conversion operation.
0b = No operation is active.
1b = A sequence, sample, or conversion is active.
ADCCTL2_H reserved
7 6 5 4 3 2 1 0
ADC12D ADC12P
ADCCTL2_L reserved ADC12RES
F WRMD
RESET R-0 R-0 RW-1 RW-0 RW-0 R-0 R-0 RW-0
ADC12RES: ADC12_B resolution. This bit ADC12PWRMD: Enables ADC low-power mode
defines the conversion result resolution. for ADC12CLK
This bit should only be modified when 0b = Regular power mode (sample rate not restricted)
ADC12ENC=0. 1b = Low power mode enable
00b = 8 bit (10 clock cycle conv. time)
01b = 10 bit (12 clock cycle conv. time)
10b = 12 bit (14 clock cycle conv. time)
11b = Reserved
ADC12DF: ADC12_B data read-back
format. Data is always stored in the binary
unsigned format.
0b: binary unsigned
1b: signed binary (2s complement)
111 slau367o.pdf page 894
ADC12CTL2 control bits
Field Bit Value Definition
ADC12PWRMD 0x0001 ADC12 Power Mode
ADC12DF 0x0008 ADC12 Data format
ADC12RES0 0x0010 ADC12 Resolution Bit: 0
ADC12RES1 0x0020 ADC12 Resolution Bit: 1
ADC12RES__8BIT 0x0000 ADC12+ Resolution : 8 Bit
ADC12RES__10BIT 0x0010 ADC12+ Resolution : 10 Bit
ADC12RES__12BIT 0x0020 ADC12+ Resolution : 12 Bit
ADC12RES_0 0x0000 ADC12+ Resolution : 8 Bit
ADC12RES_1 0x0010 ADC12+ Resolution : 10 Bit
ADC12RES_2 0x0020 ADC12+ Resolution : 12 Bit
ADC12RES_3 0x0400 ADC12+ Resolution : reserved
RESET RW RW RW RW RW RW RW RW
7 6 5 4 3 2 1 0
RESET RW RW RW RW RW RW RW RW
If ADC12DF = 0: The 12-bit conversion results are right justified. Bit 11 is the
MSB. Bits 15-12 are 0 in 12-bit mode, bits 15-10 are 0 in 10-bit mode, and bits
15-8 are 0 in 8-bit mode. If the user writes to the conversion memory registers,
the results are corrupted.
115
ADC12MCTLx Conv. Mem. Ctl
slau367o.pdf page 897
7 6 5 4 3 2 1 0
ADC12 ADC12
rsvd rsvd ADC12RSEL
WINC DIF
RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
7 6 5 4 3 2 1 0
ADC12
rsvd ADC12INCHx
EOS
RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
ADC12WINC: Comparator window enable. ADC12VRSEL : Selects combinations of VR+ and VR-
Can be modified only when ADC12ENC=0 sources as well as the buffer selection. Note: there is only
0b: comp. wind. disabled. one buffer so it can be used for either VR+ or VR-, but
1b: comparetor wind. enabled. not both. Can be modified only when ADC12ENC = 0.
ADC12DIF: Differential mode. Can be 0000b: VR+ = AVCC, VR-=AVSS
modified only when ADC12ENC = 0. 0001b: VR+=VREF buffered, VR-=AVSS
0b: single-ended mode enabled. 0010b: VR+=VeRef-, VR-=AVSS
1b: differential mode enabled. 0011b: VR+=VeREF+buffered,VR-=AVSS
ADC12EOS: End of sequence. Indicates the 0100b: VR+= VeREF+, VR- = AVSS
last conversion in a sequence. Can be 0101b: VR+= AVCC, VR-=VeREF+ buffered
modified only when ADC12ENC = 0. 0110b: VR+= AVCC, VR- = VeREF+
0b: not end of sequence 0111b: VR+=VREF buffered,VR- = VeREF+
1b: end of sequence ………..
116
ADC12MCTLx Conv. Mem. Ctl
slau367o.pdf page 897
7 6 5 4 3 2 1 0
ADC12 ADC12
rsvd rsvd ADC12RSEL
WINC DIF
RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
7 6 5 4 3 2 1 0
ADC12
rsvd ADC12INCHx
EOS
RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
ADC12INCHx: Input channel select. If even channels are set as differential, then odd channel
configuration is ignored. Can be modified only when ADC12ENC = 0
00000b = If ADC12DIF = 0: A0; If ADC12DIF = 1: Ain+ = A0, Ain- = A1
00001b = If ADC12DIF = 0: A1; If ADC12DIF = 1: Ain+ = A0, Ain- = A1
00010b = If ADC12DIF = 0: A2; If ADC12DIF = 1: Ain+ = A2, Ain- = A3
00011b = If ADC12DIF = 0: A3; If ADC12DIF = 1: Ain+ = A2, Ain- = A3
00100b = If ADC12DIF = 0: A4; If ADC12DIF = 1: Ain+ = A4, Ain- = A5
00101b = If ADC12DIF = 0: A5; If ADC12DIF = 1: Ain+ = A4, Ain- = A5
00110b = If ADC12DIF = 0: A6; If ADC12DIF = 1: Ain+ = A6, Ain- = A7
00111b = If ADC12DIF = 0: A7; If ADC12DIF = 1: Ain+ = A6, Ain- = A7
01000b = If ADC12DIF = 0: A8; If ADC12DIF = 1: Ain+ = A8, Ain- = A9
01001b = If ADC12DIF = 0: A9; If ADC12DIF = 1: Ain+ = A8, Ain- = A9
01010b = If ADC12DIF = 0: A10; If ADC12DIF = 1: Ain+ = A10, Ain- = A11
… … … …. .. ………………………… . . . .. . . . .
117
ADC12MCTLx control bits
Field Bit Value Definition
ADC12INCH0 0x0001 ADC12 Input Channel Select Bit 0
ADC12INCH1 0x0002 ADC12 Input Channel Select Bit 1
ADC12INCH2 0x0004 ADC12 Input Channel Select Bit 2
ADC12INCH3 0x0008 ADC12 Input Channel Select Bit 3
ADC12INCH4 0x0010 ADC12 Input Channel Select Bit 4
ADC12EOS 0x0080 ADC12 End of Sequence
ADC12VRSEL0 0x0100 ADC12 VR Select Bit 0
ADC12VRSEL1 0x0200 ADC12 VR Select Bit 1
ADC12VRSEL2 0x0400 ADC12 VR Select Bit 2
ADC12VRSEL3 0x0800 ADC12 VR Select Bit 3
ADC12DIF 0x2000 ADC12 Differential mode (only for even regs)
ADC12WINC 0x4000 ADC12 Comparator window enable
ADC12INCH_n n ADC12 Input Channel n
High Threshold
7 6 5 4 3 2 1 0
High Threshold
High threshold: Window comparator high threshold should only be modified when
ADC12ENC=0.
119
ADC12LO Window Comparator Low Threshold Register
slau367o.pdf page 899
7 6 5 4 3 2 1 0
Low Threshold
7 6 5 4 3 2 1 0
Low Threshold
Low threshold: Window comparator low threshold should only be modified when
ADC12ENC=0.
120
ADC12IER0 Interrupt Enable Reg. 0
slau367o.pdf page 900
7 6 5 4 3 2 1 0
ADC12 ADC12 ADC12 ADC12 ADC12 ADC12 ADC12 ADC12
IE15 IE14 IE13 IE12 IE11 IE10 IE9 IE8
RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
7 6 5 4 3 2 1 0
ADC12 ADC12 ADC12 ADC12 ADC12 ADC12 ADC12 ADC12
IE7 IE6 IE5 IE4 IE3 IE2 IE1 IE0
RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
Msp430fr5969.h
ADC12IEn interrupt enable for channel n
121
ADC12IER1 Interrupt Enable Reg. 1
slau367o.pdf page 900
7 6 5 4 3 2 1 0
ADC12 ADC12 ADC12 ADC12 ADC12 ADC12 ADC12 ADC12
IE31 IE30 IE29 IE28 IE27 IE26 IE25 IE24
RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
7 6 5 4 3 2 1 0
ADC12 ADC12 ADC12 ADC12 ADC12 ADC12 ADC12 ADC12
IE23 IE22 IE21 IE20 IE19 IE18 IE17 IE16
RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
122
ADC12IER0-1 Interrupt Enable
Field Bit Value Definition
ADC12IE0 0x0001 ADC12 Memory 0 Interrupt Enable
ADC12IE1 0x0002 ADC12 Memory 1 Interrupt Enable
ADC12IE2 0x0004 ADC12 Memory 2 Interrupt Enable
ADC12IE3 0x0008 ADC12 Memory 3 Interrupt Enable
ADC12IE4 0x0010 ADC12 Memory 4 Interrupt Enable
ADC12IE5 0x0020 ADC12 Memory 5 Interrupt Enable
ADC12IE6 0x0040 ADC12 Memory 6 Interrupt Enable
ADC12IE7 0x0080 ADC12 Memory 7 Interrupt Enable
........ ..... ........
ADC12I28 0x1000 ADC12 Memory 28 Interrupt Enable
ADC12I29 0x2000 ADC12 Memory 29 Interrupt Enable
ADC12I30 0x4000 ADC12 Memory 30 Interrupt Enable
ADC12I31 0x8000 ADC12 Memory 31 Interrupt Enable
reserved
RESET R0 R0 R0 R0 R0 R0 R0 R0
7 6 5 4 3 2 1 0
ADC12 ADC12 ADC12 ADC12 ADC12 ADC12
reserved reserved
RDYIE TOVIE OVIE HIIE LOIE INIE
RESET R0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 R0
125
ADC12IFGR1 Interrupt Flag Reg. 1
slau367o.pdf page 900
7 6 5 4 3 2 1 0
ADC12 ADC12 ADC12 ADC12 ADC12 ADC12 ADC12 ADC12
IFG31 IFG30 IFG29 IFG28 IFG27 IFG26 IFG25 IFG24
RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
7 6 5 4 3 2 1 0
ADC12 ADC12 ADC12 ADC12 ADC12 ADC12 ADC12 ADC12
IFG23 IFG22 IFG21 IFG20 IFG19 IFG18 IFG17 IFG16
RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
126
ADC12IFGR2 Interrupt Flag Reg. 2
slau367o.pdf page 909
7 6 5 4 3 2 1 0
reserved
128
ADC12_B | Window Comparator Example
ADC12HI threshold
Set
ADC12INIFG
ADC12LO threshold
129
ADC12_B | Window Comparator Example
Set
ADC12HI threshold
ADC12HIIFG
ADC12LO threshold
130
ADC12_B | Window Comparator Example
ADC12HI threshold
Set
ADC12INIFG
ADC12LO threshold
131
ADC12_B | Window Comparator Example
ADC12HI threshold
ADC12LO threshold
Set
ADC12LOIFG
132
ADC12_B | Window Comparator Example
ADC12HI threshold
ADC12LO threshold
Set
ADC12LOIFG
133
ADC12_B | Window Comparator Example
Set
ADC12HI threshold
ADC12HIIFG
Set
ADC12INIFG
ADC12LO threshold
Set
ADC12LOIFG
134
ADC12_B | Differential Mode
• Combine 2 input channels to create a differential
input channel
• In this mode the ADC will measure the
difference between two channels and store this
value in the ADC12MEMx register
Vcc
A1
A1 voltage
ADC12MEMx
A2 ∆ Difference
Register
A2 voltage
Gnd
135
ADC12_B | Int. Channel Mapping
136
ADC12IV Interrupt Vector
In the interrupt service routine, ADC12IV register is used to find
out the source of the pending interrupt.
7 6 5 4 3 2 1 0
ADC12IVx
ADC12IVx
ADC12IVx: Interrupt vector value. Writing to this ADC12IVx: Interrupt vector value. Writing to
register clears all pending interrupt flags. this register clears all pending interrupt flags.
000h: no interrupt pending 040h: ADC12MEM4 intr. Flag. ADC12IFG4
002h: ADC12MEMx overflow, ADC12OVIFG ………….
004h: Conversion time overflow, ADC12TOVIFG 042h: ADC12MEM27 intr. Flag. ADC12IFG27
006h: wind. high interr. flag, ADC12HIIFG 044h: ADC12MEM28 intr. Flag. ADC12IFG28
008h: window low interrupt flag, ADC12LOIFG 046h: ADC12MEM29 intr. Flag. ADC12IFG29
00Ah: n-window interrupt flag, ADC12INIFG 048h: ADC12MEM30 intr. Flag. ADC12IFG30
00Ch: ADC12MEM0 intr. Flag. ADC12IFG0 04Ah: ADC12MEM31 intr. Flag. ADC12IFG31
00Eh: ADC12MEM1 intr. Flag. ADC12IFG1 04Ch: ADC12RDYIFG intr. Flag.
010h: ADC12MEM2 intr. Flag. ADC12IFG2
020h: ADC12MEM3 intr. Flag. ADC12IFG3
137 slau367o.pdf page 909
ADC12IV Interrupt Vector
Field Bit Value Interrupt Source
ADC12IV_NONE 0x0000 No interrupt pending
ADC12IV_ADC12OVIFG 0x0002 ADC12OVIFG
ADC12IV_ADC12TOVIFG 0x0004 ADC12TOVIFG
ADC12IV_ADC12HIIFG 0x0006 ADC12HIIFG
ADC12IV_ADC12LOIFG 0x0008 ADC12LOIFG
ADC12IV_ADC12INIFG 0x000A ADC12INIFG
ADC12IV_ADC12IFG0 0x000C ADC12IFG0
ADC12IV_ADC12IFG1 0x000E ADC12IFG1
........ ..... ........
ADC12IV_ADC12IFG29 0x0046 ADC12IFG29
ADC12IV_ADC12IFG30 0x0048 ADC12IFG30
ADC12IV_ADC12IFG31 0x004A ADC12IFG31
ADC12IV_ADC12RDYIFG 0x004C ADC12RDYIFG
// Configure ADC12
ADC12CTL0 = ADC12SHT01 | ADC12ON; // Sampling time, S&H=16, ADC12 on
ADC12CTL1 = ADC12SHP; // Use sampling timer
ADC12CTL2 |= ADC12RES__12BIT; // 12-bit conversion results
ADC12MCTL0 |= ADC12INCH_1; // A1 ADC input select; Vref=AVCC
ADC12IER0 |= ADC12IE0; // Enable ADC conv complete intr
while (1) {
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
/* Initialize ADC12_A */
ADC12CTL0 &= ~ADC12ENC; // Disable ADC12
ADC12CTL0 = ADC12SHT0_8 + ADC12ON; // Set sample time (8 clock cycles)
ADC12CTL1 = ADC12SHP; // Enable sample timer
ADC12CTL3 = ADC12TCMAP; // Enable internal temperature sensor
ADC12MCTL0 = ADC12VRSEL_1 + ADC12INCH_30; // ADC input ch A30 => internal temperature sensor
ADC12IER0 = 0x001; // ADC_IFG upon conv result-ADCMEMO
while(!(REFCTL0 & REFGENRDY)); // Wait for reference generator to settle
ADC12CTL0 |= ADC12ENC;
while(1) {
ADC12CTL0 |= ADC12SC; // Sampling and conversion start
__bis_SR_register(LPM0_bits + GIE); // LPM0 with interrupts enabled
__no_operation();
// Temperature in Celsius.
temperatureDegC = (float)(((long)temp - CALADC12_12V_30C) * (85 - 30)) /
(CALADC12_12V_85C - CALADC12_12V_30C) + 30.0f;
__no_operation(); // SET BREAKPOINT HERE
}
}
P1SEL1 = BIT2;
P1SEL2 = BIT2;
150 Week 6: Parallel I/O
Output Pin P1.3
• If you would like to change the behaviour of the port pin, you
need to select the pin functionality using PxSELy registers.
Control Signals and Bits
Pin Name x Function
P1DIR.x P1SEL1.x P1SEL2.x
P1.3 (I/O) I:0, O:1 0 0
TA1 CCI2A 0
0 1
TA1.2 1
P1.3 1
UCB0STE 0
1 0
UCB0STE 1
A3,C3 X 1 1
• For selecting the ADC mode (A2) of P1.3, you have to set
P1SEL1 = BIT3;
P1SEL2 = BIT3;
151 Week 6: Parallel I/O
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
// Configure GPIO
P1OUT &= ~BIT0; // Clear LED to start
P1DIR |= BIT0; // Set P1.0/LED to output
P1SEL1 |= BIT2 | BIT3; // Configure ADC inputs A2 and A3
P1SEL0 |= BIT2 | BIT3;
// Configure ADC12
ADC12CTL0 = ADC12SHT0_15 | ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 = ADC12SHP; // Use sampling timer
ADC12CTL2 |= ADC12RES_2; // 12-bit conversion results
ADC12MCTL0 |= ADC12INCH_2 | ADC12DIF; // Channel2 ADC input select; Vref=AVCC
ADC12IER0 |= ADC12IE0; // Enable ADC conv complete interrupt
while (1)
{
__delay_cycles(5000);
ADC12CTL0 |= ADC12ENC | ADC12SC; // Start sampling/conversion