Timer1 and it's Programming
The Timer1 timer/counter module incorporates these features:
- Software selectable operation as a 16-bit timer or counter
- Readable and writable 8-bit registers (TMR1H and TMR1L)
- Selectable clock source (internal or external) with device clock or Timer1 oscillator internal options
- Reset on CCP Special Event Trigger
- Device clock status flag (T1RUN)
A simplified block diagram of the Timer1 module is shown in Figure The module incorporates its own low-power oscillator to provide an additional clocking option. The Timer1 oscillator can also be used as a low-power clock source for the microcontroller in power-managed operation. Timer1 can also be used to provide Real-Time Clock (RTC) functionality to applications with only a minimal addition of external components and code overhead. Timer1 is controlled through the T1CON Control register. It also contains the Timer1 Oscillator Enable bit (T1OSCEN). Timer1 can be enabled or disabled by setting or clearing control bit, TMR1ON (T1CON<0>).
|7||RD16: 16-Bit Read/Write Mode Enable bit|
|6||T1RUN: Timer1 System Clock Status bit|
|5-4||T1CKPS<1:0>: Timer1 Input Clock Prescale Select bits|
|3||T1OSCEN: Timer1 Oscillator Enable bit|
|2||T1SYNC: Timer1 External Clock Input Synchronization Select bit|
|1||TMR1CS: Timer1 Clock Source Select bit 1 = External clock from pin RC0/T1OSO/T13CKI (on the rising edge) 0 = Internal clock (FOSC/4)|
|0||TMR1ON: Timer1 On bit|
Timer1 Block Diagram
Timer1 can operate in one of these modes:
- Synchronous Counter
- Asynchronous Counter
The operating mode is determined by the clock select bit, TMR1CS (T1CON<1>). When TMR1CS is cleared (= 0), Timer1 increments on every internal instruction cycle (FOSC/4). When the bit is set, Timer1 increments on every rising edge of the Timer1 external clock input or the Timer1 oscillator, if enabled. When Timer1 is enabled, the RC1/T1OSI and RC0/ T1OSO/T13CKI pins become inputs. This means the values of TRISC<1:0> are ignored and the pins are read as ‘0’.
An on-chip crystal oscillator circuit is incorporated between pins T1OSI (input) and T1OSO (amplifier output). It is enabled by setting the Timer1 Oscillator Enable bit, T1OSCEN (T1CON<3>). The oscillator is a lowpower circuit rated for 32kHz crystals. It will continue to run during all power-managed modes. The circuit for a typical LP oscillator is shown in Figure12-3. Table12-1 shows the capacitor selection for the Timer1 oscillator. The user must provide a software time delay to ensure proper start-up of the Timer1 oscillator.
- Created, Edited and Notes by Prof. Sujit Wagh, SKNCOE, Pune
- WikiNote Foundation