Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Gear Tooth Sensor (http://www.chiefdelphi.com/forums/showthread.php?t=43244)

nukem 03-02-2006 17:45

Gear Tooth Sensor
 
So for a couple of days ive been researching how to get the gear tooth sensor to work and I have seen many different posts on it but none really explain how to get it working with the 2006 code. I know that I need to use interrupts but how do I do that on the 2006 code? It seems that it was implemented by default on the 2005 code why was it not on the 2006? If anyone knows when the gear tooth sensor or at least the interrupt code will be ready on kevin.org that would be a great help to.

Thanks

Mike Betts 03-02-2006 17:59

Re: Gear Tooth Sensor
 
The services supplied by Mr. Watson are on a voluntary basis. You have all of the information you need to implement your own interrupts.

If you wait for someone else to do it for you, you may have to wait a long time...

JMHO

Mike

Matt Krass 03-02-2006 19:24

Re: Gear Tooth Sensor
 
That and it is ready, his encoder code works with the gear tooth sensors with minor modification, found easily by searching:
http://www.chiefdelphi.com/forums/sh...5&postcount=16

Be sure to thank Kevin, and it's never a bad idea to do it yourself anyway, I'd rather know how to do something so if Kevin decides he doesn't like us anymore, I'm not stuck. :)

b_mallerd 04-02-2006 01:58

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.

dtengineering 04-02-2006 02:16

Re: Gear Tooth Sensor
 
Interesting, I'll have to have the programmer's look at the Kevin's new code release.

We had worked out two solutions... one was to use a custom filter circuit to filter out the shorter pulse, then use two sensors, one forward and one backward on each gear. The other was to program a PIC 16f627 or similar other "little" PIC to serve as a dedicated gear tooth sensor monitor.

Of course, we haven't got around to implementing these, and with the deadline coming, Kevin's help is once again most appreciated.

Jason

Gdeaver 04-02-2006 09:28

Re: Gear Tooth Sensor
 
We're taking the easy way out and not worrying about direction info. We are mounting VEX encoders on the KOP transmission output shaft and use the EASY-C function. Our capabilities are very limited. Worked well on the VEX bot.

nukem 04-02-2006 11:23

Re: Gear Tooth Sensor
 
Well I did search around but no matter what I did the code I wrote would not work. I had code implemented very similar to b_mallerd and infact I just tried the code he showed and still nothing happens. I put the interupts initialization in User_Initialization() and uncommented the code for interrupts in InterruptHandlerLow(). I told it just to print out On whenever it sees the gear tooth(Im moving it by hand) but nothing prints on the screen. It seems nothing ever triggers the interrupt code(yes it is plugged in on Digial In 1). I thought I was doing something wrong but I guess not. Why isnt anything I do make the gear tooth sensor trigger?

nukem 04-02-2006 11:30

Re: Gear Tooth Sensor
 
I just did a search for INTCON3bits.INT2IF and it was only found in the if statement seeing if it was trigged and when I set it to 0. Where/how do I put code to make it trigger?

Mike Betts 04-02-2006 20:17

Re: Gear Tooth Sensor
 
Quote:

Originally Posted by nukem
I just did a search for INTCON3bits.INT2IF and it was only found in the if statement seeing if it was trigged and when I set it to 0. Where/how do I put code to make it trigger?

As you can see from page 125 of this document, the flag is set in hardware and must be reset (cleared) in software.

Quote:

Interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global interrupt enable bit. User software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. This feature allows for software polling.
Does this answer your question?

Alan Anderson 04-02-2006 20:21

Re: Gear Tooth Sensor
 
Interrupts aren't supposed to be triggered by code. They are triggered by events such as signals changing on the input pins or timers overflowing.


All times are GMT -5. The time now is 16:08.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi