O'Reilly logo

Microcontroller Programming and Interfacing Texas Instruments MSP430 by Daniel J. Pack, Steven F. Barrett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

252 8. ANALOG PERIPHERALS
on or turn off low pass filter to the output of the comparator. The filter removes comparator output
oscillation, providing an output not affected by system noise sources.
The output of the comparator is stored in the CBOUT bit (bit 0) in the CBCTL1 register.
When the interrupt enabling CBIE bit in the Comparator_B Interrupt Control Register (CBINT)
is set, either output 1 or output 0 causes an interrupt. The CBIES (bit 3) bit of the CBCTL1 register
is used to pick which output causes an interrupt to occur: 0 for a rising edge and 1 for a falling edge.
The associated flag is the CBIFG bit (bit 0) in register CBINT. As before, we should have the
general interrupt enable bit (GIE) set for the interrupt system to be turned on.
When the CBEX bit (bit 5) of the CBCTL1 register is set, two inputs are exchanged and
the output is inverted. The polarity bit, CBOUTPOL, in the CBCTL1 register is used to invert
(CBOUTPOL = 1) output polarity, if necessary.The CBSHORT bit (bit 4) of the CBCTL1 register
is used to short (set this bit) the two input pins selected by CBIPSEL and CBIMSEL bits. Why
would anyone wants to do this? Suppose CBIPSEL bits selected pin CB0 and CBIMSEL bits
selected pin CB1. If we connect a simple capacitor to pin CB1 and allow an input analog signal to
be connected to pin CB0, the CBSHORT bit can be used to transport the analog input from pin
CB0 to pin CB1, and the capacitor will capture the voltage of the analog signal appearing on the
CB0 pin.
Please refer to the documentation for the specific MSP 430 microcontroller being used for a
detailed description of the comparator registers.
8.5.2 MSP430 12-BIT ANALOG-TO-DIGITAL CONVERTER
The ADC converter receives up to 16 input signals on pins A0 through A15 and a built-in multiplexer
selects an analog input to be sampled, quantized, and encoded as specified by control registers. An
ADC conversion is initiated by writing to one of the control registers, results are written to result
registers (ADC12MEMx), and the corresponding flags are set in the status register (ADC12IFG).
If an input voltage value is equal to reference low (REF-) value, 000h results while an input
voltage equal to reference high (REF+) voltage is represented as 0FFFh. The results are encoded
either as unsigned or 2’complement binary values. The ATD converter of MSP430 uses 12 bits to
sample analog signals, providing 4096 different quantized levels (0000h - 0FFFh) to represent a
sample value, has 16 input channels that can be connected to external (12) and internal (4) signals,
and processes more than 200 thousand samples per second. It has 18 associated interrupts and a
flexible means to provide reference voltages. In this subsection, we study how this converter works.
The converter can convert one sample from a single source or multiple sources or multiple samples
from a single source or multiple sources.
Figure 8.7 shows a block diagram of the converter. It is configured using ADC12CTL0 and
ADC12CTL1 registers as we will show.
Its a bit overwhelming, at first glance, to see all the components of the converter, but once
you know how each component works and how it is integrated to the overall system and practice
using it a few times, you will feel at ease with the converter.
8.5. MSP430 ANALOG-TO-DIGITAL CONVERTER 253
$
$
$
$
$
$
$
$
$
$
9H5()
95()9H5()
7HPSHUDWXUH6HQVRU
$9FF$9VV
,1&+[
6DPSOH
+ROG
95 95
ELW$'&
&RQYHUW %XV\
6+3
6$03&21

$9VV

$9FF
5()%857 $'&65
5()
65()
65()
65()
$'&21
9RU9
5HI9ROWDJH
5()21
5()B
9FF
5()21
,1&+[ $K
25*DWH
'LYLGHUZLWK

$'&',9[
$'&3',9
$'&66(/[




$'&26&
$&/.
0&/.
60&/.
3UHGLYLGHU
6DPSOH7LPHU

6+72[
$'&6+7[
06&
6+,
,66+
(1&
6+6;
7LPHU
6RXUFH
6\QF
$'&0(0
[
0HPRU\%XIIHU
$'&0(0
$'&0&7/
[
0HPRU\&RQWURO
$'&0&7/




$'&6&
,QYHUWHU
6\QF
Figure 8.7: A block diagram of the MSP430 12-bit analog-to-digital converter.
Lets start from the location where an input signal enters the converter. For all remaining
discussions, refer to Figure 8.7.To use the converter, a user must first turn it on using the ADC12ON
bit (bit 4) in the ATD12 Control Register 0 (ATD12CTL0).
There are 16 different locations where signals enter the converter as shown in the left of
Figure 8.7: Pins A0 through A15. Of the 16 pins, 12 pins (A0-A7 and A12-A15) are used to usher
in analog input signals to the converter. Pins A8 and A9 are connected to a positive reference voltage
and a negative reference voltage, which can be supplied by a user with external voltage sources
or using the MSP430 internal reference voltage generator module discussed in this chapter. The
ADC12SREFx bits (bits 6-4) in the ADC12 Memory Control Register x (ADC12MCTLx) are
used to select one of eight possible selections as shown in Table 8.1. The ADC12REFON bit (bit
5) in the ADCCTL0 register turns on (1) the reference voltage module (top right of the figure) to
enable the converter to use internal reference voltages.The ADC12REF2_5V bit (bit 6) of the same

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required