ECE 4760: Laboratory 4

Tachometer and motor controller


You will build a digital tachometer which displays motor speed on a LCD display and controls the motor with user-selectable parameters to maintain constant speed. You will be required to use a multitasking kernel and write your program as tasks within the kernel API.


For this assignment you must write your code for a multitasking kernel called Tiny Real Time (TRT).
Look through the examples on the TRT page to see how to use the API and to download the kernel.
You must edit the trtSettings.h file!
If the kernel continually resets then:

IR sensor:
We will be bouncing infrared light off the hub of the fan and detecting intensity variations in the reflected light to determine the speed. The circuit below uses a infrared emitter to shine light onto a surface. The relected light is detected by a phototransistor. You will want to run the phototransistor output through an opamp comparator to produce fast, logic-level output swings. Even if the levels at the output of the phototransistor are compatable with CMOS logic, the rise time of the light will be too slow for accuracy. The 10K potentiometer sets the comparator threshold, the 1M resistor sets the hysteresis and may need to be adjusted. Hysteresis makes the rising/falling edges of the waveform less sensitive to noise.

Note the * in the following schematic indicating the long component lead!

The left image below shows a fan with a dab of white paint on the hub. The clear IR emitter is pointed at the hub. The dark phototransistor is also pointed at the hub. The top trace on the right shows the output from the phototransistor. As the white paint rotates in front of the sensor, the transistor turns on and the voltage drops. The bottom trace shows the output of the opamp. The threshold should be adjusted so that the opamp switches at a voltage where abs(dv/dt) is high. The output of the opamp could be fed directly into the int0 external interrupt pin (MCU pin D.2), as long as the opamp power rails are +5 and ground. Keep the opamp output away from the PWM lead coming from the MCU. Capacitative coupling can corrupt the output of the opamp!

For debugging, you can see a slight glow in the IR emitter using your cell phone camera because a solid state camera is sensitive to infrared light. You may need to shield the phototransistor from the LED by slipping a small piece of black paper between them so that the transistor sees the white paint, but not the LED. The symptom will be that the transistor output is always low.

fan + sensors scope image pulse train

Motor Control:
You will need to drive a fan from the mcu. Fans have motors which can cause nasty inductive spikes to wipe out the transistors in the mcu port. The circuit shown below is fairly safe. An optoisolator completely isolates the MCU from the motor. The diode placed across the motor shorts out spikes when the motor is turned off. The resistor grounding the base of the phototransistor should be set for best falltime, probably around 1Mohm. The motor capacitor should start around 0.1uf. Increase it if there is too much spike noise on the analog input, but be sure to use ceramic capacitors, not electrolytic. Electrolytic capacitors are too slow. The pinout of the 4N35 optoisolator and BUZ73 are also shown. Note that the bandwidth of the 4N35 is very small, so use a low PWM frequency, perhaps about 1000 Hz.

A matlab program demonstrating the PID control algorithm includes the following nonlinear effects: The sensor is modeled as producing a new value once/revolution. The effect is to make a feedback which is dependent on the speed of the motor, with the motor becoming more stable at higher speed. The motor is modeled as a second-order system when it is powered, and a first-order system when it is coasting. The controller has saturation (maximum voltage) and rectification (no negative output).


Write two to four tasks using the TRT kernel API and construct a circuit which will:

You will demo all the features above to your TA. Your program should not need to be reset during the demo.

Your written lab report should include the sections mentioned in the policy page, and :

Copyright Cornell University October 8, 2012