EasyManua.ls Logo

Microchip Technology dsPIC30F - Page 252

Microchip Technology dsPIC30F
738 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
dsPIC30F Family Reference Manual
DS70059C-page 12-10 © 2004 Microchip Technology Inc.
12.4.2 Synchronous Counter Mode Using External Clock Input
When the TCS control bit (TxCON<1>) is set, the clock source for the timer is provided externally
and the selected timer increments on every rising edge of clock input on the TxCK pin.
External clock synchronization must be enabled for a Type A time base. This is accomplished by
setting the TSYNC control bit (TxCON<2>). For Type B and Type C time bases, the external
clock input is always synchronized to the system instruction cycle clock, T
CY.
When the timer is operated in the Synchronized Counter mode, there are minimum requirements
for the external clock high time and low time. The synchronization of the external clock source
with the device instruction clock is accomplished by sampling the external clock signal at two
different times within an instruction cycle.
A timer operating from a synchronized external clock source will not operate in Sleep mode,
since the synchronization circuit is shut-off during Sleep mode.
Example 12-2: Initialization Code for 16-bit Synchronous Counter Mode Using an
External Clock Input
Note: The external input clock must meet certain minimum high time and low time
requirements when Timerx is used in the Synchronous Counter mode. Refer to the
device data sheet “Electrical Specifications” section for further details.
; The following code example will enable Timer1 interrupts, load the
; Timer1 Period register and start Timer1 using an external clock
; and a 1:8 prescaler setting.
; When a Timer1 period match interrupt occurs, the interrupt service
; routine must clear the Timer1 interrupt status flag in software.
CLR T1CON ; Stops the Timer1 and reset control reg.
CLR TMR1 ; Clear contents of the timer register
MOV #0x8CFF, w0 ; Load the Period register
MOV w0, PR1 ; with the value 0x8CFF
BSET IPC0, #T1IP0 ; Setup Timer1 interrupt for
BCLR IPC0, #T1IP1 ; desired priority level
BCLR IPC0, #T1IP2 ; (this example assigns level 1 priority)
BCLR IFS0, #T1IF ; Clear the Timer1 interrupt status flag
BSET IEC0, #T1IE ; Enable Timer1 interrupts
MOV #0x8016, W0 ; Start Timer1 with prescaler settings at
; 1:8 and clock source set to the external
MOV w0, T1CON ; clock in the synchronous mode
; Example code for Timer1 ISR
__T1Interrupt:
BCLR IFS0, #T1IF ; Reset Timer1 interrupt flag
; User code goes here.
RETFIE ; Return from ISR

Table of Contents

Other manuals for Microchip Technology dsPIC30F