lab 3: adc
DESCRIPTION
Lab 3: ADC. Signal Path. Produce a proper output voltage level. Signal Conditioning (if necessary). Sensors. Amplification Filtering. Analog to Digital Conversion (ADC). Light Temperature Acceleration Humidity Pressure etc. Resistance Capacitance Current Voltage - PowerPoint PPT PresentationTRANSCRIPT
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Signal Path
Sensors Signal Conditioning
(if necessary)
Convert to voltage
• Amplification• Filtering
• Light• Temperature• Acceleration• Humidity• Pressure• etc.
• Resistance• Capacitance• Current• Voltage• etc.
Analog to Digital
Conversion
(ADC)
10011101
Produce a proper output
voltage level
Converts voltage to
digital numberToday’s
labs
Network and Systems Laboratorynslab.ee.ntu.edu.tw
General ViewPositive/Negative voltage reference: define the upper and
lower limits of the conversion
12 input channels available
Software configurable
sample-and-hold period
16 conversion result storage
registers
Each storage register
associated with a control register
4 clock sources available for ADC12 clock
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Conversion FormulaThis is a conversion formula of ADC
For MSP430 ADC12 moduleIt is 12-bit ADC
If Vin > Vref+ => output 4095 (max)If Vin < Vref- => output 0 (min)
refref
refbitnADC VV
VVinN )12(
refref
refADC VV
VVinN )4095(
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Input Channels12 input channels available
8 external input pins: A0 ~ A72 external voltage reference pins: VeREF+, VeREF-1 internal temperature sensor1 supply voltage monitor
Multiplexed with P6 GPIOSetting P6SEL to choose the
function you want
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Internal Voltage Reference GeneratorVoltage references are used as a base of the
conversionInput voltage compares to the voltage reference to
generate the conversion result
A stable voltage reference is crucial to an accurate conversion Usually we use a special circuit to generate stable
voltage referenceMSP430 has a built-in voltage reference generator
It has two selectable voltage levels 1.5V and 2.5V
refref
refbitnADC VV
VVinN )12(
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Voltage References Options3 positive reference sources
AVcc – Positive supply voltageVREF – internal voltage reference
Can be 1.5V or 2.5V, depends on your selection
VeREF+ – external positive voltage reference
2 negative reference sourcesAVss – Negative supply voltage (GND)VeREF- -- external negative voltage reference
6 combinations in total
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ADC12 Conversion ModesSingle channel single-conversion
A single channel is converted onceSequence-of-channels
A sequence of channels is converted onceRepeat-single-channel
A single channel is converted repeatedlyRepeat-sequence-of-channels
A sequence of channels is converted repeatedly
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Conversion Memory16 ADC12MEMx memory registers to store
conversion resultsEach ADC12MEMx is configured with an
associated ADC12MCTLx control register.EOS: End of sequence, indicates last conversionSREFx: Select voltage referenceINCHx: Select Input Channel
CSTARTADDx bits define the first memory used for conversionThis bit is in ADC12CTL1 control register
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ADC12MCTLx
Use in sequence of
channels mode
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ExampleDepends on the setting of conversion mode,
ADC12MCTLx and CSTARTADDx, the ADC will have different behavior
Single-channel
CSTARTADDx = 0000
You need to set ADC12MCTL0 (choose the input channel and voltage reference). And the conversion result will store in ADC12MEM0
CSTARTADDx = 0100
You need to set ADC12MCTL8 (choose the input channel and voltage reference). And the conversion result will store in ADC12MEM8
Sequence of Channels
CSTARTADDx = 0000
You need to set ADC12MCTL0 to ADC12MCTL4 (choose the input channel and voltage reference for each ADC12MEM). You need to set the EOS bit in ADC12MCTL4 to 1, indicates the sequence of conversion end here. And the conversion results will store in corresponding ADC12 memory registers
CSTARTADDx = 0100
If you need 5 input channels
If you need 7 input channels
You need to set ADC12MCTL8 to ADC12MCTL14 (choose the input channel and voltage reference for each ADC12MEM). You need to set the EOS bit in ADC12MCTL14 to 1, indicates the sequence of conversion end here. And the conversion results will store in corresponding ADC12 memory registers
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Conversion Clock4 clock sources available
ADC12OSC: ADC12 internal oscillatorMCLKSMCLKACLKFor simplicity, we use ADC12OSC in our labIndependent of the system clock
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ADC12 CoreTwo phases for a conversion
Sample-and-holdA/D conversion
Conversions in MSP430 ADC12Triggered by a SHI signalTwo sample modes
Extended Sample Mode
Pulse Sample Mode
SHI signal triggers a conversion and controls the length of sample-and-hold
period
SHI signal triggers a conversion, the length of the
sample-and-hold period is controlled by other register
Network and Systems Laboratorynslab.ee.ntu.edu.tw
The SHI SignalFour selectable sources for SHI
ADC12SC bit A single bit in ADC12 control register, set this bit to
high will trigger a conversionTimer_A output unit 1 (TA1)Timer_B output unit 0 (TB0)Timer_B output unit 1 (TB1)
Lab_2 slide
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Sample And Hold Revisit
There is a sample and hold circuit before A/D conversion
Mostly integrated with the ADC chip When no conversion, switch S1 is open When a conversion start
S1 closed Input signal charge C1 S1 open, C1 holds the value of input
signal A/D conversion
Sample and hold time Time between S1 close and re open If it is too short
C1 will not fully charged (error)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Sample Timing Considerations
For an accurate conversion, the sample-and-hold time must be long enough to charge up CI to Vs
Rs will affect the sample-and-hold time (tsample)For MSP430F1611, RI = 2K ohm (max); CI = 40
pF (max)Minimum tsample for 12-bit conversion
=>
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Setting tsample
If we use ADC internal oscillator (ADC12OSC) as
ADC12 clock source. Frequency of ADC12OSC is about 5MHz, if you set SHT0x to 0100, then the sample-and-hold time is
64*(1/5000000) second = 12.8 μs
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Rs: Source ResistanceMany devices didn’t specify their source
resistance (source impedance/output impedance)
Measuring source impedance is not an easy task
For most of the case, set the SHTx bit to 0001 or 0010 should work
My suggestion isit’s only 16 possible setting, just try it out!
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ADC12 InterruptsADC12 has 18 interrupt sources:
ADC12IFG0-ADC12IFG15 flag Associated with each ADC12MEMx, indicates a
conversion of this memory is completeADC12OV: ADC12MEMx overflow
A conversion result is written to any ADC12MEMx before its previous conversion result was read
ADC12TOV: conversion time overflow Another conversion is requested before the current
conversion is completed
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ADC12IV, Interrupt Vector GeneratorAll ADC12 interrupts are source to a single
interrupt vectorSimilar to Timer_A3
The highest priority enabled ADC12 interrupt generates a number in the ADC12IV registerHighest priority interrupt generates a number
Branch to the ADC ISR, read ADC12IV, process the associate sub-routine, leave the ADC ISR
And then, second highest priority interrupt generates another number Branch to the ADC ISR again, ……….
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Reset of InterruptsOverflow interrupts (memory overflow and
conversion time overflow) will reset automatically whenAny access, read or write, of the ADC12IV
registerADC12IFG0-ADC12IFG15 flag will reset
whenAccessing their associated ADC12MEMx
register
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Interrupt Enable Register
Enable the interrupt of corresponding ADC12 memory (ADC12MEM).
Usually, you only need to enable one of the source.
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ADC12 Configuration
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ADC12 ConfigurationEnable/disable internal voltage
reference generator, set the voltage
reference to 1.5/2.5 V
Enable/disable overflow interrupt
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ADC12 Configuration
We use this bit in ADC12CTL0 register to trigger a conversion. You
can try out the other source of trigger. The benefit of using Timer_A
or Timer_B trigger sources is you don’t need CPU to handle the trigger
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ADC12 Configuration
We use ADC12 internal
oscillator as clock source
Depends on your requirement, choose
the proper conversion sequence
mode
Use Pulse Sample Mode
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Example: Single Channel, single conversionOnly one input channel, one conversion at a
timeInitialization
Turn-on ADC12
Enable Conversion
Configure the ADC: ADC12CTL0 1. setting SHTx 2. setting voltage reference ADC12CTL1 1. setting CSTARTADDx (pointed to one memory) 2. setting SHSx 3. SHP = 1 4. setting ADC12 clock source 5. select single channel, single conversion modeADC12MCTLx 1. depends on the conversion mode you choose, and the input channel and voltage reference you want, set proper ADC12MCTLx register
Set ADC12ON to 1
Set ENC to 1Trigger a Conversion
You can use a timer to trigger a conversion, in the timer ISR, set
the ADC12SC bit to 1
An ADC interrupt generated when the conversion complete. The conversion result is available at the memory register you choose
You need to enable the corresponding interrupt.
The one selected by CSTARTADDx
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Example: Sequence of ChannelsMultiple input channels, a sequence of
conversionsInitialization
Turn-on ADC12
Enable Conversion
Configure the ADC: ADC12CTL0 1. setting SHTx 2. setting voltage reference 3. set MSC bit to 1 (multiple conversion automatically start) ADC12CTL1 1. setting CSTARTADDx (pointed to one memory) 2. setting SHSx 3. SHP = 1 4. setting ADC12 clock source 5. select Sequence-of-channels modeADC12MCTLx 1. depends on the conversion mode you choose, and the input channel and voltage reference you want, set proper ADC12MCTLx register 2. depends on the number of channels you want, set the EOS bit to 1 in the proper ADC12MCTLx register
Set ADC12ON to 1
Set ENC to 1Trigger a Conversion
You can use a timer to trigger a conversion, in the timer ISR, set
the ADC12SC bit to 1
An ADC interrupt generated when the last conversion complete. The conversion results are available at the memory registers you choose
You need to enable the interrupt of the last conversion memory.
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Today’s LabsLab 1: Light Sensor
use the sample code on websitechoose a light sensor on Tarokoconfigure the ADC to take samples from the
light sensorwhen the light sensor is covered by hand, turn
on a LED; when the hand remove, turn off the LED set a threshold
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Lab2: Infrared Proximity SensorConnect the sensor to
Tarokoconfigure the ADC to take
samples from the sensoruse an obstacle(hand, paper,
etc.) to approach the sensorif distance < 10 cm, Red
LED onif distance > 20 cm, Green
LED onelse, Yellow LED on
VccGND
Signal
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Lab 3: AccelerometerConnect the accelerometer module to TarokoConfigure a GPIO pin as a supply voltage source
for the accelerometer moduleconfigure the ADC to take samples from multiple
input channelsConfigure the LEDs
when accelerate in +X direction, turn on Red LED; accelerate in -X direction, turn off Red LED
when accelerate in +Y direction, turn on Green LED; accelerate in -Y direction, turn off Green LED
when accelerate in +Z direction, turn on Yellow LED; accelerate in -Z direction, turn off Yellow LED