EE 308 -- LAB 13
Final Project - Motor Control

For your final project, you will use two HC11 boards as a motor controller (Figure 1). The two boards will be connected together through their SPI ports, one board acting as master and the other as slave. The slave board will control the speed of a motor using pulse width modulation, and will send the speed of the motor to the master board over the SPI interface. The master board will tell the slave board at what speed it wants the motor to run, and will display the speed received from the slave on its LEDs.

Figure 1: Block diagram for final project lab.

The master board will have a pot connected to it, which will be used to set the motor speed. The speed of the motor should be 0 RPM at 0 volts, and 3,000 RPM at 5 V.

The slave board will control the motor speed using pulse width modulation. It can control current through the motor by turning on and off an FET switch. The duty cycle (the percent of time the switch is turn on) controls the motor speed. A 100% duty cycle will yield maximum speed (about 3,000 RPM when Vmotor = 7 V), and duty cycles of about 10% or less will yield zero speed. An optical sensor attached to the motor will measure its speed. An LED sends light to an opto-transistor -- when the light from the LED can reach the transistor, the transistor will be turned on, current will flow through the 2.2 kOhm collector resistor, and the voltage at the collector will be about 0.5 V. A blade on the motor will momentarily block the light from the LED from reaching the opto-transistor. When this happens, the transistor will turn off, very little current will flow through the transistor, and the voltage at the collector will be about 5 V. This collector voltage is inverted and turned into a clean digital signal by the 74HC14 Schmitt trigger. By using a timer input capture pin to measure the period of the signal from the Schmitt trigger, you can determine the speed of the motor.

The slave board should receive the motor speed set point from the master board, and slowly increase the duty cycle of the pulse width modulation until the speed of the motor equals that commanded from the master. When the master commands the slave to reduce the motor speed, the slave should slowly decrease the duty cycle until the set point is reached.

Program the HC11s in the following way:

  1. The set point and the actual speed should be global variables in the master and the slave. Both should be saved as unsigned characters, with a value of 0 representing 0 RPM, and a value of 255 representing 3,000 RPM.

  2. The slave should use a TIC interrupt to measure the motor period, convert it to speed, and save it in the speed global variable.

  3. The slave should control the speed of the motor by pulse width modulation, using a TOC1 interrupt and both TOC1 and TOC2 to control the TOC2 output pin. The pulse width modulation frequency should be about 1 kHz. A successful TOC1 compare should force the TOC2 pin high, and a successful TOC2 compare should force the TOC2 pin low. This will allow you to easily program duty cycles from about 10% (at which point the motor should stop) to 100% (at which point the motor should operate at about 3,000 RPM).

  4. Once a second (using an XIRQ interrupt from the Real Time Clock chip) the master should read the voltage on the pot from the A/D converter, save it in a global variable and send the value to the slave over the SPI.

  5. When the slave receives an interrupt on the SPI system it should read the set point from the SPI, save it in a global variable, and return the actual motor speed to the master over the SPI.

  6. Using a TOI interrupt the master should decide what to display on the LEDs depending on what is set on the DIP switches:

    PA2 PA1 PA0
    PIA Port B Function
    0 X 0
    Motor Set Point
    0 X 1
    Motor Speed
    1 0 0
    Up Counter
    1 0 1
    Down Counter
    1 1 0
    1 1 1
    Turn Signal

    Table 1: PIA Port A inputs to control the PIA Port B functions.

  7. When the master receives a IRQ interrupt from CA1 of the PIA, it should set a global flag in the IRQ interrupt service routine.

  8. In its main program the master should monitor the global flag set in the IRQ interrupt. When the flag is set, it should print the time, set point and motor speed (in RPM) to the PC display, and clear the global flag.

Optional. Once you get this system working, program it into the EPROM version of the HC11 chip you received with your kit.

Bill Rison, < >
Wed Apr 16 1997

© 1997, New Mexico Tech