M68HC11
REFERENCE MANUAL
PULSE ACCUMULATOR
MOTOROLA
11-7
gate the B register instead and store the result to PACNT (negative of $00 is $00).
Save A in a RAM variable so software can decrement it at each overflow. As the pulse
accumulator starts counting, the first overflow will occur after detecting the 256th event
(counter counts $00-01-02 ... FE-FF-00). The second overflow will occur after the
512th count. If the RAM variable was decremented at each overflow (it started at $02),
it would become $00 after the second overflow (i.e., after the desired 512 events).
For case 2, negate the B register and store the result to PACNT (negative of $03 is
$FD). As the pulse accumulator starts counting, the first overflow will occur after de-
tecting the third event (counter counts $FD-FE-FF-00). The second overflow will occur
after the 259th count, and the third overflow will occur after the 515th count. A third
overflow is needed because there was an initial remainder that had to be counted be-
fore starting to count whole sets of 256 events.
The user can write a program that will handle either case by checking the B register to
see if it was zero. If it was not zero, the A register is incremented before storing it to
the RAM variable that keeps track of overflows. Before negating the B register, test B
and branch around an increment A register instruction if the B register was zero. This
procedure is demonstrated in the following partial listing:
---- cc 02 03
---- 40
---- 27 01
---- 4c
---- 5o
---- f7 10 27
---- b7 D0 00
The test B instruction can be eliminated (saving a byte of program space and two cy-
cles of execution time) by checking the carry flag that results after the negate-B oper-
ation. Carry is set in all cases except when B is zero). The following partial listing
demonstrates this slightly shorter procedure:
[3]
[2]
[2]
[2]
[2]
[4]
[4]
LDD
TSTB
BEQ
INCA
NEGB
STAB
STAA
#515
Get desired count in A:B
Test for remainder count
If none; skip the INCA
Increment the overflow count
Two’s complement remainder in B
Store to pulse accum counter
Store to RAM overflow variable
ARNINC
ARNINC
PACNT
OVCNT
---- cc 02 03
---- 50
---- 27 01
---- 4c
---- f7 10 27
---- b7 D0 00
This alternate approach illustrates that a sophisticated, careful user can sometimes
find tricks to save memory and execution time, but are they that important in all MCU
applications The costs of this trick and others like it are 1) it often makes the program
slightly more difficult to understand (more risk of a mistake), and 2) it takes extra de-
velopment time. Remember, the savings in this case is just one byte of program space
and two cycles of execution time.
[3]
[2]
[2]
[2]
[4]
[4]
LDD
NEGB
BCC
INCA
STAB
STAA
#515
Get desired count in A:B
C-bit only cleared if B was 0
If B was ($00); skip the INCA
Increment the overflow count
Store two’s comp. remainder count
Store to RAM overflow variable
ARNINC
ARNINC
PACNT
OVCNT
11.3 Gated Time Accumulation Mode
This mode changes the pulse accumulator from a counter into a timer. In this mode,
the 8-bit PACNT is incremented every 64th E-clock cycle provided the PAI pin is ac-
tive. The PEDGE bit controls which level at the PAI pin inhibits counting. This mode is