Page 283 - Programming Microcontrollers in C
P. 283
268 Chapter 5 Programming Large 8-Bit Systems
The program used to obtain the data in the above table was a
slight modification of the motor control program listing given in
Listing 5-6. The only change in this program was that the function
@port void IC1_Isr(void) from Listing 5-7 was used. This
routine stores in the location measured_period a value equal to
the average of the last eight measured periods.
For several reasons, a reed switch is probably the worst example
of an input sensor that you can find for a microcontroller. I chose this
input because it is the poorest, and the result has been satisfactory.
With reed switches, there are serious bounce problems on both the
rising and falling edges of the signals. The life expectancy for a reed
switch is relatively small, about ten million closures. During the course
of preparing this text, I broke one reed switch and had probably a
total of several hours of service out of the two used for these
experiments. In practice, it is recommended that rotational
measurements be made with optical interrupters. Do not, however,
think that an optical interrupter is free from bounce problems. An
optical interrupter will exhibit both bounce and also a relatively slow
rise time. In such a case, it is necessary to use a software debounce
technique and also an external Schmidt trigger circuit to create a
quick and stable rise time that can be captured by the microcontroller.
The data for the above table were measured on the circuit shown in
Figure 5-2. It was found that the PWM to voltage conversion was very
accurate and repeatable with many changes in the system. For example,
the prescaler value was changed from the value of 4 discussed above
to 2 and up to 16. No difference could be noted in the PWM to voltage
conversion over this range. Also, the input capture values were quite
stable. The program in Listing 5-6 was compiled and used to complete
the measurements. The PWM_count value was changed manually over
the range of values shown above. The value for icap period is the value
found in measured_period in the program. The voltage measured
was the integrated value that was sent into the input of the MC33033
motor driver. The RPM was calculated as
60000
RPM =
measured_period
Data from this table are used to create an equation that relates RPM
to the PWM_count. This equation will be used in the program to