EE 308 - LAB 8

Final version for 2001


Using the 68HC12 Pulse Width Modulation Subsystem

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.


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

To make a motor turn at a desired speed it is necessary to know how fast the motor is turning. The motors you will use in this lab have encoders which will generate 320 pulses in a single revolution of the motor. The encoder works as shown in Figure 2. A light emitting diode (LED) sends light to an optical sensor. When the light shines on the sensor, the output of the optical sensor is VCC, a digital 1. When something blocks the light from reaching the sensor, the voltage goes to 0 V. a digital 0. As the motor turns, a transparent piece of plastic with black lines on it will pass through the sensor, and turn on and off the sensor. Thus, you will be able to measure the speed of the motor.


 
\begin{figure}
\begin{center}
\epsfig{file=lab07_fig2.eps, width=3in}\end{center}\end{figure}
Figure 2: Optical encoder which generates 320 pulses per revolution of the motor.

In this lab you will use the PWM subsystem of the HC12 to control the speed of a small motor, and use the input capture subsystem to measure the speed of the motor.

For the prelab do the calculations required for Parts 3 and 4. Write the program required for Parts 4, 5 and 6

1.
Connect the motor and FET as shown in Figure 1. Let VMOTOR = 15 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?

2.
Set the frequency of the square wave at about 1 kHz. Connect the circuit shown in Figure 2. It is essential that you put the 330 Ohm and 2.2 kOhm resistors in your circuit. Without these, the circuit will not work and you will destroy the optical sensor. Look at the output of the optical sensor with your logic analyzer. Verify that you get multiple pulses per revolution.

3.
Connect the output of the optical sensor to one of the input capture pins of the HC12. The motor I used had speed of about 800 RPM when I used a 100% duty cycle with a 5 V power supply for the motor.
(a)
With a 800 RPM motor speed, how much time will there be between successive rising edges from the optical sensor?

(b)
With a 10 RPM motor speed, how much time will there be between successive rising edges from the optical sensor?

Set the prescaler of the HC12 so the rollover time of the TCNT register is the smallest time which is larger than the above two numbers. What value did you use for the prescaler?

4.
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 6.25 % 1000 56.25%
0001 12.50% 1001 62.50%
0010 18.75% 1010 68.75%
0011 25.00% 1011 75.00%
0100 31.25% 1100 81.25%
0101 37.50% 1101 87.50%
0110 43.75% 1110 93.75%
0111 50.00% 1111 100.00%

Note that you should pre-calculate the duty cycles as the integer you will write to the duty cycle register which will give duty cycles closest to the values in the table. Do not use floating point arithmetic in your C program.

5.
Run the motor with each of the duty cycles from Part 4. Have the HC12 print the number of timer pulses between rising edges to the screen. Convert these numbers to RPM. Record the speed in RPM for each duty cycle. Plot the motor speed as a function of duty cycle. How linear is it?

6.
Add to your program an output capture function which will generate a 250 Hz square wave. Verify with the logic analyzer that your HC12 is generate a square wave of the appropriate frequency.

7.
Compare your results (speed of the motor vs. duty cycle) to the results of at least two other groups. Do the motors all behave the same, or are there significant differences?



Bill Rison
2000-02-29