Hardware Reference
In-Depth Information
TCTL4 5 0x01;
/* select to capture the rising edge of PT0 */
TFLG1 5 C0F;
/* cleared C0F flag */
while (!(TFLG1 & C0F));
/* wait for the first edge */
edge1 5 TC0;
while (!(TFLG1 & C0F));
/* wait for the second edge */
diff
5 TC0 2 edge1;
temp 5 10000001/(long)(2 * diff);
rpm
5 temp * 60;
return rpm;
}
8.11.3 Electrical Braking
Once a DC motor is running, it picks up speed. Turing off the voltage to the motor does
not make it stop immediately because the momentum will keep it rotating. After the voltage
is turned off, the momentum will gradually wear out because of friction. If the application does
not require an abrupt stop, then the motor can be brought to a gradual stop by removing the
driving voltage.
An abrupt stop may be required by certain applications in which the motor must run a few
turns and stop quickly at a predetermined point. This could be achieved by electrical braking.
Electrical braking is done by reversing the voltage applied to the motor. The length of time that
the reversing voltage is applied must be precisely calculated to ensure a quick stop while not
starting the motor in the reverse direction. A discussion of good motor braking algorithms is
outside the scope of this textbook. In a closed-loop system, the feedback can be used to deter-
mine where or when to start and stop braking and when to discontinue. In Figure 8.56, the mo-
tor can be braked by (1) reducing the PWM duty count to 0 or (2) setting port pin PP7 output to
high for an appropriate amount of time.
8.12 Summary
Many applications require a dedicated timer. Without a timer the following applications
will become very difficult or even impossible to implement:
The measurement of pulse width, frequency, period, duty cycle, and phase
difference
The detection of certain events
The creation of time delays
The generation of waveforms
The generation of a siren and playing of songs
Some HCS12 members implement an Enhanced Capture Timer (ECT) module, which
has the features of the Standard Timer Module (TIM) enhanced by additional functions. The
heart of the timer system is the 16-bit main timer, TCNT. This timer must be enabled in
order to run. Its clock signal is derived by dividing the E-clock by a prescaler. The prescale
factor can be from 1 to 128 for the standard timer module and the enhanced capture timer
module.
 
Search WWH ::




Custom Search