![](http://datasheet.mmic.net.cn/270000/16LF628A_datasheet_15978171/16LF628A_52.png)
PIC16F627A/628A/648A
DS40044A-page 50
Preliminary
2002 Microchip Technology Inc.
7.3
Timer1 Operation in
Asynchronous Counter Mode
If control bit T1SYNC (T1CON<2>) is set, the external
clock input is not synchronized. The timer continues to
increment asynchronous to the internal phase clocks.
The timer will continue to run during SLEEP and can
generate an interrupt on overflow, which will wake-up
the processor. However, special precautions in soft-
ware are needed to read/write the timer (Section 7.3.2).
7.3.1
EXTERNAL CLOCK INPUT TIMING
WITH UNSYNCHRONIZED CLOCK
If control bit T1SYNC is set, the timer will increment
completely asynchronously. The input clock must meet
certain minimum high and low time requirements. Refer
to Table 17-9 in the Electrical Specifications Section,
timing parameters 45, 46, and 47.
7.3.2
READING AND WRITING TIMER1 IN
ASYNCHRONOUS COUNTER
MODE
Reading the TMR1H or TMR1L register while the timer
is running, from an external asynchronous clock, will
produce a valid read (taken care of in hardware). How-
ever, the user should keep in mind that reading the 16-
bit timer in two 8-bit values itself poses certain prob-
lems since the timer may overflow between the reads.
For writes, it is recommended that the user simply stop
the timer and write the desired values. A write conten-
tion may occur by writing to the timer registers while the
register is incrementing. This may produce an unpre-
dictable value in the timer register.
Reading the 16-bit value requires some care.
Example 7-1 is an example routine to read the 16-bit
timer value. This is useful if the timer cannot be
stopped.
EXAMPLE 7-1:
READING A 16-BIT FREE-
RUNNING TIMER
Note:
In Asynchronous Counter mode, Timer1
cannot be used as a time-base for capture
or compare operations.
; All interrupts are disabled
MOVF
TMR1H, W
MOVWF
TMPH
MOVF
TMR1L, W
MOVWF
TMPL
MOVF
TMR1H, W
SUBWF
TMPH, W
;Read high byte
;
;Read low byte
;
;Read high byte
;Sub 1st read with
;2nd read
;Is result = 0
;Good 16-bit read
BTFSC
GOTO
STATUS,Z
CONTINUE
;
; TMR1L may have rolled over between the
; read of the high and low bytes. Reading
; the high and low bytes now will read a good
; value.
;
MOVF
TMR1H, W
MOVWF
TMPH
MOVF
TMR1L, W
MOVWF
TMPL
; Re-enable the Interrupts (if required)
CONTINUE
;Read high byte
;
;Read low byte
;
;Continue with your
;code