Professional Documents
Culture Documents
in
PIC 16F877
three
TIMER-0, TIMER1,andTIMER2.
. These timer module terminals are also
TIMER-0 module
Timer-0 module has built in
timer/counter
8 bit
It is easily readable/writable
Easily select internal/external clock pulses
Edge selection for external clock pulse
Built in 8 bit software programmable prescalar functions((shared with Watchdog
timer)
Interrupt with overflow from the value FFh
to 00h
TMR0.
The Timer0 module has a dedicated 8bit
register that can be accessed for read and
write operations.
This register can be accessed from BANK 0 and
BANK 2, and is named "TMR0". A direct read
(MOVf TMR0,w) will transfer the value of the
Timer0 counter directly to the W register,
while a direct write (MOVwf, TMR0) will
transfer the content of the W register to the
Timer0 counter.
OPTION_REG register
The operation of the Timer0
(T0CS):
This is the "TMR0 Clock Source Select bit". The
Prescaler Assignment
bit(PSA)
NB:
When the prescaler is assigned to the
timer/counter, any write to the TMR0 register
will clear the prescaler;
When the prescaler is assigned to watch-dog
timer, a CLRWDT instruction will clear both the
prescaler and WDT;
ie,
If the prescaler is assigned to the Timer0 module, then
these 3 bits will determine the division rate. If for
example the division rate is 64, then the TMR0 module
will increase it's value by one, after 64 counts.
Timer-0 Interrupt
bit TMR0IE.
Bit TMR0IF must be cleared in software
by the Timer 0 module Interrupt Service
Routine before re-enabling this interrupt.
The TMR0 interrupt cannot awaken the
Processor from Sleep since the timer is
shut-off during Sleep.
NOTES:
Setting Timer0:
Timer mode is selected by the T0CS bit of the
NOTES
To measure time:
Reset the TMR0 register or write some decided
value to it;
Elapsed time (in microseconds when using
Notes..
To count pulses:
The polarity of pulses are to be counted is
selected on the RA4 pin are selected by the
TOSE bit of the OPTION register (T0SE:
0=positive, 1=negative pulses); and
Number of pulses may be read from the TMR0
register. The prescaler and interrupt are used
in the same manner as in timer mode.
TIMER1
TIMER1
1 - LP oscillator is enabled for timer TMR1 clock (oscillator with low power consumption
and frequency 32.768 kHz); and
0 - LP oscillator is off.
T1SYNC - Timer1 External Clock Input Synchronization Control bit enables synchronization
of the LP oscillator input or T1CKI pin input with the microcontroller internal clock. When
counting pulses from the local clock source (bit TMR1CS = 0), this bit is ignored.
1 - Counts pulses on the T1CKI pin (on the rising edge 0-1); and
Timer1..
.
Timer TMR1 Oscillator
RC0/T1OSO and RC1/T1OSI pins are used to register pulses coming
output of comparator C2. This gate allows the timer to directly time
external events using the logic state on the T1G pin or analog events
using the comparator C2 output. Refer to figure above. In order to
time a signals duration it is sufficient to enable such gate and count
pulses having passed through it.
Timer TMR1 Prescaler
Timer TMR1 has a completely separate prescaler which allows 1, 2, 4
Timer mode
Counter Mode
The Counter mode is selected by setting timer 1
Counter Mode.
SYNCHRONOUS COUNTER
TMR1 in counter mode
Timer TMR1 starts to operate as a counter by
TIMER2
TMR2
TIMER2
The pulses from the quartz oscillator first pass
NB:
Upon power-on, the PR2 register contains the
value FFh;
Both prescaler and postscaler are cleared by
writing to the TMR2 register;
Both prescaler and postscaler are cleared by
writing to the T2CON register; and
On any reset, both prescaler and postscaler are
cleared.