
© 2010 Microchip Technology Inc. DS70205C-page 11-17
Section 11. Timers
Timers
11
The input clock (FCY or TxCK) to all 32-bit timers has prescale options of 1:1, 1:8, 1:64 and 1:256.
The clock prescaler is selected using the Timer Clock Prescaler bits (TCKPS<1:0>) in the Type
B Timer Control register (TxCON<5:4>). The prescaler counter is cleared when any of the
following occurs:
• A write to the Type B Timer register (TMRx) or Type B Timer Control register (TxCON)
• Clearing the Timer Enable bit (TON) in the Type B Timer Control register (TxCON<15>)
• Any device Reset
The 32-bit Timer module is enabled or disabled using the TON bit in the Type B Timer Control
registers (TxCON<15>).
For 32-bit read/write operations to be synchronized between the lsw and msw of the 32-bit timer,
additional control logic and holding registers are used (refer to Figure 11-6). Each Type C timer
has a register called TMRyHLD, which is used when reading or writing the timer register pair. The
TMRyHLD registers are used only when the respective timers are configured for 32-bit operation.
Assuming TMR3:TMR2 form a 32-bit timer pair, the user application must first read the lsw of the
timer value from the TMR2 register. The read of the lsw automatically transfers the contents of
TMR3 into the TMR3HLD register. The user application can then read TMR3HLD to get the msw
of the timer value.
To write a value to the TMR3:TMR2 register pair, the user application must first write the msw to
the TMR3HLD register. When the lsw of the timer value is written to TMR2, the contents of
TMR3HLD is automatically transferred to the TMR3 register.
The code for accessing the 32-bit timer is shown in Example 11-5.
Example 11-5: 32-Bit Timer Access
// Reading from 32-bit timer
lsw = TMR2; // Read lsw from the Type B timer register
msw = TMR3HLD; // Read msw from the Type C timer holding register
// Writing to 32-bit timer
TMR3HLD = msw; // Write msw to the Type C timer holding register
TMR2 = lsw; // Write lsw to the Type B timer register
Komentarze do niniejszej Instrukcji