EE 308 - LAB 13

Final Project - Motor Control

For your final project, you will use an HC12 board as a motor controller (Figure 1). A potentiometer connected to the HC12's A/D converter will be used to set the motor's desired speed. The HC12 will control the speed of the motor using pulse width modulation

Figure 1: Block diagram for final project lab.
\begin{figure}\begin{center}
\epsfig{file=lab13_fig1.eps,width=6.5in}\end{center}\end{figure}

The HC12 will have a pot connected to it, which will be used to set the motor speed. The speed of the motor should be 500 RPM at 0 volts, and 3000 RPM at 5 V. As in Lab 7, you will use the HC12 Timer Imput Capture subsystem to measure the motor's speed, and the HC12 PWM subsystem to control the speed,

If the actual speed is slower than the desired speed, the HC12 should increase the duty cycle of the pulse width modulation until the speed of the motor equals the desired speed. If the actual speed is faster than the desired speed, the HC12 should decrease the duty cycle until the desired speed is reached. How to do this will be discussed in class.

Program the HC12 in the following way:

  1. The desired speed, actual speed and duty cycle should be global variables. The set point and actual speed should be unsigned characters, with a value of 0 representing 500 RPM, and a value of 255 representing 3,000 RPM. The duty cycle should also be an unsigned character for 8-bit PWM.

  2. The HC12 should use a timer input capture interrupt to measure the motor period, convert it to speed, and save it in the speed global variable.

  3. The HC12 should control the speed of the motor by pulse width modulation, as in Lab 7.

  4. About once every 64 ms (using an RTI interrupt) the HC12 should do the following:
    1. Read the voltage on the pot from the A/D converter to determine the desired speed.
    2. Calculate a new PWM duty cycle based on the current duty cycle and the difference between the actual and desired speeds:


      \begin{displaymath}DC_n = DC_o + k (S_d - S_a)\end{displaymath}

      where $DC_n$ is the new duty cycle, $DC_o$ is the old duty cycle, $S_d$ is the desired speed, and $S_a$ is the actual speed. ($k$ is a constant - an appropriate value can be found by experimentation. In class we will discuss how to find a good initial guess.)

    3. Update the PWM duty cycle register.

  5. In the main program loop, you should print some information to the screen, such as the desired and actual speeds, and the duty cycle.



Bill Rison
2001-04-17