570
Digital Electronics
The digital-to-analogue converter, on the other hand, provides an interface between the microcontroller
and the actuators that provide the control function. As an example, both 68HC11 and 68HC12 from
Freescale Semiconductor have eight-channel, eight-bit analogue-to-digital converters. The digitalto-analogue converter function in microcontrollers is provided by a combination of pulse width
modulator (PWM) followed by a filter. As an example, 68HC12 has an on-chip 16-bit/two-channel
PWM. Analogue-to-digital and digital-to-analogue converters are discussed at length in Chapter 12.
14.2.5.2 I/O Ports
I/O ports provide an interface between the microcontroller and the peripheral I/O devices such
as the keyboard, display, etc. The 80C51 family of microcontrollers has four eight-bit I/O ports.
Microcontroller 68HC11 offers 38 general-purpose I/O pins including 16 bidirectional I/O pins, 11
input-only pins and 11 output-only pins.
14.2.5.3 Counters/Timers
Counters/timers usually perform the following three functions. They are used to keep time and/or
measure the time interval between events, count the number of events and generate baud rates for
the serial ports. Microcontroller 68HC11 has a 16-bit timer system comprising three input capture
channels, four output compare channels and one additional channel that can be configured as either an
input or an output channel. Another popular microcontroller type number, PIC 16F84, has an eight-bit
timer/counter with an eight-bit prescaler.
Figure 14.4 shows a generalized block schematic representation of the timer subsystem of a
microcontroller. The clock signal controls all timing activities of the microcontroller. The counter is
used both to capture external timing events (accomplished by the timer input block) and to generate
timing events for external devices (accomplished by the timer output block). While the former process
is typically used to measure the frequency and time interval of periodic signals, the latter generates
control signals for external devices.
It may be mentioned here that a timing event to be captured or generated is nothing but a change
in logic status on one of the microcontroller I/O pins configured as an input pin if the event is to be
captured and as an output pin if it is to be generated. Figure 14.5 shows a block schematic arrangement
of the timer input block of Fig. 14.4. As shown in the figure, the counter captures the input time
event in the form of its contents at the time of occurrence of the event. In fact, the counter captures
the relative time of the event as the counter is free running. Absolute timing values can be computed
from the relative system clock values. As an example, consider a microcontroller with a 10 MHz
clock and a 16-bit counter/timer subsystem. This counter will take 6.5536 ms to count from 0000 to
FFFF (hex notation). Let us assume that it is desired to find the frequency of a periodic signal whose
successive rising or falling edges are observed to occur at 0010 and 0150. 0010 and 0150 respectively
correspond to 16 and 336 in decimal. Therefore, the time interval between two successive edges equals
320 ×0.1 = 32 s. The signal frequency is therefore (1/32) MHz = 31.25 kHz.
Figure 14.6 shows a block schematic arrangement of the timer output block of Fig. 14.4. The diagram
is self-explanatory. Again, free-running counter values can be used to synchronize the time of the
desired logic state changes on the output pin. This feature can also be used to generate an aperiodic
pulse or a periodic signal of any desired duty cycle.
For timer input and output operations, the microcontroller needs to set up some special registers.
For timer input operation, as shown in Fig. 14.5, registers are required to program the event (logic
HIGH or logic LOW), configure the physical I/O pin as an input pin and also set up parameters for the
Digital Electronics
The digital-to-analogue converter, on the other hand, provides an interface between the microcontroller
and the actuators that provide the control function. As an example, both 68HC11 and 68HC12 from
Freescale Semiconductor have eight-channel, eight-bit analogue-to-digital converters. The digitalto-analogue converter function in microcontrollers is provided by a combination of pulse width
modulator (PWM) followed by a filter. As an example, 68HC12 has an on-chip 16-bit/two-channel
PWM. Analogue-to-digital and digital-to-analogue converters are discussed at length in Chapter 12.
14.2.5.2 I/O Ports
I/O ports provide an interface between the microcontroller and the peripheral I/O devices such
as the keyboard, display, etc. The 80C51 family of microcontrollers has four eight-bit I/O ports.
Microcontroller 68HC11 offers 38 general-purpose I/O pins including 16 bidirectional I/O pins, 11
input-only pins and 11 output-only pins.
14.2.5.3 Counters/Timers
Counters/timers usually perform the following three functions. They are used to keep time and/or
measure the time interval between events, count the number of events and generate baud rates for
the serial ports. Microcontroller 68HC11 has a 16-bit timer system comprising three input capture
channels, four output compare channels and one additional channel that can be configured as either an
input or an output channel. Another popular microcontroller type number, PIC 16F84, has an eight-bit
timer/counter with an eight-bit prescaler.
Figure 14.4 shows a generalized block schematic representation of the timer subsystem of a
microcontroller. The clock signal controls all timing activities of the microcontroller. The counter is
used both to capture external timing events (accomplished by the timer input block) and to generate
timing events for external devices (accomplished by the timer output block). While the former process
is typically used to measure the frequency and time interval of periodic signals, the latter generates
control signals for external devices.
It may be mentioned here that a timing event to be captured or generated is nothing but a change
in logic status on one of the microcontroller I/O pins configured as an input pin if the event is to be
captured and as an output pin if it is to be generated. Figure 14.5 shows a block schematic arrangement
of the timer input block of Fig. 14.4. As shown in the figure, the counter captures the input time
event in the form of its contents at the time of occurrence of the event. In fact, the counter captures
the relative time of the event as the counter is free running. Absolute timing values can be computed
from the relative system clock values. As an example, consider a microcontroller with a 10 MHz
clock and a 16-bit counter/timer subsystem. This counter will take 6.5536 ms to count from 0000 to
FFFF (hex notation). Let us assume that it is desired to find the frequency of a periodic signal whose
successive rising or falling edges are observed to occur at 0010 and 0150. 0010 and 0150 respectively
correspond to 16 and 336 in decimal. Therefore, the time interval between two successive edges equals
320 ×0.1 = 32 s. The signal frequency is therefore (1/32) MHz = 31.25 kHz.
Figure 14.6 shows a block schematic arrangement of the timer output block of Fig. 14.4. The diagram
is self-explanatory. Again, free-running counter values can be used to synchronize the time of the
desired logic state changes on the output pin. This feature can also be used to generate an aperiodic
pulse or a periodic signal of any desired duty cycle.
For timer input and output operations, the microcontroller needs to set up some special registers.
For timer input operation, as shown in Fig. 14.5, registers are required to program the event (logic
HIGH or logic LOW), configure the physical I/O pin as an input pin and also set up parameters for the
