
μ
PD17016, 17017
254
20.5.2 Program example of IF counter function
A program example of the IF counter function is shown below.
As shown in this example, wait time must elapse after an instruction that selects the P1D
3
/FMIFC or P1D
2
/
AMIFC pin as the IF counter pin has been executed before counting is started.
This is because the internal AC amplifier may not operate normally immediately after each pin has been
selected, as explained in 20.5.1.
Example To count frequency on P1D
3
/FMIFC pin (gate time: 8 ms)
INITFLG NOT IFCMD1, IFCMD0, IFCCK1, NOT IFCCK0
; Selects FMIFC pin and sets gate time to 8 ms.
; Internal AC amplifier stabilization time
Wait
IFC_RES_AND_START
; Resets and starts counter (sets IFCRES and
; IFCSTRT flags)
Note
.
; Macro definition is used because SET2 instruction cannot
; be used.
LOOP:
SKT1
IFCGOSTT
; Detects opening/closing of gate.
; Branches to READ: when gate is closed.
BR
READ
Processing A
; Do not read data of IF counter by this processing A.
; Do not select BEEP function.
BR
LOOP
READ:
GET
DBF, IFC
; Reads value of IF counter data register to data buffer.
Note
Refer to
20.7.3 Notes on using embedded macroinstruction SETn to IFCRES and IFCSTRT
flags
.
20.5.3 Error of IF counter
The IF counter may have a gate time error and a count error.
These errors are explained in (1) and (2) below.
(1) Error of gate time
The gate time of the IF counter is created by dividing the 4.5-MHz system clock.
Therefore, if the system clock deviates “+x” ppm, the gate time deviates “–x” ppm.
(2) Count error
The IF counter counts the frequency at the rising edge of an input signal.
If a high level is input to the pin when the gate is opened, therefore, one excess pulse is counted.
However, counting is not performed because of the status of the pin when the gate is closed.
Therefore, a count error of “+1, –0” may occur.