8 Timers PIC18F46k22
8 Timers PIC18F46k22
8 Timers PIC18F46k22
Timers
• Each one of the timers in a medium-end PIC microcontroller is
based on an 8-bit or 16-bit incrementing synchronous counter.
• These counters can be programmed to count internal or
external pulses.
• The count number stored by each counter can be read or
modified by accessing the special function registers associated
with that timer.
• Some of the bits in these registers are used to notify of counter
overflow, being able to generate an interrupt request to the
microcontroller.
Timers in PIC
Microcontrollers
• Timer0 consists of a prescaler and an 8-bit incrementing
synchronous counter that can be read or written using the
special function register TMR0
• The prescaler is an asynchronous counter with a
programmable division factor.
• Timer0 can be configured to count machine cycles or to
count external pulses. When counting machine cycles it is
said to operate as a timer.
• When counting external pulses, it is said that it operates
as a counter.
Timer Module
• The division factor (P) for the prescaler assigned to
Timer0 can have the
• following values:
• P = 2, 4,…, 2n+1,…, 256, (6.2)
• with n = 0, 1, …, 7 being the value stored in bits
PS2:PS0.
• When the prescaler is assigned to the WDT, the division
factor is P = 1,
• 2, 4, …, 2n, 2n+1, …, 128, as shown in table 2.1.
• The overflow time for Timer0 can be calculated as follows. Let N be the
• number of pulses that need to reach Timer0 to overflow it, P the prescaler
• division factor, and Ti the period of the pulses at the input of the prescaler.
• If Timer0 works as a timer, then Ti is the duration of a machine cycle; if it
• operates as a counter, Ti is the period of the external pulses. The overflow
• time (To) can be found as
• Note that the value stored in the TMR0 register is not N but its 2-complement
• using 8 bits, which is the value that N needs to reach 256
• If Timer0 works as a timer (counting machine cycles) it is necessary to
• keep in mind that the counting is inhibited during two machine cycles
• after writing data in the TMR0 register. Therefore, the value that needs to
• be loaded in the TMR0 is