Section 13. Input Capture: Highlights
Section 13. Input Capture: Highlights
Input Capture
HIGHLIGHTS
This section of the manual contains the following major topics:
Input Capture
13.12 Related Application Notes.......................................................................................... 13-13
13.13 Revision History ......................................................................................................... 13-14
13.1 Introduction
This section describes the Input Capture module and its associated Operational modes. The
Input Capture module is used to capture a timer value from one of two selectable time bases,
upon an event on an input pin. The Input Capture features are quite useful in applications
requiring frequency (Time Period) and pulse measurement. Figure 13-1 depicts a simplified
block diagram of the Input Capture module.
Refer to the specific device data sheet for further information on the number of channels
available in a particular device. All Input Capture channels are functionally identical. In this
section, an ‘x’ in the pin name or register name denotes the specific Input Capture channel.
The Input Capture module has multiple Operating modes, which are selected via the ICxCON
register. The Operating modes include:
• Capture timer value on every falling edge of input applied at the ICx pin
• Capture timer value on every rising edge of input applied at the ICx pin
• Capture timer value on every fourth rising edge of input applied at the ICx pin
• Capture timer value on every 16th rising edge of input applied at the ICx pin
• Capture timer value on every rising and every falling edge of input applied at the ICx pin
The Input Capture module has a four-level FIFO buffer. The number of capture events required
to generate a CPU interrupt can be selected by the user.
16 16
1 0 ICTMR
(ICxCON<7>)
Prescaler Edge Detection Logic FIFO
Counter and R/W
(1, 4, 16) Clock Synchronizer Logic
ICx pin
3 ICM<2:0>(ICxCON<2:0>)
Mode Select
FIFO
ICBNE, ICOV(ICxCON<4:3>)
ICxBUF
ICxI<1:0>
Interrupt
ICxCON Logic
System Bus
Set Flag ICxIF
(in IFSn Register)
Note: An ‘x’ in a signal, register or bit name denotes the number of the capture channel.
Lower Byte:
R/W-0 R/W-0 R/W-0 R-0, HC R-0, HC R/W-0 R/W-0 R/W-0
ICTMR ICI<1:0> ICOV ICBNE ICM<2:0>
bit 7 bit 0
Input Capture
1 = TMR2 contents are captured on capture event
0 = TMR3 contents are captured on capture event
Note: Timer selections may vary. Refer to the device data sheet for details.
bit 6-5 ICI<1:0>: Select Number of Captures per Interrupt bits
11 = Interrupt on every fourth capture event
10 = Interrupt on every third capture event
01 = Interrupt on every second capture event
00 = Interrupt on every capture event
bit 4 ICOV: Input Capture Overflow Status Flag (Read Only) bit
1 = Input capture overflow occurred
0 = No input capture overflow occurred
bit 3 ICBNE: Input Capture Buffer Empty Status (Read Only) bit
1 = Input capture buffer is not empty, at least one more capture value can be read
0 = Input capture buffer is empty
bit 2-0 ICM<2:0>: Input Capture Mode Select bits
111 = Input Capture functions as interrupt pin only, when device is in Sleep or Idle mode
(Rising edge detect only, all other control bits are not applicable.)
110 = Unused (module disabled)
101 = Capture mode, every 16th rising edge
100 = Capture mode, every 4th rising edge
011 = Capture mode, every rising edge
010 = Capture mode, every falling edge
001 = Capture mode, every edge (rising and falling)
(ICI<1:0> does not control interrupt generation for this mode.)
000 = Input capture module turned off
Legend:
HC = Cleared in Hardware HS = Set in Hardware
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Figure 13-2: Simple Capture Event Timing Diagram, Time Base Prescaler = 1:1
ICx pin
See Note 1
Note 1: A capture signal edge that occurs in this region will result in a capture buffer entry value of 1 or 2 timer counts from
the capture signal edge.
Figure 13-3: Simple Capture Event Timing Diagram, Time Base Prescaler = 1:4
TCY
ICxIF Set
Input Capture
ICx pin
Capture Data n
; 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.
; The following code shows how to read the capture buffer when
; an interrupt is generated. W0 contains the capture buffer address.
__IC1Interrupt:
BCLR IFS0, #IC1IF ; Reset respective interrupt flag 13
MOV [w0++], [w1++] ; Read and save off first capture entry
Input Capture
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).
TMRy n-3 n-2 n-1 n n+1 n+2 n+3 n+4 n+5 n+6
ICx pin
Input Capture
The input capture module can also be configured to function as an external interrupt pin. For this
mode, the ICI<1:0> (ICxCON<6:5>) bits must be set to ‘00’. Interrupts will be generated
independently of buffer reads.
This wake-up feature is quite useful for adding extra external pin interrupts. The following
conditions are true when the input capture module is used in this mode:
• The capture prescaler counter is not utilized while in this mode.
• The ICI<1:0>(ICxCON<6:5>) bits are not applicable.
IFS0 0084 CNIF MI2CIF SI2CIF NVMIF ADIF U1TXIF U1RXIF SPI1IF T3IF T2IF OC2IF IC2IF T1IF OC1IF IC1IF INT0F 0000 0000 0000 0000
IFS1 0086 IC6IF IC5IF IC4IF IC3IF C1IF SPI2IF U2TXIF U2RXIF INT2IF T5IF T4IF OC4IF OC3IF IC8IF IC7IF INT1IF 0000 0000 0000 0000
IEC0 008C CNIE MI2CIE SI2CIE IR12 ADIE U1TXIE U1RXIE SPI1IE T3IE T2IE OC2IE IC2IE T1IE OC1IE IC1IE INT0IE 0000 0000 0000 0000
IEC1 008E IC6IE EI30 IC4IE IC3IE C1IE SPI2IE U2TXIE U2RXIE INT2IE T5IE T4IE OC4IE OC3IE IC8IE IC7IE INT1IE 0000 0000 0000 0000
IPC0 0094 — T1IP<2:0> — OC1IP<2:0> — IC1IP<2:0> — INT0IP<2:0> 0100 0100 0100 0100
DS70060C-page 13-11
Input Capture
13
dsPIC30F Family Reference Manual
Question 1: Can the Input Capture module be used to wake the device from Sleep
mode?
Answer: Yes. When the Input Capture module is configured to ICM<2:0> = ‘111’ and the
respective channel interrupt enable bit is asserted, ICxIE = 1, a rising edge on the capture pin
will wake-up the device from Sleep (see Section 13.8 “Input Capture Operation in Power
Saving States”).
Note: Please visit the Microchip web site (www.microchip.com) for additional Application
Notes and code examples for the dsPIC30F Family of devices.
13
Input Capture