EEM336 Week10 Sensors ADC

Download as pdf or txt
Download as pdf or txt
You are on page 1of 153

Sensors

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)

Light Dependant Resistor (LDR),


Lights & Lamps, LED's &
Light Level Photodiode, Phototransistor, Solar
Displays, Fiber Optics
Cell
Thermocouple, Thermistor,
Heater, Fan, Peltier
Temperature Thermostat, Resistive temperature
Elements
detectors (RTD)
Strain Gauge, Pressure Switch, Load Lifts & Jacks,
Force/Pressure
Cells Electromagnetic, Vibration
Potentiometer, Encoders,
Motor, Solenoid, Panel
Position Reflective/Slotted Opto-switch,
Meters
LVDT
Tacho-generator, Reflective/Slotted AC and DC Motors,
Speed
Opto-coupler, Doppler Effect Sensors Stepper Motor, Brake
Carbon Microphone, Piezo-electric
Sound Bell, Buzzer, Loudspeaker
Crystal
5
Temperature Sensors
• Resistive thermometers
– typical devices use platinum wire (such a
device is called a platinum resistance
thermometers or PRT)
– linear but has poor sensitivity

A typical PRT element A sheathed PRT


Week 6: Sensors 6
Temperature Sensors
• Thermistors
– use materials with a high thermal coefficient of
resistance
– sensitive but highly non-linear

– Thermistors (thermally sensitive resistors);


Platinum Resistance Thermometer (PRT), very
high accuracy.
Week 6: Sensors 7
Temperature Sensors
• pn junctions
– a semiconductor device with the
properties of a diode (we will
consider semiconductors and
diodes later)
– inexpensive, linear and easy to use
– limited temperature range (perhaps -50°C to 150 °C) due to
nature of semiconductor material

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

• Use op-amp to process/amplify the voltage


• Absolute accuracy of 1K is difficult

10
11
Light Sensors
• Photovoltaic
– light falling on a pn-junction A typical photodiode

can be used to generate


electricity from light energy
(as in a solar cell)
– small devices used as
sensors are called
photodiodes
– fast acting, but the voltage
produced is not linearly
related to light intensity

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)

Solar power is 1.4kW/m^2

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.

A limit switch A float switch

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

• Other counting techniques


– several methods use counting to determine
position
• two examples are given below

Inductive sensor Opto-switch sensor

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

Brushed motor – permanent magnets on armature, rotor acts as electromagnet


Brushless motor – permanent magnet on the rotor, electromagnets on armature are switched 31
Piezo transducers
• Detect motion (high and low frequency)
• Sound (lab this week), pressure, fast motion
• Cheap, reliable but has a very limited range of motion

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

• Note: voice coil can also be used to generate fast motion

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,200 V(t=0.640) = 1 m/s

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

• Description “g” level


Earth’s gravity 1g
Passenger car in corner 2g
Bumps in road 2g
Racing car driver in corner 3g
Bobsled rider in corner 5g
Human unconsciousness 7g
Space shuttle 10g
TI/RTOS 40
Why to measure Accelaration?
• Why measure acceleration?
– Acceleration is a physical characteristic of a
system.
– The measurement of acceleration is used as an
input into some types of control systems.
– The control systems use the measured
acceleration to correct for changing dynamic
conditions

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.

V(t) ADC V(n)

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

000 001 010 011 100 101 110 111


Volts
0.0 0.625 1.25 1.875 2.5 3.125 3.75 4.375 5.0
Some Observations
• Vref is broken up into Vref/2n voltage ranges
when n is the number of bits of conversion
• The midpoint for each range is the nominal
“quantized” value resulting from the conversion
• You do not get the exact measurement, but only
an approximation limited by the precision of the
result
• Analog to digital conversion resembles to the
analog signal if the number of bits of conversion
is high.
Popular A/D Techniques
• Integrating ADC
• Flash (parallel) ADC
• Pipelined ADC
• Ramp/Counter ADC
• Successive Approximation Register (SAR) ADC
• Sigma Delta ADC
• Two step ADC
Integrating ADC
• Integrating ADCs provide
– high resolution
– good line frequency
– noise rejection.
• These converters have been around for quite some
time.
• The integrating architecture provides an approach to
converting a low bandwidth analog signal into its
digital representation.
• These type of converters often include built-in drivers
for LCD or LED displays and are found in many
portable instrument applications, including digital
panel meters and digital multi-meters.
Single Slope Integrating ADC
• An unknown input voltage is integrated and the value compared against a
known reference value.
• The time it takes for the integrator to trip the comparator is proportional to the
unknown voltage (TINT/VIN).
• The accuracy is also dependent on the tolerances of the integrator's R and C
values. To overcome this problem, the dual-slope integrating architecture is
used.
C
R
VIN - VINT
-
+
VREF
+

VREF TINT α VIN

VINT

Time TINT
Dual Slope Integrating ADC
VIN = VREF
TINT TDE-INT
VINT TINT = fixed
TDE-INT α VIN
VREF
TINT TDE-INT Time

• The advantage over the single-slope is that the final


conversion result is insensitive to errors in the component
values.
• In other words, any error introduced by a component value
during the integrate cycle will be cancelled out during the
de-integrate phase.
https://www.youtube.com/watch?v=pzXZnvEKMXs
http://www.ti.com/lit/an/snoa597b/snoa597b.pdf
Multi Slope ADCs
C
R Error comparator
VIN - VINT
-
+ VREF
+
• The normal limit for resolution of the dual-slope architecture is based
on the speed of the error comparator
• For a 20-bit converter and a 1MHz clock, the conversion time would
be about 2 seconds.
• The ramp rate seen by the error comparator is about 2V/106 divided
by 1 microsecond. This is about 2 microvolts/microsecond. With such
a small slew rate, the error comparator would allow the integrator to
exceed its trip point. This overshoot (measured at the integrator
output) is called the "residue".
• Instead, we could convert the first 10 most significant bits (one
integrate/de-integrate cycle), then amplify the residue by 25, then
deintegrate again, then amplify the residue by 25, and then deintegrate
for the last time.
Flash (parallel) ADC
• Flash analog-to-digital converters are the fastest way
to convert an analog signal to a digital signal.
• They are suitable for applications requiring very large
bandwidths.
• However, flash converters consume a lot of power,
have relatively low resolution, and can be quite
expensive.
• This limits them to high frequency applications that
typically cannot be addressed any other way.
• Examples include data acquisition, satellite
communication, radar processing, sampling
oscilloscopes, and high-density disk drives.
• They are based on resistor network and biased
comparator inputs
Flash ADC
Example: 2 bit (4 levels) Flash ADC
analog input Vin
+ L11
Vref --

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

If the input voltage is a maximum, counter has to go to the


maximum value to get the answer. Can be time consuming.
Successive Approximation Register ADC
• Successive-approximation-register (SAR) analog-to-
digital converters (ADCs) are used for medium-to-
high-resolution applications
• SAR ADCs
– resolutions from 8 to 16 bits
– Lower than 5 million samples per second
– low power consumption
– small form factors
• They are ideal for portable/battery-powered
instruments, pen digitizers, industrial controls, and
data/signal acquisition.
• For more information
http://www.maxim-ic.com/appnotes.cfm/an_pk/1080/
SAR ADC • Track/Hold system
gets the input voltage
Analog and holds it.
Voltage Vin comparator • Comparator compares
Track/Hold +
VDAC VDAC and VIN, and
- SAR logic decides on
the next voltage to try.
N-bit
• Next to try is loaded
Vref DAC into N-bit register and
N
this value is converted
Data out N-bit
to analog equivalence.
register Then tis voltage is
SAR compared against VIN.
logic
• This continues until
VIN and VDAC are very
close
Track & Hold
CLK
tAJ
Analog
Input

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

1st step 2nd step 3rd step 4th step time


Sigma Delta ADC
• Sigma Delta analog-to-digital converters
(ADCs) are used predominately in lower
speed applications requiring a trade off of
speed for resolution by oversampling,
followed by filtering to reduce noise.
• 24 bit Sigma Delta converters are common in
Audio designs, instrumentation and Sonar.
• Bandwidths are typically less than 1MHz
with a range of 12 to 18 true bits.
Two Step ADC
• Two Step analog-to-digital converters (ADCs)
are also known as subranging converters and
sometimes referred to as multi-step or half
flash (slower than Flash architecture).
• This is a cross between a Flash ADC and
pipeline ADC and can achieve higher
resolution or smaller die size and power for a
given resolution are needed vs. a Flash ADC.
Example MAX153.
Comparison of ADC
Technologies
Integrating, Flash, SAR, Sigma-Delta, Pipelined
ADCs

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

Comparator for saving l


CPU overhead e
x
• DMA-enabled for e
intelligent interrupt r

processing ADC12 Memory Registers

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

Week 6: Sensors 100


ADC_B BLOCK DIAGRAM

Week 6: Sensors 101


ADC Core
• Core converts an analog input to its 12-bit digital
representation an stores the result in conversion memory;
the conversion formula is

• VR+ and VR− are programmable voltage levels:


the upper (VR+) and lower limits (VR-) of the conversion
• The digital output (NADC) is full scale
– (0xFFF) when the input signal is equal to or higher than VR+
– (0x000) when the input signal is equal to or lower than VR−
– The input channel and the reference voltage levels (VR+ and VR−)
are defined in the conversion-control memory.
102
ADC12CTL0 ADC Ctrl Register 0
15 14 13 12 11 10 9 8

ADCCTL0_H ADC12SHT1x ADC12SHT0x


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
ADCCTL0_L reserved reserved
MSC ON ENC SC

RESET RW-0 R-0 R-0 RW-0 R-0 R-0 RW-0 RW-0

ADC12SHT1x: ADC12_B sample-and-hold time. ADC12SHT0x: ADC12_B sample-and-hold time.


These bits define the number of ADC12CLK These bits define the number of ADC12CLK
cycles in the sampling period for registers cycles in the sampling period for registers
ADC12MEM8 to ADC12MEM23. Can be ADC12MEM0 to ADC12MEM7 and ADC12MEM24
modified only when ADC12ENC = 0. to ADC12MEM31. Can be modified only when
ADC12ENC = 0.
0000b: 4 ADC12CLK cycles 0000b: 4 ADC12CLK cycles
0001b: 8 cycles, 0010b: 16, 0011b: 32 0001b: 8 cycles, 0010b: 16, 0011b: 32
0100b: 64 cycles, 0101b: 96, 0110b: 128 0100b: 64 cycles, 0101b: 96, 0110b: 128
0111b: 192 cycles, 1000b: 256, 1001b: 384 0111b: 192 cycles, 1000b: 256, 1001b: 384
1010b: 512 ADC12CLK cycles 1010b: 512 ADC12CLK cycles
1011b, 1101b, 1110b, 1111b: reserved 1011b, 1101b, 1110b, 1111b: reserved

slau367o.pdf page 890 103


ADC12CTL0 ADC Ctrl Register 0
15 14 13 12 11 10 9 8

ADCCTL0_H ADC12SHT1x ADC12SHT0x


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
ADCCTL0_L reserved reserved
MSC ON ENC SC

RESET RW-0 R-0 R-0 RW-0 R-0 R-0 RW-0 RW-0

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

slau367o.pdf page 891 104


ADC12CTL0 control bits
Field Bit Value Definition
ADC12SC 0x0001 ADC12 Start Conversion
ADC12ENC 0x0002 ADC12 Enable Conversion
ADC12ON 0x0010 ADC12 On/enable
ADC12MSC 0x0080 ADC12 Multiple SampleConversion
ADC12SHT00 0x0100 ADC12 Sample Hold 0 Select Bit: 0
ADC12SHT01 0x0200 ADC12 Sample Hold 0 Select Bit: 1
ADC12SHT02 0x0400 ADC12 Sample Hold 0 Select Bit: 2
ADC12SHT03 0x0800 ADC12 Sample Hold 0 Select Bit: 3
ADC12SHT10 0x1000 ADC12 Sample Hold 1 Select Bit: 0
ADC12SHT11 0x2000 ADC12 Sample Hold 1 Select Bit: 1
ADC12SHT12 0x4000 ADC12 Sample Hold 1 Select Bit: 2
ADC12SHT13 0x8000 ADC12 Sample Hold 1 Select Bit: 3

msp430fr5969.h Week 6: Sensors 105


ADC12CTL0 control bits
Field Bit Value Definition
ADC12SHT0_0 0*0x100u ADC12 Sample Hold 0 Select Bit: 0
ADC12SHT0_1 1*0x100u ADC12 Sample Hold 0 Select Bit: 1
ADC12SHT0_2 2*0x100u ADC12 Sample Hold 0 Select Bit: 2
ADC12SHT0_3 3*0x100u ADC12 Sample Hold 0 Select Bit: 3
ADC12SHT0_4 4*0x100u ADC12 Sample Hold 0 Select Bit: 4
ADC12SHT0_5 5*0x100u ADC12 Sample Hold 0 Select Bit: 5
ADC12SHT0_6 6*0x100u ADC12 Sample Hold 0 Select Bit: 6
ADC12SHT0_7 7*0x100u ADC12 Sample Hold 0 Select Bit: 7
ADC12SHT0_8 8*0x100u ADC12 Sample Hold 0 Select Bit: 8
ADC12SHT0_9 9*0x100u ADC12 Sample Hold 0 Select Bit: 9
ADC12SHT0_10 10*0x100u ADC12 Sample Hold 1 Select Bit: 10
ADC12SHT0_11 11*0x100u ADC12 Sample Hold 1 Select Bit: 11
ADC12SHT0_12 12*0x100u ADC12 Sample Hold 0 Select Bit: 12
ADC12SHT0_13 13*0x100u ADC12 Sample Hold 0 Select Bit: 13
ADC12SHT0_14 14*0x100u ADC12 Sample Hold 0 Select Bit: 14
ADC12SHT0_15 15*0x100u ADC12 Sample Hold 0 Select Bit: 15
msp430fr5969.h Week 6: Sensors 106
ADC12CTL0 control bits
Field Bit Value Definition
ADC12SHT1_0 0*0x100u ADC12 Sample Hold 1 Select Bit: 0
ADC12SHT1_1 1*0x100u ADC12 Sample Hold 1 Select Bit: 1
ADC12SHT1_2 2*0x100u ADC12 Sample Hold 1 Select Bit: 2
ADC12SHT1_3 3*0x100u ADC12 Sample Hold 1 Select Bit: 3
ADC12SHT1_4 4*0x100u ADC12 Sample Hold 1 Select Bit: 4
ADC12SHT1_5 5*0x100u ADC12 Sample Hold 1 Select Bit: 5
ADC12SHT1_6 6*0x100u ADC12 Sample Hold 1 Select Bit: 6
ADC12SHT1_7 7*0x100u ADC12 Sample Hold 1 Select Bit: 7
ADC12SHT1_8 8*0x100u ADC12 Sample Hold 1 Select Bit: 8
ADC12SHT1_9 9*0x100u ADC12 Sample Hold 1 Select Bit: 9
ADC12SHT1_10 10*0x100u ADC12 Sample Hold 1 Select Bit: 10
ADC12SHT1_11 11*0x100u ADC12 Sample Hold 1 Select Bit: 11
ADC12SHT1_12 12*0x100u ADC12 Sample Hold 1 Select Bit: 12
ADC12SHT1_13 13*0x100u ADC12 Sample Hold 1 Select Bit: 13
ADC12SHT1_14 14*0x100u ADC12 Sample Hold 1 Select Bit: 14
ADC12SHT1_15 15*0x100u ADC12 Sample Hold 1 Select Bit: 15
msp430fr5969.h Week 6: Sensors 107
ADC12CTL1 ADC Ctrl Register 1
15 14 13 12 11 10 9 8
RTC RTC
ADC12CTL0_H rsvd ADC12PDIV ADC12SHSx
AIFG RDYIFG
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
ADC12CTL0_L ADC12DIVx ADC12SSELx ADC12CONSEQx
BUSY
RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0

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.

slau367o.pdf page 892 109


ADC12CTL1 control bits
Field Bit Value Definition
ADC12BUSY 0x0001 ADC12 Busy
ADC12CONSEQ0 0x0002 ADC12 Conversion Sequence Select Bit: 0
ADC12CONSEQ1 0x0004 ADC12 Conversion Sequence Select Bit: 1
ADC12SSEL0 0x0008 ADC12 Clock Source Select Bit: 0
ADC12SSEL1 0x0010 ADC12 Clock Source Select Bit: 1
ADC12DIV0 0x0020 ADC12 Clock Divider Select Bit: 0
ADC12DIV1 0x0040 ADC12 Clock Divider Select Bit: 1
ADC12DIV2 0x0080 ADC12 Clock Divider Select Bit: 2
ADC12ISSH 0x0100 ADC12 Invert Sample Hold Signal
ADC12SHP 0x0200 ADC12 Sample/Hold Pulse Mode
ADC12SHS0 0x0400 ADC12 Sample/Hold Source Bit: 0
ADC12SHS1 0x0800 ADC12 Sample/Hold Source Bit: 1
ADC12SHS2 0x1000 ADC12 Sample/Hold Source Bit: 2
ADC12PDIV0 0x2000 ADC12 Predivider Bit: 0
ADC12PDIV1 0x4000 ADC12 Predivider Bit: 1
Week 6: Sensors 110
ADC12CTL2 ADC Ctrl Register 2
7 6 5 4 3 2 1

ADCCTL2_H reserved

RESET R-0 R-0 R-0 R-0 R-0 R-0 R-0 R-0

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

Week 6: Sensors 112


ADC12CTL3 ADC Ctrl Register 3
15 14 13 12 11 10 9 8
ADC12 ADC12 ADC12 ADC12
ADCCTL3_H
ICH3MAP ICH2MAP ICH1MAP ICH0MAP

RESET R-0 R-0 R-0 R-0 RW-0 RW-0 RW-0 RW-0


7 6 5 4 3 2 1 0
ADC12 ADC12
ADCCTL3_L rsvd ADC12CSTARTADDx
TCMAP BATMAP

RESET RW-0 RW-0 R-0 RW-0 RW-0 RW-0 RW-0 RW-0

ADC12ICH3MAP: Controls internal channel 3 ADC12ICH1MAP: Controls internal channel 1


selection to ADC input channel A26. Can be selection to ADC input channel A28. Can be
modified only when ADC12ENC = 0. modified only when ADC12ENC = 0.
0b = external pin selected for ADC ch26 0b = external pin selected for ADC ch28
1b = ADC input ch. internal 3 is selected for 1b = ADC input ch. İnternal 1 is selected for ADC
ADC input channel A26 input channel A28
ADC12ICH2MAP: Controls internal channel 2 ADC12ICH0MAP: Controls internal channel 0
selection to ADC input channel A27. Can be selection to ADC input channel A29. Can be
modified only when ADC12ENC = 0. modified only when ADC12ENC = 0.
0b = external pin selected for ADC ch27 0b = external pin selected for ADC ch29
1b = ADC input ch. İnternal 2 is selected for 1b = ADC input ch. İnternal 0 is selected for ADC
ADC input channel A27 input channel A29

113 slau367o.pdf page 894


ADC12CTL3 ADC Ctrl Register 3
15 14 13 12 11 10 9 8
ADC12 ADC12 ADC12 ADC12
ADCCTL3_H
ICH3MAP ICH2MAP ICH1MAP ICH0MAP

RESET R-0 R-0 R-0 R-0 RW-0 RW-0 RW-0 RW-0


7 6 5 4 3 2 1 0
ADC12 ADC12
ADCCTL3_L rsvd ADC12CSTARTADDx
TCMAP BATMAP

RESET RW-0 RW-0 R-0 RW-0 RW-0 RW-0 RW-0 RW-0

ADC12TCMAP: Controls temperature sensor ADC12CSTARTADDx: ADC12_B conversion start


ADC input channel selection. Can be modified address. These bits select which ADC12_B
onlywhen ADC12ENC = 0. conversion memory register is used for a single
0b = external pin selected for ADC conversion or for the first conversion in a sequence.
inp. ch. A30 The value of CSTARTADDx is 0h to 1Fh,
1b = ADC int. tempera. sensor ch. is corresponding to ADC12MEM0 to ADC12MEM31.
selected for ADC input channel A30 Can be modified only when ADC12ENC = 0.
ADC12BATMAP: Controls 1/2 AVCC ADC
input channel selection. Can be modified only
when ADC12ENC = 0.
0b = external pin is selected for ADC MSP430FR5969 has an
input channel A31 internal temperature
1b = ADC internal 1/2 x AVCC
channel is selected for ADC input sensor ch. A30
channel A31 slau367o.pdf page 894
114
ADC12MEMx Register
slau367o.pdf page 896
7 6 5 4 3 2 1 0

ADC12MEMx_H Conversion result

RESET RW RW RW RW RW RW RW RW
7 6 5 4 3 2 1 0

ADC12MEMx_L Conversion result

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.

If ADC12DF = 1: The 12-bit conversion results are left-justified 2s-complement


format. Bit 15 is the MSB. Bits 3-0 are 0 in 12-bit mode, bits 5-0 are 0 in 10-bit
mode, and bits 7-0 are 0 in 8-bit mode. The data is stored in the right-justified
format and is converted to the left-justified 2s-complement format during read
back. 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

Week 6: Sensors 118


ADC12HI Window Comparator High Threshold Register
slau367o.pdf page 899
7 6 5 4 3 2 1 0

High Threshold

RESET RW-0 RW-0 RW-0 RW-0 RW-1 RW-1 RW-1 RW-1

7 6 5 4 3 2 1 0

High Threshold

RESET RW-1 RW-1 RW-1 RW-1 RW-1 RW-1 RW-1 RW-1

High threshold: Window comparator high threshold should only be modified when
ADC12ENC=0.

If ADC12DF = 0: The 12-bit threshold value is right justified when ADC12DF = 0.


Bits 15-12 are 0. Bit 11 is the MSB. Bits 11-10 are 0 in 10-bit mode, and bits 11-
8 are 0 in 8-bit mode.

If ADC12DF = 1: The 12-bit threshold value is left justified when ADC12DF = 1,


2s-complement format. Bit 15 is the MSB. Bits 3-0 are 0 in 12-bit mode, bits 5-0
are 0 in 10-bit mode, and bits 7-0 are 0 in 8-bit mode.

119
ADC12LO Window Comparator Low Threshold Register
slau367o.pdf page 899
7 6 5 4 3 2 1 0

Low Threshold

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

Low Threshold

RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0

Low threshold: Window comparator low threshold should only be modified when
ADC12ENC=0.

If ADC12DF = 0: The 12-bit threshold value is right justified when ADC12DF = 0.


Bits 15-12 are 0. Bit 11 is the MSB. Bits 11-10 are 0 in 10-bit mode, and bits 11-
8 are 0 in 8-bit mode.

If ADC12DF = 1: The 12-bit threshold value is left justified when ADC12DF = 1,


2s-complement format. Bit 15 is the MSB. Bits 3-0 are 0 in 12-bit mode, bits 5-0
are 0 in 10-bit mode, and bits 7-0 are 0 in 8-bit mode.

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

ADC12IEx: Interrupt enable


0b: interrupt disabled
1b: interrupt enabled.

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

ADC12IEx: Interrupt enable


0b: interrupt disabled
1b: interrupt enabled.

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

Week 6: Sensors 123


ADC12IER2 Interrupt Enable Reg. 2
slau367o.pdf page 904
7 6 5 4 3 2 1 0

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

ADC12RDYIE: ADC12_B local reference ADC12LOIE: Interrupt enable for the


buffer ready interrupt enable. (0b: interrupt falling short of the lower limit interrupt of
disabled, 1b: interrupt enabled.) the window comparator for the
ADC12TOVIE: ADC12_B conversion- ADC12MEMx result register. (0b: interrupt
time-overflow interrupt enable. (0b: disabled, 1b: interrupt enabled.)
interrupt disabled, 1b: interrupt enabled.) ADC12INIE: Interrupt enable for the
ADC12OVIE:ADC12MEMx overflow- ADC12MEMx result register being greater
interrupt enable. (0b: interrupt disabled, 1b: than the ADC12LO threshold and below the
interrupt enabled.) ADC12HI threshold. (0b: interrupt disabled,
ADC12HIIE:Interrupt enable for the 1b: interrupt enabled.)
exceeding the upper limit interrupt of the
window comparator for ADC12MEMx
result register. The (0b: interrupt disabled,
1b: interrupt enabled.)
124
ADC12IFGR0 Interrupt Flag Reg. 0
slau367o.pdf page 900
7 6 5 4 3 2 1 0
ADC12 ADC12 ADC12 ADC12 ADC12 ADC12 ADC12 ADC12
IFG15 IFG14 IFG13 IFG12 IFG11 IFG10 IFG9 IFG8
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
IFG7 IFG6 IFG5 IFG4 IFG3 IFG2 IFG1 IFG0
RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0

ADC12IFGn: (n=0..15) ADC12MEMn


interrupt flag. This bit is set when
ADC12MEMn is loaded with a conversion
result. The ADC12IFGn bit is reset if
ADC12MEMn is accessed, or
it can be reset with software.
0b = No interrupt pending
1b = Interrupt pending

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

ADC12IFGn: (n=16..31) ADC12MEMn


interrupt flag. This bit is set when
ADC12MEMn is loaded with a conversion
result. The ADC12IFGn bit is reset if
ADC12MEMn is accessed, or
it can be reset with software.
0b = No interrupt pending
1b = Interrupt pending

126
ADC12IFGR2 Interrupt Flag Reg. 2
slau367o.pdf page 909
7 6 5 4 3 2 1 0

reserved

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


reserved
RDYIFG TOVIFG OVIFG HIIFG LOIFG INIFG IFG16
RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0

ADC12RDYIFG: ADC12_B local reference ADC12LOIFG: Interrupt flag for falling


buffer ready interrupt flag. (0b = No short of the lower limit interrupt of the
interrupt pending, 1b = Interrupt pending) window comparator for the ADC12MEMx
ADC12TOVIFG: ADC12_B conversion- result register.. (0b = No interrupt pending,
time-overflow interrupt flag. (0b = No 1b = Interrupt pending)
interrupt pending, 1b = Interrupt pending) ADC12INIFG: Interrupt flag for the
ADC12OVIFG:ADC12MEMx overflow- ADC12MEMx result register being greater
interrupt flag. (0b = No interrupt pending, than the ADC12LO threshold and below the
1b = Interrupt pending) ADC12HI threshold interrupt. (0b = No
ADC12HIIFG:Interrupt flag for exceeding interrupt pending, 1b = Interrupt pending)
the upper limit interrupt of the window
comparator for ADC12MEMx result
register (0b = No interrupt pending, 1b =
Interrupt pending)
127
ADC12_B | Window Comparator
• Window Comparator
– Allows you to configure input
threshold levels Set
– The ADC conversion results are ADC12HI threshold
ADC12HIIFG
automatically compared against
the thresholds
– Hi, Lo, and In interrupts Set
indicate which range the result ADC12INIFG
falls in
– Same thresholds shared among ADC12LO threshold
all channels
– Useful for low power because
Set
device can stay in LPM until ADC12LOIFG
result falls in window

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

• A26-31 can map to either an


External Input or Internal
ADC input
• Internal inputs include the
temperature sensor and
battery monitor

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

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

ADC12IVx

RESET RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0

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

Week 6: Sensors 138


Example
• A single sample is made on A1 with reference to Avcc
(Analog supply voltage).
• Software sets ADC12SC to start sample and
conversion - ADC12SC automatically cleared at EOC.
ADC12 internal oscillator times sample (16x) and
conversion.
• In Mainloop MSP430 waits in LPM0 to save power
until ADC12 conversion complete, ADC12_ISR will
force exit from LPM0 in Mainloop on reti.
• If input ADC voltage is greater than 0x7FF (i.e. A1
> 0.5*AVcc), P1.0 (LED) set, else reset. Show the
correct handling of and ADC12 interrupt as well.
Week 6: Sensors 139
Solution
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
P1OUT &= ~BIT0; // Clear LED to start
P1DIR |= BIT0; // Set P1.0/LED to output
P1SEL1 |= BIT1; // Configure P1.1 for ADC
P1SEL0 |= BIT1;
PM5CTL0 &= ~LOCKLPM5; // enable GPIO

// 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) {

__delay_cycles(5000); // delay 5000 clock cycles


ADC12CTL0 |= ADC12ENC | ADC12SC; // Start sampling/conversion

__bis_SR_register(LPM0_bits | GIE); // LPM0, ADC12_ISR will force exit


__no_operation(); // For debugger
}
}
140
Solution
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
switch(ADC12IV)
{
case ADC12IV_NONE: break; // Vector 0: No interrupt
case ADC12IV_ADC12IFG0: // Vector 12: ADC12MEM0 intr
if (ADC12MEM0 >= 0x7ff) // ADC12MEM0=A1 > 0.5AVcc?
P1OUT |= BIT0; // P1.0 = 1
else
P1OUT &= ~BIT0; // P1.0 = 0
__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
break; // Clear CPUOFF bit from 0(SR)
case ADC12IV_ADC12RDYIFG: break; // Vector 76: ADC12RDY
case ADC12IV_ADC12OVIFG: break; // Vector 2: ADC12MEMx ovf
case ADC12IV_ADC12TOVIFG: break; // Vector 4: Conv time ovf
case ADC12IV_ADC12HIIFG: break; // Vector 6: ADC12BHI
case ADC12IV_ADC12LOIFG: break; // Vector 8: ADC12BLO
case ADC12IV_ADC12INIFG: break; // Vector 10: ADC12BIN
case ADC12IV_ADC12IFG1: break; // Vector 14: ADC12MEM1

// ... Put cases for all ADC12IV_ADC12IFG8..... ADC12IV_ADC12IFG31


default: break;
}
}
141
MSP430 REF_A
• The reference module (REF) is responsible for
generation of all critical reference voltages that can be
used by various analog peripherals in a given device.
• The heart of the reference system is the bandgap from
which all other references are derived by unity or
noninverting gain stages.
• The REFGEN subsystem consists of the bandgap, the
bandgap bias, and the noninverting buffer stage, which
generates the three primary voltage reference available
in the system (1.2 V, 2.0 V, and 2.5 V).
• In addition, when enabled, a buffered bandgap voltage
is available.
Week 6: Sensors 142
REFCTL0 REF_A Control Reg
slau367o.pdf page 863
15 14 13 12 11 10 9 8
REF REF REFGEN REF REF
reserved BGMODE
BGRDY GENRDY BUSY BGACT GENACT
RESET R0 R0 R-0 R-0 R-0 R-0 R-0 R-0
7 6 5 4 3 2 1 0
REF REF REF
REFVSEL rsvd REFOUT REFON
BGOT GENOT TCOFF
RESET RW-0 RW-0 RW-0 RW-0 RW-0 R0 RW-0 RW-0

REFVSEL: Reference voltage level select. This register is used to


Can be modified only when REFGENBUSY = 0. generate reference voltage
00b = 1.2 V available when REFON = 1
01b = 2.0 V available when REFON = 1 for the ADC system.
10b = 2.5 V available when REFON = 1 once we start generation
11b = 2.5 V available when REFON = 1
of the reference voltage,
REFON: Reference enable we need to check whether
Can be modified only when REFGENBUSY = 0.
0b = Disables reference if no other the reference voltage is
reference requests are pending stabilized or not by
1b = Enables reference
REFGENBUSY flag.
143
EXAMPLE
Using Internal Temperature Sensor
msp430fr59xx_adc12_10.c

Week 6: Sensors 144


ADC Example
• MSP430FR5969 has an internal
temperature sensor connected to channel
A30.
• We are going to use ADC12 for converting
internal temperature sensor value to digital.
• We need to use the calibration data to
correct the internal temperature sensor.

Week 6: Sensors 145


#include <msp430.h>
#define CALADC12_12V_30C *((unsigned int *)0x1A1A)// Temperature Sensor Calibration-30 C
#define CALADC12_12V_85C *((unsigned int *)0x1A1C)// Temperature Sensor Calibration-85 C

unsigned int temp;


volatile float temperatureDegC;

int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT

// Initialize the shared reference module


// By default, REFMSTR=1 => REFCTL is used to configure the internal reference
while(REFCTL0 & REFGENBUSY); // If ref generator busy, WAIT
REFCTL0 |= REFVSEL_0 + REFON; // Enable internal 1.2V reference

/* 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
}
}

Week 6: Sensors 146


#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
switch(ADC12IV)
{
case ADC12IV_NONE: break; // Vector 0: No interrupt
case ADC12IV_ADC12OVIFG: break; // Vector 2: ADC12MEMx Overflow
case ADC12IV_ADC12TOVIFG: break; // Vector 4: Conversion time ovf
case ADC12IV_ADC12HIIFG: break; // Vector 6: ADC12BHI
case ADC12IV_ADC12LOIFG: break; // Vector 8: ADC12BLO
case ADC12IV_ADC12INIFG: break; // Vector 10: ADC12BIN
case ADC12IV_ADC12IFG0: // Vector 12: ADC12MEM0 Interrupt
temp = ADC12MEM0; // Move results, IFG is cleared
__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
break;
case ADC12IV_ADC12IFG1: break; // Vector 14: ADC12MEM1
case ADC12IV_ADC12IFG2: break; // Vector 16: ADC12MEM2
case ADC12IV_ADC12IFG3: break; // Vector 18: ADC12MEM3
case ADC12IV_ADC12IFG4: break; // Vector 20: ADC12MEM4
case ADC12IV_ADC12IFG5: break; // Vector 22: ADC12MEM5
// ..............................................
case ADC12IV_ADC12IFG27: break; // Vector 66: ADC12MEM27
case ADC12IV_ADC12IFG28: break; // Vector 68: ADC12MEM28
case ADC12IV_ADC12IFG29: break; // Vector 70: ADC12MEM29
case ADC12IV_ADC12IFG30: break; // Vector 72: ADC12MEM30
case ADC12IV_ADC12IFG31: break; // Vector 74: ADC12MEM31
case ADC12IV_ADC12RDYIFG: break; // Vector 76: ADC12RDY
default: break;
}
}
Week 6: Sensors 147
EXAMPLE
Differential ADC
msp430fr59xx_adc12_03.c

Week 6: Sensors 148


ADC Example
• Use a voltage source that can produce
between 1V to 3V.
• Use three 10K equal valued resistors
to divide the voltage 2xVin/3 and
Vin/3 . Vin
• Vin is varied from 1V to 3V.
• When Vin = 3V, A2 = 2V and A3 = A2 (P1.2)
1V providing a differential voltage of
1V across the ADC input. A3 (P1.3)
• If A2-A3 >= 1V, P1.0 set, else reset.
• Use ADC12 interrupt.
• Here A1 = P1.2 and A2=P1.3
149
Output Pin P1.2
• 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.0 (I/O) Inp:0, Out:1 0 0
TA1 CCI1A 0
0 1
TA1.1 1
P1.2 0
TA0CLK 0
1 0
COUT 1
A2,C2 X 1 1
• For selecting the ADC mode (A2) of P1.2, you have to set

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>

volatile unsigned int result = 0;

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;

// Disable the GPIO power-on default high-impedance mode to activate


// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;

// 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

__bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit


__no_operation(); // For debugger
}
}

Week 6: Sensors 152


#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
switch(ADC12IV)
{
case ADC12IV_NONE: break; // Vector 0: No interrupt
case ADC12IV_ADC12OVIFG: break; // Vector 2: ADC12MEMx Overflow
case ADC12IV_ADC12TOVIFG: break; // Vector 4: Conversion time ovf
case ADC12IV_ADC12HIIFG: break; // Vector 6: ADC12BHI
case ADC12IV_ADC12LOIFG: break; // Vector 8: ADC12BLO
case ADC12IV_ADC12INIFG: break; // Vector 10: ADC12BIN
case ADC12IV_ADC12IFG0: // Vector 12: ADC12MEM0 Interrupt
result = ADC12MEM0; // read out the result register
if (result >= 0x0AAB) // ADC12MEM0 = A2-A3 >= 1V?
P1OUT |= BIT0; // P1.0 = 1
else
P1OUT &= ~BIT0; // P1.0 = 0
__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
break; // Clear CPUOFF bit from 0(SR)
case ADC12IV_ADC12IFG1: break; // Vector 14: ADC12MEM1
case ADC12IV_ADC12IFG2: break; // Vector 16: ADC12MEM2
case ADC12IV_ADC12IFG3: break; // Vector 18: ADC12MEM3
case ADC12IV_ADC12IFG4: break; // Vector 20: ADC12MEM4
case ADC12IV_ADC12IFG5: break; // Vector 22: ADC12MEM5
// ..............................................
default: break;
}
}
Week 6: Sensors 153

You might also like