This darn Gear Tooth Sensor

Alright, my team has been around for 3 years this year. I have been head programmer all three years. Now basically, our programming has been relatively simple in the past years. I have gotten a feel for how the PIC works, and the code’s architecture, but there is something I have never touched: Interrupts.
Looking into Chief Delphi, looking for answers, I found things saying that you need to use interrupts to get the input from the Gear Tooth Sensor. This is a lot more programming than I anticipated at first for this thing. I was hoping for a simple check on rc_dig_in01, but that doesn’t work. I found this out by trying it, and then looking on here to see why.

Alright, I’m rambling. Onto my question:
How can I use interrupts to tell when the GTS pulses? I don’t care what direction it is spinning, I am combining the GTS and the gyro, to get a heading of the robot. I am just merely finding the distance traveled by one wheel, and then doing the same on the other wheel.
Thank you!
–Adam

All you really have to do is enable the interrupt on port 1, make sure your sensor is plugged into digital I/O 1, and add 1 to a counter in the interrupt handler in “User_Routines_Fast.c”

Although to access it a quick function to disable the interrupt and return the variable’s should also be used and the variable should be volatile type.

If you understood that thats good :slight_smile:

I will edit this post with a link to a good white paper that gives an in-depth description of the interrupts. They are actually fairly easy :slight_smile:

Here it is: http://www.chiefdelphi.com/media/papers/1483

The core of the interrupts, in IFI’s default code is the InterruptHandlerLow() routine, which can be found in user_routines_fast.c. IFI’s set things up so that when an interrupt is triggered, that function is automatically called. Within it, IFI setup a skeleton of if statements to demonstrate how to check which interrupt was triggered and how to handle it.

If you can’t quite understand their skeleton (which I don’t expect you to, don’t worry) pull up the PIC Controller Manual (Kevin.org has it) and do a search for all the variables used in the function (such as INTCON3bits.INT2IF). They’re actually software registers and the manual describes what they all do and how to use them. They might also be in the manual for the IFI Default Code, but I’m not sure.

Basically, each of the if statements corresponds to a different interrupt. Inside the statement you can either put a small section of your own code to process the interrupt (increment a counter of how many times it has triggered, perhaps), or you can call a separate function to do the same thing.

I believe you also need to enable the interrupt from User_Initialization() in user_routines.c. Look for something about interrupts in there.

Keep your progress posted here.

look up kevin’s encoder code ( kevin.org/frc ) and a modified copy should work with the GTS