6.11. LABORATORY EXERCISE: GENERATION OF VARYING PULSE WIDTH 213
6.11 LABORATORY EXERCISE: GENERATION OF VARYING
PULSE WIDTH MODULATED SIGNALS TO CONTROL
Purpose: The purpose of this laboratory exercise is to program an MSP430 series controller to
generate a pulse-width modulated signal/waveform with varying duty cycle to control the speed of
a DC motor. The program requires you to use the input capture and output compare capabilities of
the controller. To meet the requirements of this laboratory exercise, you must
• Use the output compare system to modify the duty cycle of the output waveform,
• Use the input capture system to monitor the number of pulses generated by the output compare
system and adjust the output waveform appropriately,
• Change the duty cycle based on a desired DC motor speed proﬁle,
• Conﬁgure Port 1 pins, and
• Verify the output waveform by connecting the output pin on Port 1 to an oscilloscope.
Documentation: User Manual of your MSP430 microcontroller board
Prelab: For the prelab, complete a ﬂowchart and pseudocode for your program.
Description: As we learned in this chapter, the timer system of the MSP430 series microcon-
troller is used for signal generation, measurement, and timing. In this lab, you are asked to conﬁgure
an MSP430 series controller to generate desired output waveforms using its output compare system.
The contents of the output compare system registers are programmed to set and clear the logic states
of an output pin and cause an interrupt related to the output pin.
The output event occurs when the free running counter (TAR) value matches the value stored
in the designated output compare register (TACCRx). By adjusting the value in the TACCRx
register, one can program MSP430 to change the time when an output event occurs. The input
capture system is used to monitor the incoming signal. In this laboratory exercise, it is used to count
the number of pulses being generated by the output compare pin. By counting the number of pulses,
the input capture system can keep track of the time the output waveform is generated and modify
the duty cycle accordingly. The physical pins used in this laboratory are P1.1 and P1.2, where P1.1
will be used as the input capture pin and the P1.2 pin will be used as the output compare pin.
Tasks: In this lab, you need to write a program to modify the duty cycle of an output periodic
signal in real-time. The desired speed proﬁle (velocity versus time) is shown in Figure 6.23. The
y-axis shows the desired duty cycle, and the x-axis shows the time duration for the entire proﬁle.The
duty cycle should increase from 0% to 50% during the ﬁrst three seconds, maintain the 50% duty