Page 290 - Programming Microcontrollers in C
P. 290
Timer Operations 275
TMSK1.OC2I=OFF; /* disable OC2 interrupt */
TMSK1.IC1I=ON; /* enable IC1 interrupt */
}
@port void OC3_Isr( void) /* the PWM isr */
{
TFLG1=OC1F; /* reset OC1 interrupt flag */
TOC1+=PWM_period;
OC1D.OC1D7 ^=ON;
TFLG1=OC3F; /* reset OC3 interrupt flag */
TOC3=TOC1+PWM_count;
if(++count==COUNT_ONE_QUARTER)
{
count=0; /* enter the speed control */
tick = TRUE; /* about each quarter of
of a second */
}
}
Listing 5-7: Motor Control Program
In this program, dynamic debounce is used. In the function
IC1_Isr() the debounce time is a calculated value rather than a
mere 3 ms as was done in Listing 5- 6. Here the debounce lock-out
time is five-eighths of the current measured period. This value goes
beyond the half-way point in the input waveform enough to avoid
any bounce that will occur during the rise time of the input signal.
The remainder of this program is quite similar to that in Listing 5-6.
We have completed most of the application. The remaining parts
of the program are to find a means to read into the microcontroller
the speed that is desired for the motor, and to integrate and debug the
whole program. Usually, the speed is established by some measure
ment being done with the microcontroller. Let us approach the
problem a little differently. Instead of making the speed a result of a
measurement, let’s enter the speed into the part through the asyn
chronous serial port.
Serial Communications Interface (SCI)
The SCI is another of the very useful peripheral functions found
on the MC68HC11 family of microcontrollers. In fact, the SCI is