View Single Post
  #4   Spotlight this post!  
Unread 04-02-2006, 01:58
b_mallerd b_mallerd is offline
Programmer
FRC #1346 (Trobotics)
Team Role: Programmer
 
Join Date: Dec 2005
Rookie Year: 2005
Location: Vancouver
Posts: 35
b_mallerd is on a distinguished road
Send a message via MSN to b_mallerd
Re: Gear Tooth Sensor

I really recommend interrupts for dummies...I know this will be enforcing a bad habit so DON'T ASK FOR HELP BEFORE YOU TRY TO LEARN IT YOURSELF.

Ok. say you plug your gts into your digital io port 1...that corresponds to interrupt number 2. Now to use the interrupt you must first enable it, then set the interrupt flag to 0, then set the configuration so it interrupts on a rising edge or a falling edge. I wrapped all of it into a function so here it is!

void initialize_interrupt2(void)
{
INTCON3bits.INT2IP = 0; //set interrupt 2 to low priority
INTCON2bits.INTEDG2 = 1; //edge select 1 = rising edge 0 = falling edge
INTCON3bits.INT2IF = 0; //clear interrupt flag
INTCON3bits.INT2IE = 1; //enable interrupts
}

There you go...that enables the interrupt...now you find a line in your user_routines_fast.c file and look for the line with

if(INTCON3bits.INT2IE && INTCON3bits.INT2IF)
{
INTCON3bits.INT2IF=0;
}

and you change it so that it calls your handler

e.g

if(INTCON3bits.INT2IE && INTCON3bits.INT2IF)
{
INTCON3bits.INT2IF=0;
interrupt_2_handler();
}

Once that is finished you need to write a handler, the thing that is executed everysingle time the interrupt happens (when a gear passes the sensor)

e.g

interrupt_2_handler(void)
{
gear_count++;
}

and you can use gear count wherever you like as long as you declare the gear_count as a global variable (outside of any functions).

Good Luck (you probably don't need any with this guide =D but everyone wants that lady's attention

PS. reminding you not to be lazy...researching and doing this yourself is a valuble lesson...i guess i'm being selfish in keeping all the merits of digging through text files for myself.
__________________