Page 146 - Programming Microcontrollers in C
P. 146
Input/Output 131
operated as either an input capture or an output compare. Each output
compare can have its events coupled to other registers to control
intricate timing events with fine time resolution. We will not see the
direct programming of a TPU in this text, but we will see some of the
types of events that are controlled by the TPU programmed with the
usual 16-bit timer.
On the newer computers, such as the MCORE architecture, a
time-of-day (TOD) clock has been introduced. This clock is based on
a 32768-Hz watch crystal. These crystals are readily available, small,
very accurate, and quite inexpensive. Their only problem is that they
are slow, and are not very good for fine time measurements unless
the crystal is used as a time base to a frequency synthesizer.
Another timer function found on most microcontrollers is the
computer operating properly (COP) or watchdog timer. Most
microcontrollers are placed in embedded controls. That is, the
microcontroller is a part of a larger system, and usually an operator
never deals directly with the microcontroller. Even though great care
has been taken in the design of the microcontroller, it is possible to
cause these devices to get lost from the program that they are
executing. The power might dip, or a large transient magnetic field
might cause the part to go into abnormal operation. In such a case,
the easiest way to restore normal operation is to send the part through
a reset sequence. Such a sequence will restore all of the initial internal
status of the microcontroller, execute the initialization code procedure
of the program, and restart the execution of the application loop. A
COP timer provides just this function. A COP timer is a timer with a
relatively long period. Once the COP timer is started, it is necessary
for the main program to reset the COP periodically prior to the
expiration of the COP period. The COP timer is never allowed to
time out. If the computer gets lost, the program no longer resets the
COP, so the timer will eventually overflow, and this operation causes
the microcontroller to reset. Therefore, if the part ever gets lost from
its normal program sequence, the COP will force a reset and restore
the normal operation of the system.
Digital Input/Output
Most microcontrollers have several digital I/O ports. Usually a port
consists of eight or fewer bits, and the bits in these ports can be outputs,
inputs, or often bit programmable as either input or output bits. If a