5 chapter 5 2 input capture

14 139 0
5  chapter 5 2   input capture

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

MICROCONTROLLERS CHAPTER 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 input capture modules, whereas dsPIC30F6014A contains input capture modules This module has multiple operating modes selectable via the ICxCON register (control bit ICM): • Select by external input signal mode • Interrupt by external input signal mode  2011 – Vo Tuong Quan INPUT CAPTURE Input Capture function diagram  2011 – Vo Tuong Quan INPUT CAPTURE EXTERNAL SIGNAL CAPTURE INPUT MODE On every falling edge of input signal applied at the ICx pin On every rising edge of input signal applied at the ICx pin On every risinig and every falling edge of input signal applied at the ICx pin On every fourth rising edge of input signal applied at the ICx pin On every 16th rising edge of input signal applied at the ICx pin  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 to the values 100 or 101 respectively - The input capture module captures total value of the counter TMR2 or TMR3 for or 16 periods of the external signal at the pin ICx     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 (ICxCON) 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)       2011 – Vo Tuong Quan INPUT CAPTURE An example of setting the captured value delayed by or instruction cycles TCY  2011 – Vo Tuong Quan INPUT CAPTURE EXTERNAL SIGNAL INTERRUPT MODE - Bits ICM 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 ICxIPis defined, the microcontroller enters an interrupt  2011 – Vo Tuong Quan INPUT CAPTURE Example Pin diagram of dsPIC30F4013  2011 – Vo Tuong Quan INPUT CAPTURE Register NAME ADR IC1BUF 0x014 IC1CON 0x014 IC2BUF 0x014 IC2CON 0x014 IC7BUF 0x015 IC7CON 0x015 A IC8BUF 0x015 C IC8CON 0x015 E 15 14 13 12-8 Input Capture Buffer Register - - ICSID L - ICTMR ICI - ICSID L - ICTMR ICI ICOV ICBNE ICM - ICSID L - ICTMR ICI ICOV ICBNE ICM - ICSID L - ICTMR ICI 0x0000 0xuuuu ICOV ICBNE ICM Input Capture Buffer Register - 0x0000 0xuuuu Input Capture Buffer Register - RESET STATE 0xuuuu Input Capture Buffer Register - 0x0000 0xuuuu ICOV ICBNE ICM 0x0000 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 - 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 - 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 CCSC Compiler 13  2011 – Vo Tuong Quan INPUT CAPTURE Example: #int_ccp1 void isr() { rise = CCP_1; //CCP_1 is the fall = CCP_2; //CCP_2 is the pulse_width = fall - rise; } setup_ccp1(CCP_CAPTURE_RE); time the pulse went high time the pulse went low //pulse width // Configure CCP1 to capture rise setup_ccp2(CCP_CAPTURE_FE); // Configure CCP2 to capture fall setup_timer_1(T1_INTERNAL); // Start timer 14  2011 – Vo Tuong Quan

Ngày đăng: 07/11/2017, 14:17

Tài liệu cùng người dùng

  • Đang cập nhật ...