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

6.10. INPUT CAPTURE AND OUTPUT COMPARE FEATURES 205
6.10.5 INPUT CAPTURE
As mentioned earlier, the purpose of capture functions of the MSP430 microcontroller is to time
incoming external signal events. Suppose you want to capture the time period between two consec-
utive events, say customers entering your retail store. You must have some means to record the time
of the first event and the second event. The input capture system in Timer_A and Timer_B systems
give us those capabilities, which we present in this section. Figure 6.19 shows components that make
up an input capture channel, and Figure 6.20 shows the contents of the control register to configure
the capture system. For the rest of the discussion, refer to both Figure 6.19 and Figure 6.20. The
&&,)*[
&DSWXUH
,QWHUUXSW
6\VWHP
&&,
*,(
&&,$
&&,%
*1'
9&&
&&,6[
&0[
7$&&5[
7$5
/DWFK
Figure 6.19: Input Capture System Diagram.
Capture Mode (CMx) bits (bits 15 and 14) of the TACCTL register determine the capture events
as shown below.
00 - no capture
01 - capture rising edge
10 - capture falling edge
11 - capture both edges
The Capture/Compare Input Select (CCISx) bits (bits 13 and 12) are used to select the input to be
captured as follows.
00 - capture compare input port A CCIxA
01 - capture compare input port B CCIxB
206 6. TIMER SYSTEMS
10 - Ground
11 - Supply voltage Vcc
The Capture Mode (CAP) bit (bit 8) of the Timer_A Capture Control Register (TACCTLx)
register is used to configure channel x to be either as an input capture (1) channel or as an output
compare (0) channel. When the event designated by CMx bits appears on the input channel pin, the
current value of free running counter TAR is captured in the Timer_A Capture/Compare Register
x (TACCRx) register and the corresponding flag, Capture/Compare Interrupt Flag (CCIFG) (bit
0), in the TACCTLx register is set. If the Capture/Compare Interrupt Enable (CCIE) bit (bit 4) is
set and the General Interrupt Enable (GIE) bit is activated, the interrupt system is configured to
service the interrupt. If another input capture event occurs before the TACCRx is read, the Capture
Overflow (COV) bit (bit 1) of the TACCTLx turns to 1 (set).
7LPHUB$&DSWXUH&RPSDUH&RQWURO5HJLVWHU7$&&7/DW
&0; &0; &&,6 &&,6 6&6
66&,
8QXVHG &$3
UZUZUZUZUZUUUZ

28702' 28702' 28702' &&,( &&, 287 &29 &&,)*
UZUZUZUZUUZUZUZ

Figure 6.20: Input Capture and Output Compare Control Register.
Example: In this input capture example, we use the MSP430 Launch Pad Development Tool.
This evaluation board is part of the MSP430 Value Line. The board is equipped with the 14 pin
MSP430G2211. The microcontroller socket on the board allows a 20 pin MSP430G2231 micro-
controller. We use the controller to capture the pulse width of an incoming signal on P1.0. We
only show the capture program segment, assuming all appropriate initialization steps are already
taken. The program uses variable ’Flag’ to count the number of incoming events (rising edge or a
falling edge). Note that by storing the TACCRO0 times when the two consecutive events occur
and computing the difference between the two times, we calculated the pulse width. Definitions for
pre-defined settings are provided in the header file for the MSP430G2211. The computation for
determining elapsed time does not take into account events lasting longer than the rollover time of
the counter. That computation is left as a homework assignment at the end of the chapter.
;---------------------------------------------------------------------
bic.b #01, &P1DIR ;setup P1.0 as input

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