Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 3: ADC.

Similar presentations


Presentation on theme: "Lab 3: ADC."— Presentation transcript:

1 Lab 3: ADC

2 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 etc. Convert to voltage Converts voltage to digital number Today’s labs

3 General View Each storage register associated with a control register
Positive/Negative voltage reference: define the upper and lower limits of the conversion 16 conversion result storage registers 4 clock sources available for ADC12 clock Software configurable sample-and-hold period 12 input channels available

4 Conversion Formula This is a conversion formula of ADC
For MSP430 ADC12 module It is 12-bit ADC If Vin > Vref+ => output 4095 (max) If Vin < Vref- => output 0 (min)

5 Input Channels 12 input channels available Multiplexed with P6 GPIO
8 external input pins: A0 ~ A7 2 external voltage reference pins: VeREF+, VeREF- 1 internal temperature sensor 1 supply voltage monitor Multiplexed with P6 GPIO Setting P6SEL to choose the function you want

6 Internal Voltage Reference Generator
Voltage references are used as a base of the conversion Input 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 reference MSP430 has a built-in voltage reference generator It has two selectable voltage levels 1.5V and 2.5V

7 Voltage References Options
3 positive reference sources AVcc – Positive supply voltage VREF – internal voltage reference Can be 1.5V or 2.5V, depends on your selection VeREF+ – external positive voltage reference 2 negative reference sources AVss – Negative supply voltage (GND) VeREF- -- external negative voltage reference 6 combinations in total

8 ADC12 Conversion Modes Single channel single-conversion
A single channel is converted once Sequence-of-channels A sequence of channels is converted once Repeat-single-channel A single channel is converted repeatedly Repeat-sequence-of-channels A sequence of channels is converted repeatedly

9 Conversion Memory 16 ADC12MEMx memory registers to store conversion results Each ADC12MEMx is configured with an associated ADC12MCTLx control register. EOS: End of sequence, indicates last conversion SREFx: Select voltage reference INCHx: Select Input Channel CSTARTADDx bits define the first memory used for conversion This bit is in ADC12CTL1 control register

10 Use in sequence of channels mode
ADC12MCTLx Use in sequence of channels mode

11 Example Depends on the setting of conversion mode, ADC12MCTLx and CSTARTADDx, the ADC will have different behavior Sequence of Channels CSTARTADDx = 0000 CSTARTADDx = 0100 Single-channel If you need 5 input channels If you need 7 input channels CSTARTADDx = 0000 CSTARTADDx = 0100 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 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 You need to set ADC12MCTL0 (choose the input channel and voltage reference). And the conversion result will store in ADC12MEM0 You need to set ADC12MCTL8 (choose the input channel and voltage reference). And the conversion result will store in ADC12MEM8

12 Conversion Clock 4 clock sources available
ADC12OSC: ADC12 internal oscillator MCLK SMCLK ACLK For simplicity, we use ADC12OSC in our lab Independent of the system clock

13 ADC12 Core Two phases for a conversion Conversions in MSP430 ADC12
Sample-and-hold A/D conversion Conversions in MSP430 ADC12 Triggered by a SHI signal Two 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

14 The SHI Signal Four selectable sources for SHI ADC12SC bit
A single bit in ADC12 control register, set this bit to high will trigger a conversion Timer_A output unit 1 (TA1) Timer_B output unit 0 (TB0) Timer_B output unit 1 (TB1) Lab_2 slide

15 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)

16 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 =>

17 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/ ) second = 12.8 μs

18 Rs: Source Resistance Many 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 is it’s only 16 possible setting, just try it out!

19 ADC12 Interrupts ADC12 has 18 interrupt sources:
ADC12IFG0-ADC12IFG15 flag Associated with each ADC12MEMx, indicates a conversion of this memory is complete ADC12OV: 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

20 ADC12IV, Interrupt Vector Generator
All ADC12 interrupts are source to a single interrupt vector Similar to Timer_A3 The highest priority enabled ADC12 interrupt generates a number in the ADC12IV register Highest 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, ……….

21 Reset of Interrupts Overflow interrupts (memory overflow and conversion time overflow) will reset automatically when Any access, read or write, of the ADC12IV register ADC12IFG0-ADC12IFG15 flag will reset when Accessing their associated ADC12MEMx register

22 Interrupt Enable Register
Enable the interrupt of corresponding ADC12 memory (ADC12MEM). Usually, you only need to enable one of the source.

23 ADC12 Configuration

24 Enable/disable overflow interrupt
ADC12 Configuration Enable/disable internal voltage reference generator, set the voltage reference to 1.5/2.5 V Enable/disable overflow interrupt

25 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

26 We use ADC12 internal oscillator as clock source
ADC12 Configuration Use Pulse Sample Mode We use ADC12 internal oscillator as clock source Depends on your requirement, choose the proper conversion sequence mode

27 Example: Single Channel, single conversion
Only one input channel, one conversion at a time Initialization 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 mode ADC12MCTLx 1. depends on the conversion mode you choose, and the input channel and voltage reference you want, set proper ADC12MCTLx register Turn-on ADC12 Set ADC12ON to 1 Enable Conversion Trigger a Conversion Set ENC to 1 An ADC interrupt generated when the conversion complete. The conversion result is available at the memory register you choose You can use a timer to trigger a conversion, in the timer ISR, set the ADC12SC bit to 1 You need to enable the corresponding interrupt. The one selected by CSTARTADDx

28 Example: Sequence of Channels
Multiple input channels, a sequence of conversions 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 mode ADC12MCTLx 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 Initialization Turn-on ADC12 Set ADC12ON to 1 Enable Conversion Trigger a Conversion Set ENC to 1 An ADC interrupt generated when the last conversion complete. The conversion results are available at the memory registers you choose You can use a timer to trigger a conversion, in the timer ISR, set the ADC12SC bit to 1 You need to enable the interrupt of the last conversion memory.

29 Today’s Labs Lab 1: Light Sensor use the sample code on website
choose a light sensor on Taroko configure the ADC to take samples from the light sensor when the light sensor is covered by hand, turn on a LED; when the hand remove, turn off the LED set a threshold

30 Lab2: Infrared Proximity Sensor
Connect the sensor to Taroko configure the ADC to take samples from the sensor use an obstacle(hand, paper, etc.) to approach the sensor if distance < 10 cm, Red LED on if distance > 20 cm, Green LED on else, Yellow LED on Signal GND Vcc

31 Lab 3: Accelerometer Connect the accelerometer module to Taroko
Configure a GPIO pin as a supply voltage source for the accelerometer module configure the ADC to take samples from multiple input channels Configure 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


Download ppt "Lab 3: ADC."

Similar presentations


Ads by Google