MOTOROLA
11-6
PULSE ACCUMULATOR
M68HC11
REFERENCE MANUAL
PAII, PAIF — Pulse Accumulator Input Edge Interrupt Enable and Flag
The PAIF status bit is automatically set to one each time a selected edge is detected
at the PA7/PAI/OC1 pin. This status bit is cleared by writing to the TFLG2 register with
a one in the corresponding data bit position (bit 5). The PAII control bit allows the user
to configure the pulse accumulator input edge detect for polled or interrupt-driven op-
eration but does not affect the setting or clearing of the PAIF bit. When PAII is zero,
pulse accumulator input interrupts are inhibited, and the system is operating in a polled
mode. In this mode, the PAIF bit must be polled (sampled) by user software to deter-
mine when an edge has occurred. When the PAII control bit is one, a hardware inter-
rupt request is generated each time PAIF is set to one. Before leaving the interrupt
service routine, software must clear PAIF by writing to the TFLG2 register. For addi-
tional information, refer to
10.2.4 Tips for Clearing Timer Flags
.
11.2 Event Counting Mode
Many microcontroller unit (MCU) applications require "things" to be counted. These
things are called events, but in real applications they might be anything: pieces on an
assembly line, cycles of an incoming signal, or units of time. To be counted by the
pulse accumulator, these things must be translated into rising or falling edges on the
PAI pin. Either edge will do because software can pick which edge will be recognized.
A trivial example of event counting might be to count pieces on an assembly line. A
light emitter/detector pair could be placed across the path of the pieces so that, as
each piece passes the sensor, the light beam is interrupted and a logic-level signal is
produced, which can be connected to the PAI pin.
11.2.1 Interrupting after N Events
By writing to the PACNT, the pulse accumulator can be set up to produce an interrupt
after N events. The trick is to write the twos complement of the number (N) to PACNT
so that the counter will overflow after N counts. If the following program sequence is
used, the PACNT will overflow after the 100th count:
---- 86 64
---- 40
---- b7 10 27
[2]
[2]
[4]
LDAA
NEGA
STAA
#100
Hex ($64)
Two’s complement ($9C)
Store to pulse accum counter
PACNT
11.2.2 Counting More Than 256 Events
More than 256 events can be counted by using software to keep track of how many
times the PACNT overflows. Before the first event, calculate the number of overflows
needed and a value corresponding to any remainder that is left after seeing how many
whole times 256 goes into the intended count. Two cases are used as examples. In
the first case, 512 ($0200) events will be counted; in the second case, 515 ($0203)
events will be counted. In both cases, assume the desired count is in the D register.
Since D is the concatenation of the A register (upper 8 bits of D) and the B register
(lower 8 bits of D), division to see how many whole times 256 can go into the desired
count is not necessary (the A register has this count).
For case 1, two overflows are needed (there is no remainder). Zero is stored to
PACNT. For reasons illustrated in the following paragraphs, the user may wish to ne-