Hola!!!Encontré un programa por internet y lo he modificado para versi realiza lo que yo quiero...
El problema es que no me entra en el segundo while y no entiendo el porqué ...porque se supone que estoy recibiendo pulsos continuamente...
Alguien podría decirme algo??Muchas gracias!
#include <P18f4620.h>
#include <capture.h>
#include <timers.h>
#include <math.h>
#include <stdio.h>
#pragma config DEBUG=OFF
#pragma config OSC=XT
#pragma config WDT=OFF
#pragma config LVP=OFF
#pragma config PWRT=OFF
#pragma config MCLRE=OFF
#pragma config CCP2MX = PORTBE
unsigned int initial = 0x00;
unsigned int final = 0x00;
unsigned int elapsed = 0x00;
void main() {
// Configure High-Frequency Timer3, no Interrupts, Internal clock, prescale 1 (20MHz / 4 = 0,2 us)
OpenTimer3(TIMER_INT_OFF & T3_SOURCE_INT & T3_PS_1_1 );
// Configure Capture2
OpenCapture2(C2_EVERY_RISE_EDGE & CAPTURE_INT_OFF);
TRISBbits.TRISB3 = 0x01; //set CCP2 as input
PIR2bits.CCP2IF = 0x00; // make sure flag is 0
while(!PIR2bits.CCP2IF){; //wait for first event
initial = ReadCapture2 (); //get first time stamp
PIR2bits.CCP2IF = 0x00;// make sure flag is 0
}
while(!PIR2bits.CCP2IF){; //wait for second event
final = ReadCapture2 (); //get second time stamp
}
CloseCapture2 ();
CloseTimer3 ();
elapsed = final - initial; // compute elapsed time
}