Beruflich Dokumente
Kultur Dokumente
CHAPTER 5
INPUT CAPTURE MODULE
HCMUT - 2011
INPUT CAPTURE
What is Input Capture?
• Input capture module has the task of capturing the curent
value of the timer counter upon an input event.
• This module is mainly used for the frequency or time period
measurements and pulse measurements (e.g. mean count
rate measurement).
• Example: dsPIC30F4013 contains 4 input capture modules,
whereas dsPIC30F6014A contains 8 input capture modules.
Input
Capture
function
diagram
3
2011 – Vo Tuong Quan
INPUT CAPTURE
EXTERNAL SIGNAL CAPTURE INPUT MODE
1. On every falling edge of input signal applied at the ICx pin.
2. On every rising edge of input signal applied at the ICx pin.
3. On every rising and every falling edge of input signal
applied at the ICx pin.
4. On every fourth rising edge of input signal applied at the ICx
pin.
5. On every 16th rising edge of input signal applied at the ICx
pin.
4
2011 – Vo Tuong Quan
INPUT CAPTURE
EXTERNAL SIGNAL CAPTURE INPUT MODE
SIMPLE CAPTURE MODE
- On every rising edge or every falling edge of the external
input signal at the input pin ICx.
- Captures the value of the counter TMR2 or TMR3 and puts it
into the FIFO buffer memory. The prescaler operates wth the
ratio 1:1, i.e. without reduction
6
2011 – Vo Tuong Quan
INPUT CAPTURE
An example of setting the captured value delayed by 1 or
2 instruction cycles TCY
7
2011 – Vo Tuong Quan
INPUT CAPTURE
EXTERNAL SIGNAL INTERRUPT MODE
- Bits ICM<2:0> are set to 111.
- The input pins ICx on rising edge generate an interrupt
request ICxIF.
If the interrupt enable bit ICxIE is set and the interrupt
priority level ICxIP<2:0>is defined, the microcontroller enters
an interrupt.
8
2011 – Vo Tuong Quan
INPUT CAPTURE
Example
10
2011 – Vo Tuong Quan
INPUT CAPTURE
ICSIDL – Input capture module stop in IDLE control bit
(ICSIDL=0 input capture module will continue to operate in
IDLE mode,
ICSIDL=1 input capture module will halt in IDLE mode)
ICTMR – Input capture timer select bits (ICTMR=0 TMR3
contents are captured on capture event,
ICTMR=1 TMR2 contents are captured on capture event)
ICI <1:0> - Select number of captures per interrupt bits
00 – interrupt on every capture event
01 – interrupt on every second capture event
10 – interrupt on every third capture event
11 – interrupt on every fourth capture event
11
2011 – Vo Tuong Quan
INPUT CAPTURE
ICOV – FIFO buffer overflow status flag (read only) bit
ICBNE – FIFO buffer buffer empty status (read only) bit
(ICBNE=0 FIFO buffer empty, ICBNE=1 FIFO buffer contains at
least one capture value
ICM <2:0> - Input capture mode select bits
000 – Input capture module turned off
001 – Capture mode, every edge (rising or falling)
010 – Capture mode, every falling edge
011 – Capture mode, every rising edge
100 – Capture mode, every 4th rising edge
101 – Capture mode, every 16th rising edge
110 – Unused (module disabled)
111 – Input capture module in external signal interrupt
mode
(external source of interrupt requests) 12
2011 – Vo Tuong Quan
INPUT CAPTURE
Using Input Capture in CCS-C
setup_ccp1 (mode) or setup_ccp1 (mode, pwm)
setup_ccp2 (mode) or setup_ccp2 (mode, pwm)
setup_ccp3 (mode) or setup_ccp3 (mode, pwm)
Read more about the function of this in the Catalog of CCS-
C Compiler
13
2011 – Vo Tuong Quan
INPUT CAPTURE
Example:
#int_ccp2
void isr()
{
rise = CCP_1; //CCP_1 is the time the pulse went high
fall = CCP_2; //CCP_2 is the time the pulse went low
pulse_width = fall - rise; //pulse width
}
..
setup_ccp1(CCP_CAPTURE_RE); // Configure CCP1 to capture rise
14
2011 – Vo Tuong Quan