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 197
P5DIR |= 0x02; //Set P5.1 to output direction
__bis_SR_register(LPM3_bits + GIE); //Enter LPM3 w/interrupt
}
// Basic Timer interrupt service routine
#pragma vector=BASICTIMER_VECTOR
__interrupt void basic_timer(void)
{
P5OUT ˆ= 0x02; //Toggle P5.1 using exclusive-OR
}
//***********************************************************************
6.10 INPUT CAPTURE AND OUTPUT COMPARE FEATURES
In this section, we study the input capture and output compare features of the MSP430 micro-
controller. We begin with background information and theory, followed by MSP430 specific timer
information and application examples.
6.10.1 TIMING SYSTEM OVERVIEW AND BACKGROUND THEORY
As we have learned earlier in this chapter, the heart of the timing system is the time base. The time
base frequency of an oscillating signal is used to generate a baseline clock signal. For a timer system,
the system clock is used to update the contents of a special register called a free running counter. The
job of a free running counter is to count up (increment) each time it sees a rising edge (or a falling
edge) of a clock signal. Thus, if a clock is running at the rate of 2 MHz, the free running counter will
count up at every 0.5 microseconds. All other timer related units reference the contents of the free
running counter to perform input and output time related activities: measurement of time periods,
capture of timing events, and generation of time related signals.
For input time related activities,all microcontrollers typically have timer hardware components
that detect signal logic changes on one or more input pins. Such components rely on a free running
counter to capture external event times. We can use such ability to measure the period of an incoming
signal, the width of a pulse, and the time of a signal logic change.
For output timer functions, a microcontroller uses a comparator, a free running counter, logic
switches, and special purpose registers to generate time related signals on one or more output pins.
A comparator checks the value of the free running counter for a match with the contents of another
special purpose register where a programmer stores a specified time in terms of the free running
counter value. The checking process is executed at each clock cycle and when a match occurs, the
corresponding hardware system induces a programmed logic change on a programmed output port
198 6. TIMER SYSTEMS
pin. Using such capability, one can generate a simple logic change at a designated time incident: a
pulse with a desired time width or a pulse width modulated signal to control servo or Direct Current
(DC) motors.
You can also use the timer input system to measure the pulse width of an aperiodic signal. For
example, suppose that the times for the rising edge and the falling edge of an incoming signal are
1.5 sec and 1.6 sec, respectively. We can use these values to easily compute the pulse width of 0.1
second.
The second overall goal of the timer system is to generate signals to control external devices.
Again, an event simply means a change of logic states on an output pin of a microcontroller at a
specified time. Now consider Figure 6.15. Suppose an external device connected to the microcon-
troller requires a pulse signal to turn itself on. Suppose the particular pulse the external device needs
is 2 millisecond wide. In such situations, we can use the free running counter value to synchronize
the time of desired logic state changes. Naturally, extending the same capability, we can also generate
a periodic pulse with a fixed duty cycle or a varying duty cycle.
Free-Running
Counter
Special Storage
Register
Programmed
Event
- Toggle
- Logic high
- Logic low
Physical
Output
Pin
Timer Output
Flag
Timer Output
Interrupt
System
Comparator
Figure 6.15: A diagram of a timer output system.
From the examples we discussed above, you may have wondered how a microcontroller can to
compute absolute times from the relative free running counter values, say 1.5 second and 1.6 second.

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