Quiero ver el tiempo que transcurre entre el pulso de subida y el pulso de bajada de una señal de no mas de 400ms, y uso el siguiente programa:
//FUSES
_FOSC(CSW_FSCM_OFF & XT_PLL4);
_FGS(CODE_PROT_OFF);
_FWDT( WDT_OFF);
_FBORPOR(MCLR_EN & PWRT_OFF) ;
unsigned int periodoTotal = 0xffff;
void CONFIG_timers(void) {
CloseTimer2();
unsigned int config2 = T2_OFF & T2_IDLE_CON & T2_GATE_OFF & T2_PS_1_256 &
T2_32BIT_MODE_OFF & T2_SOURCE_INT;
OpenTimer2(config2, periodoTotal);
int main (void) {
CONFIG_puertos();
CONFIG_timers();
CONFIG_uart();
T2CONbits.TON = 1;
CloseINT2();
ConfigINT2(EXT_INT_ENABLE & EXT_INT_PRI_6 & RISING_EDGE_INT);
retardoMs(1000);
LATDbits.LATD2 = 1;
retardoMs(3);
LATDbits.LATD2 = 0;
retardoMs(7);
LATDbits.LATD2 = 1;
while(1){
} return 1;
}
void __attribute__((__interrupt__)) _INT2Interrupt(void) {
unsigned int tiempo = 0;
if(INTCON2bits.INT1EP==0){
LATBbits.LATB12 = 1;
INTCON2bits.INT1EP = 1;
T2CONbits.TON = 1;
} else {
LATBbits.LATB12 = 0;
tiempo = ReadTimer2();
T2CONbits.TON = 0;
TMR2 = 0;
INTCON2bits.INT1EP=0;
char buffer[20];
buffer[0] = (char)(tiempo >>

;
buffer[1] = (char)(tiempo & 0x00ff);
WriteUART2(buffer[0]);
WriteUART2(buffer[1]);
}
IFS1bits.INT2IF = 0; //Clear the INT2 interrupt flag or else
//the CPU will keep vectoring back to the ISR
//}
me genero un pulso que mido con el osciloscopio y no es el que me lee el timer, ¿que puedo estar leyendo mal? el calculo del tiempo con respecto al timer lo hago con la formula:
ValorTimer x 256 x 4 / 40.000.000 (frecuencia= 10Mhz de reloj x 4 PLL)