0% found this document useful (0 votes)
115 views27 pages

Lecture 8: Analog To Digital Converter: To Embedded Systems: Using Microcontrollers and The MSP430

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

Lecture 8: Analog To Digital Converter: To Embedded Systems: Using Microcontrollers and The MSP430

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

INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

LECTURE 8: ANALOG TO
DIGITAL CONVERTER
Lecture
M. Jiménez, R. Palomera, & I. Couver tier Slides
Series

INTRODUCTION TO EMBEDDED SYSTEMS:


Using Microcontrollers and the MSP430

© M. Jiménez et al. 2014

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

USING THE MSP430 ADCS


 ADCs built-in in MSP430 microcontrollers are all SAR or
Sigma Delta type converters.

 Some models are mentioned as having slope ADC


incorporated. In fact, they have comparators and I/O ports
with good performance by design for these applications.

 Low voltage series, on the other hand, have a set of analog


peripherals which allow configuring 8-bit SAR ADC
converters, but do not have the converter as a built in
peripheral.
 The actual ADCs that are available are the 10-bit SAR ADC
converter, ADC10, 12-bit SAR ADC converter, ADC12, and
the 16-bit and 24-bit sigma-delta converters SD16,
SD16_A, SD24, and SD24_A.

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

MSP430
ADC10

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

MSP430 ADC10 (ADC12) FEATURES


 ADC10 and ADC12 differ in very few aspects: resolution
and management of results.
 Hence, we limit our introduction to the ADC10 case. A
simplified block structure of the ADC10 system is shown in
Fig. 10.46.
 The ADC10 system has eight registers associated to it:
◦ • Two 16-bit read-and-write control registers: ADC10CTL0 and
ADC10CTL1. Some specific bits are read-only. They are reset on POR.
◦ • Two 8-bit read-and-write input enable registers: ADC10AE0 and
ADC10AE1. They are reset on POR.
◦ • One 16-bit read-only register, ADC10MEM, to receive conversion
results.
◦ • Two read-and-write data transfer control registers: ADC10DTC0 and
ADC10DTC1. Some specific bits are read-only. They are reset on POR.
◦ • On 16-bit read-and-write data transfer start address register:
ADC10SA, initialized with 0200h on POR. Bit 0 is hardwired to 0.

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

ADC10 Configuration

• ADC10CTL0 & ADC10CTL1—ADC10 Control Registers


• Used to configure how the ADC runs
• ADC10AE0 & ADC10AE1—Analog Input Enable Registers
• Specifies which pins should be used for analog input
• ADC10MEM—Conversion Memory Register
• This is where the conversion result is stored
• ADC10DTC0 & ADC10DTC1—Data Transfer Control Registers
• Used to control direct memory transfer of conversion results
• ADC10SA—Start Address Register for Data Transfer
• Specifies the starting address in memory where results are transferred

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

MSP430 ADC10 (ADC12) FEATURES


 ADC10 and ADC12 differ in very few aspects: resolution
and management of results.
 Hence, we limit our introduction to the ADC10 case. A
simplified block structure of the ADC10 system is shown in
Fig. 10.46.
 The ADC10 system has eight registers associated to it:
◦ • Two 16-bit read-and-write control registers: ADC10CTL0 and
ADC10CTL1. Some specific bits are read-only. They are reset on POR.
◦ • Two 8-bit read-and-write input enable registers: ADC10AE0 and
ADC10AE1. They are reset on POR.
◦ • One 16-bit read-only register, ADC10MEM, to receive conversion
results.
◦ • Two read-and-write data transfer control registers: ADC10DTC0 and
ADC10DTC1. Some specific bits are read-only. They are reset on POR.
◦ • On 16-bit read-and-write data transfer start address register:
ADC10SA, initialized with 0200h on POR. Bit 0 is hardwired to 0.

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

ADC10 Control Register 0—ADC10CTL0

We must tell ADC10 what voltage


reference source to use. For example, if
we want to use the supply voltage and
ground as the references, set bits 15-13 =
000 = SREF_0 (defined in header file).

Set these bits to ensure accurate


conversion voltage

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

ADC10 Control Register 0 — ADC10CTL0

Internal voltage
reference control.

Don’t forget to
turn the ADC on!

You do want interrupts,


don’t you?

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

ADC10 Control Register 1—ADC10CTL1

Choose your
input channels.

MSP430 Analog to Digital


Conversion

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

ADC10 Control Register 1 — ADC10CTL1

Choose your clock rate.

Choose your clock.

Specify your conversion sequence mode.

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

ADC10 Input Enable Control Reg 0 — ADC10AE0

ADC10 Conversion Memory Reg — ADC10MEM

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

10-BIT SAR CORE


 The core of the system is a switched capacitor SAR
converter. The SH unit in the figure is only functional, since
it is practically part of the core (see Fig. 10.42). It may be
turned on or off with the ADC10ON bit—Bit 4 in
ADC10CTL0–.

 A read only flag ADC10BUSY—bit 0 in ADC10CTL1—is set


to indicate that sampling and conversion are in progress.
The result is written to register ADC10MEM in a format
selected with ADC10DF—bit 9 in ADC10CTL1:
◦ • The default right justified straight binary in ADC10MEM. Bits
b15 to b10 are 0. Result 0000h corresponds to the bottom of
input range VR−. Result goes from 0000h to 03FFh.
◦ • Left justified two’s complement format, with bits b5 to b0
equal to 0. Result 0000h corresponds to the midpoint of input
range. Results read from 8000h to 7FC0h.

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

10-BIT SAR CORE


 Core Clock The clock for the SAR core is a signal ADC10CLK,
which is generated from a divider. This divider receives an input
from one of four sources: The MSP430 clocks ACLK, MCLK, or
SMCLK, or else a built-in oscillator ADC10OSC. The selection is
done with bits 4-3, ADC10SSELx, and division with bits
ADC10DIVx, bits 7-5 all found in control register 1.

 Conversion ADC10 must be enabled with bit ENC (bit 1 in control


register 0) for a conversion to take place. Conversion may be
started by software setting bit ADC10SC, or else by any of timer A
outputs, Timer_A.OUT0, Timer_A.OUT1 or Timer_A.OUT2. The
trigger source may be selected with bits SHSx in ADC10CTL1.
Once triggered, the sample and hold time is controlled with bits
ADC10SHTx of ADC10CTL0, to be 4, 8, 16, or 64 times ADC10CLK.
ADC10SC is automatically reset when conversion is terminated.

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

10-BIT SAR CORE


 Inputs The analog inputs to the ADC unit may be external
inputs A0, A1,…, the number depending on the model. The
external references and internal reference may serve as
inputs. Internally generated values 0.5 VCC or from
temperature sensor may also be inputs to the converter.

 The selection is done with bits 15-12, INCHx, from control


register 1. In the same register, bits 2-1, CONSEQx, allow to
control for single or multiple conversions from different
channels.

 Inputs A1, A2,…are shared with I/O pins. Hence, the


ADC10AE0 and ADC10AE1 registers are used for enabling
the connections for these pins to the converter.

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

10-BIT SAR CORE


 Result and transfer The ADC10MEM is readable. However,
we usually need to transfer the results to another place in
memory. This is done with the ADC10 data transfer
controllers. One convenient feature is that data transfer is
done without the CPU intervention (it may even be off)
directly interacting with DMA. These registers function as
follows:

◦ • ADC10DTC0: selects one or two blocks in destination, or continuous


transfers.
◦ • ADC10DTC1: provides the number of transfers per block. Transfer is
disabled when the value is 0.
◦ • ADC10SA is the start address for destination. To enable transfers, the
user must write to this register.

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

CLOCK SOURCES
 The SAR core of the MSP430G2xxx3 microcontroller can be
clocked by either ACLK, SMCLK, MCLK or by the internal
Oscillator ADC10OSC.The clock produced by the internal
oscillator ADC10OSC is in the range of 5MHz and varies with
changes in temperature and Voltage. The default clock for
ADC10 is taken from ADC10OSC .

 ADC10SSELx bits on ADC10CTL register is used to select


the clock source. The selected clock can be divided by
using ADC10DIVx bits (on ADC10CTL) before giving to the
SAR core. The clock coming after the Divider is
called ADC10CLK and is also used for setting Sample and
Hold Timing.

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

MODES OF OPERATION
 ADC10 of MSP430G2xxx can operate in 4 different modes

 Single Channel,Single Conversion :


◦ A single channel is converted once
 Sequence of Channels:
◦ A Sequence of channels are converted once
 Repeat Single Channel:
◦ A single channel is converted repeatedly
 Repeat Sequence of Channels:
◦ A Sequence of channels are converted
repeatedly

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

CONFIGURING THE ANALOG PINS


 The analog channels of ADC10 are selected by
using INCHx bits on ADC10CTL1 register. In the
case of MSP430G2xxx3 there are 8 analog channels
+ 2 internal channels. The internal channels are not
available outside the chip and are used for
connecting the internal temperature sensor and
VCC/2.
 Like any other microcontroller the ADC pins of
MSP430 are shared with other peripherals like
Digital IO, Comparator Inputs etc, So before
reading analog values from outside we have to
select the analog function of the port pins .This is
done by setting the appropriate bits in the Analog
Enable Control Register ADC10AE0.

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

CONFIGURING THE ADC CORE


 Before configuring the ADC, the SAR core have to
be switched on using ADC10ON bit and ENC bit
should be cleared. After that you can configure
the clock sources, interrupts, analog channels etc.
After the configuration is over you can start the
ADC conversion by setting ADC10SC bit and ENC.
 The ADC conversion can be started by software or
by hardware. In Software ,the conversion is
started by setting the ADC10SC bit by the
program. In Hardware, the conversion is started
by an external peripheral like Timer A ,this
method is recommended if there are time and
power constraints.

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

ADC10 INTERRUPTS

 After the conversion is finished the ADC10 sets


the ADC10IFG flag and an interrupt is generated.
The converted value is available in the
ADC10MEM register for further processing.
The ADC10IFGflag is automatically reset after the
interrupt is processed. Please note that for the
interrupt to occur the ADC10IE flag and GIE
bit should be set.

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

#include "msp430g2553.h"
#include "intrinsics.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // stop WDT

// ADC configuration,V+ref=3V,V-ref=0V,Channel=A0
ADC10CTL0 = ADC10ON + ADC10IE; // Vref Vr+=3v,Vr-=VSS,
// S&Htime = 4 X ADCCLK,ADC10 on,ADC interrupts enabled
ADC10CTL1 = ADC10DIV_7; // INCH =0000->A0,ADCCLK src = ADC10CLK,
// ADCCLK/8,Single Channel Single Conversion
ADC10AE0 = INCH_0; // channel A0

ADC10CTL0 |= ENC + ADC10SC; // Start Conversion

_BIS_SR(LPM0_bits +GIE); // Go to LPM0,interrupts enabled


}

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

/***************************************************************************/
/* interrupt vectors for MSP430 */
/***************************************************************************/
#pragma vector = ADC10_VECTOR
__interrupt void adc10_interrupt(void)
{
ADC10CTL0 |= ENC + ADC10SC; // Start Conversion again
}

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier


INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430
INTRODUCTION TO EMBEDDED SYSTEMS: Using Microcontrollers and the MSP430 Chapter 10

END OF LECTURE 8 SLIDES

© 2014 by M. Jiménez, R. Palomera, & I. Couvertier

You might also like