Quote:
Originally Posted by compwiz2008
Our Team is using the IFI Default Code and have the counter in user_routines_fast.c. We have the Gear Tooth Sensor plugged into rc_dig_in01 and are using the interrupt code that comes with the user_routines_fast.c default code.
|
Thanks for showing us your code. As I feared, it confirms that you
aren't doing it correctly.
Note that the default interrupt handler doesn't do anything except clear the interrupt when your GTS sends its pulse:
Code:
if (INTCON3bits.INT2IF && INTCON3bits.INT2IE) /* The INT2 pin is RB2/DIG I/O 1. */
{
INTCON3bits.INT2IF = 0;
}
You'll need to add a line in there to increment your counter.
Quote:
Our Counter Code is:
Code:
if (rc_dig_in01 >0) {
counter = counter + 1;
}
|
The input pulse from the GTS is very short. You'll not be able to catch it reliably that way. You have to put the counter increment into the interrupt service routine.
Look at Kevin Watson's encoder support files (
http://www.kevin.org/frc ) to see an example of how to initialize the interrupt, update the counter value, and read the value while protecting it from being changed in the middle of being read.