Sie sind auf Seite 1von 14

MICROCONTROLLERS

CHAPTER 5
INPUT CAPTURE MODULE

Dr. Vo Tuong Quan

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.

This module has multiple operating modes selectable via the


ICxCON register (control bit ICM<2:0>):
• Select by external input signal mode
• Interrupt by external input signal mode.
2
 2011 – Vo Tuong Quan
INPUT CAPTURE

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

PRESCALER CAPTURE MODE


- The operation of the input capture module the external
signal is prescaled by the ratio 1:4 or 1:16 by setting the
control bit ICM<2:0> to the values 100 or 101 respectively.
- The input capture module captures total value of the counter
TMR2 or TMR3 for 4 or 16 periods of the external signal at the
pin ICx. 5
 2011 – Vo Tuong Quan
INPUT CAPTURE
EXTERNAL SIGNAL CAPTURE INPUT MODE
EDGE DETECTION MODE
- Capturing the value of TMR2 or TMR3 counter can be done
on every rising and every falling edge of the external input
signal applied to the ICx pin.
- The edge detection mode is selected by setting the
ICM<2:0> (ICxCON<2:0>) control bits to 001.
- In this mode the prescaler counter can not be used.
- The input capture module interrupt request is generated on
every rising and every falling edge (ICxIF bit is set).

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

Pin diagram of dsPIC30F4013


9
 2011 – Vo Tuong Quan
INPUT CAPTURE
Register

NAME ADR 15 14 13 12-8 7 6 5 4 3 2 1 0 RESET STATE


0x014
IC1BUF Input 1 Capture Buffer Register 0xuuuu
0
0x014 ICSID
IC1CON - - - ICTMR ICI<1:0> ICOV ICBNE ICM<2:0> 0x0000
2 L
0x014
IC2BUF Input 2 Capture Buffer Register 0xuuuu
4
0x014 ICSID
IC2CON - - - ICTMR ICI<1:0> ICOV ICBNE ICM<2:0> 0x0000
6 L
0x015
IC7BUF Input 7 Capture Buffer Register 0xuuuu
8
0x015 ICSID
IC7CON - - - ICTMR ICI<1:0> ICOV ICBNE ICM<2:0> 0x0000
A L
0x015
IC8BUF Input 8 Capture Buffer Register 0xuuuu
C
0x015 ICSID
IC8CON - - - ICTMR ICI<1:0> ICOV ICBNE ICM<2:0> 0x0000
E L

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

setup_ccp2(CCP_CAPTURE_FE); // Configure CCP2 to capture fall

setup_timer_1(T1_INTERNAL); // Start timer 1

14
 2011 – Vo Tuong Quan

Das könnte Ihnen auch gefallen