
dsPIC33F Family Reference Manual
DS70198C-page 12-10 © 2009 Microchip Technology Inc.
Example 12-2 provides sample code that transfers the capture values to RAM with DMA.
DMA Channel 0 is set up for the Input Capture module with the following configuration:
• Transfer data from the Input Capture module to RAM
• One-shot operating mode
• Register Indirect with Post-Increment addressing
• Single buffer
• 256 transfers per buffer
• Transfer words
Example 12-2: Input Capture with DMA
12.5.3 Capture Pin as External Interrupt
The Input Capture (ICx) pin can be used as an auxiliary external interrupt source by clearing the
Input Capture Interrupt (ICI = 00) bits. In this condition an interrupt is generated on every capture
event, and the FIFO overflow condition does not inhibit the capture interrupt. Consequently, the
input capture buffer need not be read in the Capture Interrupt Service Routine (ISR). The Input
Capture Mode (ICM<2:0>) bits can be used to select the edge polarity for the interrupt.
// Initialize Capture module
IC1CONbits.ICM = 0b00; // Disable Input Capture 1 module
IC1CONbits.ICTMR = 1; // Select Timer2 as the IC1 Time base
IC1CONbits.ICI = 0b00; // Interrupt on every second capture event
IC1CONbits.ICM = 0b001; // Generate capture event on every Rising edge
Setup DMA for Input Capture:
// Define Buffer in DMA RAM
unsigned int BufferA[256] __attribute__((space(dma)));
DMA0CONbits.AMODE = 0b00; // Register indirect with post increment
DMA0CONbits.MODE = 0b01; // One Shot, Ping-Pong mode Disabled
DMA0CONbits.DIR = 0; // Peripheral to RAM
DMA0PAD = (int)&IC1BUF; // Address of the capture buffer register
DMA0REQ = 1;// Select IC module as DMA request source
DMA0CNT = 255; // Number of words to buffer
DMA0STA = __builtin_dmaoffset(&BufferA);
IFS0bits.DMA0IF = 0; // Clear the DMA interrupt flag bit
IEC0bits.DMA0IE = 1; // Enable DMA interrupt enable bit
DMA0CONbits.CHEN = 1;
Setup DMA Interrupt Handler
void __attribute__((__interrupt__)) _DMA0Interrupt(void)
{
// Process the captured values
IFS0bits.DMA0IF = 0; // Clear the DMA0 Interrupt Flag
}
Comentarios a estos manuales