EasyManua.ls Logo

Microchip Technology dsPIC30F - Page 275

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...
© 2004 Microchip Technology Inc. DS70060C-page 13-7
Section 13. Input Capture
Input Capture
13
Example 13-1: Prescaled Capture Code Example
; The following code example will set the Input Capture 1 module
; for interrupts on every second capture event, capture on every
; fourth rising edge and select Timer 2 as the time-base. This
; code example clears ICxCON to avoid unexpected interrupts.
BSET IPC0, #IC1IP0 ; Setup Input Capture 1 interrupt for
BCLR IPC0, #IC1IP1 ; desired priority level
BCLR IPC0, #IC1IP2 ; (this example assigns level 1 priority)
BCLR IFS0, #IC1IF ; Clear the IC1 interrupt status flag
BSET IEC0, #IC1IE ; Enable IC1 interrupts
CLR IC1CON ; Turn off Input Capture 1 Module.
MOV #0x00A2, w0 ; Load the working register with the new
MOV w0, IC1CON ; prescaler mode and write to IC1CON
MOV #IC1BUF, w0 ; Create capture data fetch pointer
MOV #TEMP_BUFF, w1 ; Create data storage pointer
; Assumes TEMP_BUFF is already defined
; The following code shows how to read the capture buffer when
; an interrupt is generated. W0 contains the capture buffer address.
; Example code for Input Capture 1 ISR:
__IC1Interrupt:
BCLR IFS0, #IC1IF ; Reset respective interrupt flag
MOV [w0++], [w1++] ; Read and save off first capture entry
MOV [w0], [w1] ; Read and save off second capture entry
; Remaining user code here
RETFIE ; Return from ISR
Note: It is recommended that the user turn off the capture module (i.e., clear ICM<2:0>
(ICxCON<2:0>)) before switching to a new mode. If the user switches to a new
Capture mode, the prescaler counter is not cleared. Therefore, it is possible that the
first capture event and its associated interrupt is generated due to a non-zero
prescaler counter (at the time of switching modes).

Table of Contents

Other manuals for Microchip Technology dsPIC30F