Quote:
|
Originally Posted by Alan Anderson
As a general rule, using printf in an interrupt service routine is a Bad Idea. The serial communication library routines might handle it without causing issues...or they might not.
|
I was just doing that to see when the ISR was running.
My actual code is
Code:
else if (INTCONbits.RBIF && INTCONbits.RBIE){ /* Ints 3-6 (RB4, RB5, RB6, or RB7) changed. */
int_byte = PORTB; /* You must read or write to PORTB */
INTCONbits.RBIF = 0; /* and clear the interrupt flag */
if(accel_x){
//Here it measures the Low time
T1CONbits.TMR1ON = 0; // turn it off
accel_xTiltC=ReadTimer1();
WriteTimer1( 0x00 );
T1CONbits.TMR1ON = 1; // turn it on
Status = 2;
}
else if (accel_x ==0){
//This time it measures the High time
T1CONbits.TMR1ON = 0; // turn it off
accel_xTilt= ReadTimer1(); //capture timer value
WriteTimer1( 0x00 );
T1CONbits.TMR1ON = 1; // turn it on
Status = 1;
}
}
accel_xTilt is an unsigned integer, and since Timer1 is configured as a 16 bit timer, that should be suffice to hold any timer value right? But from 6ms - 4 ms I get negative values! I thought maybe for some reason it was wrapping around and doing something funny, so when I made it a long I got all zero values.
Does anyone have code that does frequency/duty cycle measurement?