Log in

View Full Version : Interrupt not occuring.


devicenull
17-02-2005, 22:20
I've spent a couple days looking at this.. and I can't figure out why the one interrupt will not fire. We have 2 of the hall effect sensors being used as wheel encoders. The hardware on both is working fine, thats not the problem. (I swapped the cables around, and got values). The problem I'm having is one of the interrupts will not fire at all.


void InterruptHandlerLow()
{
unsigned char int_byte;
if (INTCON3.bitsINT2IF && INTCON3bits.INT2IE) {
INTCON3bits.INT2IF = 0;
right_enc++;
}
if (INTCON3bits.INT3IF && INTCON3bits.INT3IE) {
INTCON3bits.INT3IF = 0;
left_enc++;
}
}


void Initialze_Encoders(void) {
TRISBbits.TRISB2 = 1;
INTCON3bits.IN2IP = 0;
INTCON2bits.INTEDG2 = 1;
INTCON3bits.INT2IE = 1;

TRISBbits.TRISB3 = 1;
INTCON2bits.INT3IP = 0;
INTCON2bits.INTEDG3 = 1;
INTCON3bits.INT3IE = 1;
}


The interrupt on digital IO 1 will not fire. They are both set as inputs.. the second one works, but not the first. I'm certain its not the RC or the encoder, as I've tried on the 2004 and 2005 RC, and swapping which input they are in makes whichever is on port 2 work.

I'm out of ideas.. can't see why one works and not the other.

(Yes, I know increasing the variable there is probably not a good idea.. but once I get it working, I'm going back to the other encoder functions)

Kris Verdeyen
17-02-2005, 22:45
INTCON3bits.IN2IP = 0;



Should it be INTCON3bits.INT2IP ? Dunno if this typo is in your code - it seems like it oughtn't compile if that were the case.

I checked all of the silly things - it looks like all of the bits are in the correct registers, but again, that's more of an assembly problem, not a C problem - the complier would catch it if it was wrong.

devicenull
18-02-2005, 19:38
Sorry, that was from me typing it into the box. in the code its what you said.

They still aren't working correctly.. even when it should be. Anything else I can try?

Manoel
18-02-2005, 21:02
Sorry, that was from me typing it into the box. in the code its what you said.

They still aren't working correctly.. even when it should be. Anything else I can try?

How do you know they do not fire? Are you simply printing your right_enc and left_enc variables? If that's the case, then maybe your problem isn't related to the interrupt, but to your printf statement. We had the same problem described in this post (http://www.chiefdelphi.com/forums/showpost.php?p=335993&postcount=7), maybe you are making the same mistake. Check it out. ;)

devicenull
18-02-2005, 21:46
How do you know they do not fire? Are you simply printing your right_enc and left_enc variables? If that's the case, then maybe your problem isn't related to the interrupt, but to your printf statement. We had the same problem described in this post (http://www.chiefdelphi.com/forums/showpost.php?p=335993&postcount=7), maybe you are making the same mistake. Check it out. ;)

Yea, that was it, don I feel stupid now