5 - 1. Write C programs to measure the length of high level...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1. Write C programs to measure the length of high level of a random input digital signal by using: a. External Interrupt module b. Input Capture module External Interrupt module #include <p32xxxx.h> int time=0; #pragma interrupt EXI ipl7 vector 19 void EXI (void) { static int temp=0; if (temp == 0) { T2CONSET = 0x8000; INTCONbits.INT4EP=0; TMR2=0; IFS0CLR = 0x80000; temp++; } else { INTCONbits.INT4EP=1; time = TMR2; IFS0CLR = 0x80000; temp--; } } main(){ // 0. Initialization T2CON = 0x0; // stop any 16/32 bit operation in timer 2 T3CON = 0x0; // stop any 16/32 bit operation in timer 3 T2CONSET = 0x0008; PR2=0XFFFFFF; TMR2=0; TMR3=0; TRISA=0xFFFF; INTCONbits.INT4EP=1; INTCONbits.MVEC=1; IPC4SET = 0x01F000000; //Set priority level = 7 IFS0CLR = 0x80000; IEC0SET = 0x80000; asm ("ei"); while (1) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
} } // main “7C9” is 0.5 ms, but the high time is 2 ms. Input Capture module #include <p32xxxx.h> int time; #pragma interrupt IC_ISR ipl7 vector 5 void IC_ISR (void) { static int temp=0; if (temp == 0) { time =IC1BUF; IFS0CLR = 0x20; temp++; } else { time = IC1BUF - time;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 06/24/2011.

Page1 / 5

5 - 1. Write C programs to measure the length of high level...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online