EE 308 - LAB 9

Using the HC12 Pulse Width Modulation Subsystem and the HC12 Pulse Accumulator

The speed of a motor can be adjusted by powering it with a pulse width modulated signal. Figure 1 shows how this can be done. The field effect transistor (FET), IRLD024, acts as a switch. When the signal on the gate of the FET is high the switch is closed, current flows through the motor, and the motor speeds up. When the signal is low, the switch is open, no current flows, and the motor slows down. With a high enough frequency PWM signal the amount the motor speeds up and slows down in one period is negligible, and the motor turns at a constant speed. By adjusting the duty cycle the speed of the motor can be controlled.

Figure 1: Using a pulse-width-modulated signal to adjust the speed of a motor.
\epsfig{file=lab09_fig1.eps, width=2in}\end{center}\end{figure}

To make a motor turn at a desired speed it is necessary to know how fast the motor is turning. Some motors have encoders which will generate hundreds of pulses in a single revolution of the motor. The motors you will use in this lab have an encoder which will generate one pulse per revolution. The encoder works as shown in Figure 2. A light emitting diode (LED) sends light to the base of a phototransistor. When the light shines on the base, the transistor turns on, and the voltage at the collector of the transistor is about 0.3 V, which is a digital 0. When something blocks the light from reaching the transistor base the transistor turns off, and the voltage on the collector goes to VCC, a digital 1. The motors you will use have such an optical encoder, in which the light from the LED to the transistor will be blocked once a revolution. Thus, you will be able to measure the speed of the motor. When connecting an analog signal (such as the output of a transistor collector) to a digital input (such as an HC12), it is a good idea to clean up the signal with a device called a Schmidt Trigger. A 74HC14 is an inverting Schmidt trigger which will be used to clean up the signal on the collector of the transistor.

Figure 2: Optical encoder which generates one pulse per revolution of the motor.
\epsfig{file=lab09_fig2.eps, width=3in}\end{center}\end{figure}

In this lab you will use the PWM subsystem of the HC12 to control the speed of a small motor, and use the timer/pulse accumulator subsystem to measure the speed of the motor.

Connect the motor and FET as shown in Figure 1. Let VMotor = 10 V. Connect the gate of the FET to the TTL output of the function generator on your breadboard. This will give you a signal with a 50% duty cycle. Verify that the motor turns smoothly until the frequency of the signal is reduced to a very low value. At what frequency does the motor become visibly jerky?

Set the frequency of the square wave at about 1 kHz. Connect the circuit shown in Figure 2. Look at the output of the 74HC14 with your logic analyzer. Verify that you get one pulse per revolution.

Connect the output of the 74HC14 to the PACTL input of the HC12. Put the PACTL in event count mode. Have the PACTL count the number of revolutions in 60 seconds. To wait for 60 seconds you can clear the PACTL counter, enable a TOF or RTI interrupt, and wait for the proper number of TOF or RTI interrupts to occur (how many of these are there in 60 seconds). After 60 seconds have passed, read the PACTL count register and print it to the screen. This will give you the motor speed in revolutions per minute (RPM).

Generate a 1 kHz pulse-width-modulated signal on Bit 3 of Port P of the HC12. The duty cycle of the signal should be determined by reading the four least significant bits of Port B:

PB3:0 Duty Cycle PB3:0 Duty Cycle
0000 0% 1000 80%
0001 10% 1001 90%
0010 20% 1010 100%
0011 30% 1011 100%
0100 40% 1100 100%
0101 50% 1101 100%
0110 60% 1110 100%
0111 70% 1111 100%

Run the motor with each of the duty cycles from Part 4. Record the speed in RPM for each duty cycle. Plot the motor speed as a function of duty cycle. How linear is it?

Compare your results to the results of at least two other groups. Do the motors all behave the same, or are there significant differences?

Bill Rison, < >
Thr Mar 11 1999

© 1999, New Mexico Tech