Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 14 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
14
Dung lượng
715,88 KB
Nội dung
MICROCONTROLLERS CHAPTERINPUTCAPTURE MODULE Dr Vo Tuong Quan HCMUT - 2011 INPUTCAPTURE What is Input Capture? • Inputcapture 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 inputcapture modules, whereas dsPIC30F6014A contains inputcapture 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 INPUTCAPTUREInputCapture function diagram 2011 – Vo Tuong Quan INPUTCAPTURE EXTERNAL SIGNAL CAPTUREINPUT 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 INPUTCAPTURE EXTERNAL SIGNAL CAPTUREINPUT 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 inputcapture 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 inputcapture 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 INPUTCAPTURE EXTERNAL SIGNAL CAPTUREINPUT 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 inputcapture module interrupt request is generated on every rising and every falling edge (ICxIF bit is set) 2011 – Vo Tuong Quan INPUTCAPTURE An example of setting the captured value delayed by or instruction cycles TCY 2011 – Vo Tuong Quan INPUTCAPTURE 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 INPUTCAPTURE Example Pin diagram of dsPIC30F4013 2011 – Vo Tuong Quan INPUTCAPTURE 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 InputCapture 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 InputCapture Buffer Register - 0x0000 0xuuuu InputCapture Buffer Register - RESET STATE 0xuuuu InputCapture Buffer Register - 0x0000 0xuuuu ICOV ICBNE ICM 0x0000 10 2011 – Vo Tuong Quan INPUTCAPTURE ICSIDL – Inputcapture module stop in IDLE control bit (ICSIDL=0 inputcapture module will continue to operate in IDLE mode, ICSIDL=1 inputcapture module will halt in IDLE mode) ICTMR – Inputcapture 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 INPUTCAPTURE 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 - Inputcapture mode select bits 000 – Inputcapture 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 – Inputcapture module in external signal interrupt mode (external source of interrupt requests) 12 2011 – Vo Tuong Quan INPUTCAPTURE Using InputCapture 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 INPUTCAPTURE 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