Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Multiple Interrupts (http://www.chiefdelphi.com/forums/showthread.php?t=62915)

windell747 30-01-2008 23:34

Multiple Interrupts
 
Hi, I was thinking of having and interrupt for the rising and falling edges from the geartooth sensors on each of two wheels as well as have a timer interrupt for each of three SONAR sensors. How do you program different interrupt handlers so that each one responds to a different interrupt from each device?

Thanks,
Windell
#2477

Kevin Sevcik 30-01-2008 23:50

Re: Multiple Interrupts
 
You only have one interrupt handler for your entire program. To handle multiple interrupts, you put a large amount of if-else statements in your interrupt handler to check for which particular interrupt you're handling at the moment, then you do whatever you need to inside that particular if-else statement.

windell747 31-01-2008 00:00

Re: Multiple Interrupts
 
Ahh I see what you mean. Are there any examples that you can show me?

Thanks,
Windell

Alan Anderson 31-01-2008 00:29

Re: Multiple Interrupts
 
Kevin Watson's encoder software is a good example of multiple interrupt sources being handled.

http://www.kevin.org/frc/frc_encoder.zip

Many of his other utilities, such as the adc and pwm replacements, are also useful examples.

JohnC 31-01-2008 13:49

Re: Multiple Interrupts
 
I just had a bad idea. If you want interrupts on the rising AND falling edges...
Code:

void Int_1_ISR(void)
{
        INTCON2bits.INTEDG2 = !INTCON2bits.INTEDG2;
}

Mmm, does anyone smell the processor cooking?

Racer26 31-01-2008 16:41

Re: Multiple Interrupts
 
Kevin would definitely be the one to ask, but i think that might work, if you also disabled the interrupt, then made the INTEDG2 change, and then reenabled it.

Alternatively, if you want rising and falling edges, just use the PORTB ones (Int3-6).

Kevin Watson 31-01-2008 16:52

Re: Multiple Interrupts
 
Quote:

Originally Posted by JohnC (Post 689530)
I just had a bad idea. If you want interrupts on the rising AND falling edges...
Code:

void Int_1_ISR(void)
{
    INTCON2bits.INTEDG2 = !INTCON2bits.INTEDG2;
}

Mmm, does anyone smell the processor cooking?

I did this for the 2004 IR beacon receiver and it works just fine (and no smoke or flames <grin>).

-Kevin

Gamer930 31-01-2008 22:00

Re: Multiple Interrupts
 
2 Attachment(s)
I have been trying to get Interrupts 2 and 3 working that would be on pins 1 and 2 of the Digital Inputs. I have the code and I seem to get in an infinite loop on the left gear tooth sensor. . . The interrupt keeps going and makes both the right and left gear boxes go full 254 forward.

Right GTS doesn't work at all. (yes we have tested the GTS after we fixed the resistors problem and it works fine)

Can someone see where I messed up??? Copied the code from Kevin Watson's Encoder Code.

Kevin Watson 01-02-2008 00:37

Re: Multiple Interrupts
 
Quote:

Originally Posted by Gamer930 (Post 689881)
I have been trying to get Interrupts 2 and 3 working that would be on pins 1 and 2 of the Digital Inputs. I have the code and I seem to get in an infinite loop on the left gear tooth sensor. . . The interrupt keeps going and makes both the right and left gear boxes go full 254 forward.

Right GTS doesn't work at all. (yes we have tested the GTS after we fixed the resistors problem and it works fine)

Can someone see where I messed up??? Copied the code from Kevin Watson's Encoder Code.

I can't really make out what's going on, but I did see that you were calling printf() in your interrupt service routine, which can cause problems. A much better quick-and-dirty way to signal the outside world is to just send a single character using Write_Serial_Port_One(), which executes much faster. It's as simple as this:

Write_Serial_Port_One('*');

Fix this one problem and let us know if it works.

-Kevin

Gamer930 01-02-2008 01:59

Re: Multiple Interrupts
 
Quote:

Originally Posted by Kevin Watson (Post 690002)
I can't really make out what's going on, but I did see that you were calling printf() in your interrupt service routine, which can cause problems. A much better quick-and-dirty way to signal the outside world is to just send a single character using Write_Serial_Port_One(), which executes much faster. It's as simple as this:

Write_Serial_Port_One('*');

Fix this one problem and let us know if it works.

-Kevin

I originally had no printf's and was having the problem. Then added them in to see additionally what could have been causing problems.

windell747 01-02-2008 03:08

Re: Multiple Interrupts
 
Quote:

Originally Posted by Gamer930 (Post 689881)
yes we have tested the GTS after we fixed the resistors problem and it works fine

I was unaware of a resistor problem. What is the problem that you speak of?

Gamer930 01-02-2008 13:47

Re: Multiple Interrupts
 
Quote:

Originally Posted by windell747 (Post 690037)
I was unaware of a resistor problem. What is the problem that you speak of?

Team Update #6 explains it. There are a bunch of discussion here on ChiefDelphi about it also. . . Pretty much they switched R3 and R4 on one of the Gear Tooth Sensors

Gamer930 02-02-2008 19:03

Re: Multiple Interrupts
 
I changed all the Longs to Ints
Took out the printf in the interrupt function.

And everything started to work!!!. . . With making those few changes the above code works for Digital Input 1 and Digital Input 2 Gear Tooth Sensors.

It really made me excited today when programming the robot to go *** (A calculated value) gear teeth (8 ft) forward it actually did.

windell747 03-02-2008 03:52

Re: Multiple Interrupts
 
whoa! Congrats! I'll be sure to remember that when I get around to the closed loop feedback.


All times are GMT -5. The time now is 23:45.

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