piclab8-motorrpm

3
ETEC 4501 - Digital Controls PIC Lab 8 – Measuring the RPM of a DC Motor Program Definition: Write a program to measure the rotational speed of a DC motor. Discussion: The speed of a motor may be measured by using a variety of devices; the simplest of which is a photo detector. This device consists of a light source and a phototransistor that provides an output proportional to the amount of light received from the light source. These two devices may be either separate or combined into a single unit. When used with a means to block or reflect the light, it may be used to detect rotation. We will be using a QRB 1114 Phototransistor Reflective Object Sensor. This device has both an LED (E) and phototransistor (S) in a single package. As the schematic in Figure 2 shows, the LED emits infrared light that is reflected back on to the base of a phototransistor. When illuminated, the phototransistor turns on and conducts current between the collector and Copyright 2005-2007 Janna B. Gallaher Figure 4: Photosensor and Motor Figure 1: QRB 1114 Figure 2: QRB 1114 Schematic Figure 3: QRB 1114 Pin Designations

Upload: truong-tuan-vu

Post on 06-Feb-2016

219 views

Category:

Documents


0 download

DESCRIPTION

PICLab8-MotorRPM

TRANSCRIPT

Page 1: PICLab8-MotorRPM

ETEC 4501 - Digital ControlsPIC Lab 8 – Measuring the RPM of a DC Motor

Program Definition:

Write a program to measure the rotational speed of a DC motor.

Discussion:

The speed of a motor may be measured by using a variety of devices; the simplest of which is a photo detector. This device consists of a light source and a phototransistor that provides an output proportional to the amount of light received from the light source. These two devices may be either separate or combined into a single unit. When used with a means to block or reflect the light, it may be used to detect rotation.

We will be using a QRB 1114 Phototransistor Reflective Object Sensor. This device has both an LED (E) and phototransistor (S) in a single package. As the schematic in Figure 2 shows, the LED emits infrared light that is reflected back on to the base of a phototransistor. When illuminated, the phototransistor turns on and conducts current between the collector and

Copyright 2005-2007 Janna B. Gallaher

Figure 4: Photosensor and Motor

Figure 1: QRB 1114 Figure 2: QRB 1114 Schematic

Figure 3: QRB 1114 Pin Designations

Page 2: PICLab8-MotorRPM

the emitter. If the light is blocked, the transistor turns off providing a high impedance between the collector and the emitter.

A plastic disk has been attached to the armature of the dc motor. The disk has black and white sections which will either reflect the light from the LED or absorb it. The light colored side of the disk is reflective and will reflect the light back into the phototransistor. As the motor turns, the alternating light and dark areas will form a time varying square wave at the collector of the sensor. This signal will be used to measure the motor rpm. See Figure 5.

Pr oced ure:

1.1.Connect a QRB 1114 mounted to a motor according to the schematic in Figure 6. Using an oscilloscope, adjust the photosensor aim to achieve a square wave similar to Figure 5. Note that Vdd

and Vss are +5 and Gnd respectively from the LabX1 board.

2. Connect the photosensor signal output to the PIC using CCP1 (pin 17) as the input.

3. Write a program that uses the Capture and Compare Module 1 to detect each falling edge of the waveform and counts these transitions. Display the counts on the LCD. Use the CCP1IF to

tell when the transition occurs. (And don’t forget to reset it after you have reacted to the

transition.) Make sure that you have a 1mhz clock (Fosc/4) and set the timer Prescale to 1:8.4. CCP1 works with Timer1 to capture the count of this timer whenever CCPIF is raised. The data is

put into CCPR1L and CCPR1H (it is a 16 bit timer). You can use this information to determine the time required for a single revolution by subtracting the time captured during a transition from the time captured at the previous transition. Note that this is “seconds per revolution” and you will need to convert it to “revolutions per second.” You will also need to turn the clock ticks into seconds. Do this by using the clock frequency, Fosc/4, and the Prescale value.

5. Display the rpm value on the LCD.6. Verify that your measurement is accurate by measuring the waveform with the oscilloscope as in

Figure 7. 7. Determine why the waveform as viewed at pin 17 has an exponential rise and fall instead of the

square appearance seen in Figure 5.

Copyright 2005-2007 Janna B. Gallaher

Figure 5: Square Wave OutputFigure 6: Photosensor Signal Conditioning

Figure 7: Waveform At Pin 17 - CCP1

Page 3: PICLab8-MotorRPM

Copyright 2005-2007 Janna B. Gallaher