View Full Version : Confused about Interrupts
why is it that in setting up priority levels for interrupts, the parent intcon number changes:
INTCON3bits.INT2IP = 0; // Pin 1
INTCON2bits.INT3IP = 0; // Pin 2
INTCON2bits.RBIP = 0; // Pins 3, 4, 5, 6
but in setting up edge select, pin 1 and pin 2 are both intcon2bits:
INTCON2bits.INTEDG2 = 1; // Pin 1
INTCON2bits.INTEDG3 = 1; // Pin 2
and then when setting interrupt flags, they both turn into 3s?
INTCON3bits.INT2IF = 0; // Pin 1
INTCON3bits.INT3IF = 0; // Pin 2
INTCONbits.RBIF = 0; // Pins 3, 4, 5, 6
(not to mention pins 3,4,5,6 going from 2 to no number)
i got this code from the interrupts_for_dummies pdf in the white pages, so i'm assuming that this is correct code.
is it all just arbitrary, or what? what am i missing here? :ahh:
Mike Betts
29-01-2005, 05:28
Hardly arbitrary. Read chapter 10 of PICmicroŽ 18C MCU Family Reference Manual
logicalhippo
29-01-2005, 08:44
indeed. The documentation usually helps :-P.
INTCON3 is an 8-bit register in the microcontroller. Since there are 8 bits, it can hold 8 binary values. The reason there are multiple INTCON (interrupt control) registers is that there are more than 8 binary values needed to control interrupts.
Seriously, if you're doing something as low level as interupts, scan the datasheet and get familiar with the processor. It'll do you good in the end.
alright, understood.
but it'd still be nice if they at least tried to be a little consistent...
To the interrupt-capable amongst us, an additional conundrum. From reading Interrupts for Dummies, it appears that Dig IO pins 1-6 can be used for interrupts.
Why then, does Kevin's encoder routine use pins 1 and 6 for one side and 2 and 8 for the other?
If you want to use other Hall encoders, how many can you use? is 6 the magic number, or is only 2? (pins 1 and 2)
Jon from Team 236
why is it that in setting up priority levels for interrupts, the parent intcon number changes:
INTCON3bits.INT2IP = 0; // Pin 1
INTCON2bits.INT3IP = 0; // Pin 2
INTCON2bits.RBIP = 0; // Pins 3, 4, 5, 6
but in setting up edge select, pin 1 and pin 2 are both intcon2bits:
INTCON2bits.INTEDG2 = 1; // Pin 1
INTCON2bits.INTEDG3 = 1; // Pin 2
and then when setting interrupt flags, they both turn into 3s?
INTCON3bits.INT2IF = 0; // Pin 1
INTCON3bits.INT3IF = 0; // Pin 2
INTCONbits.RBIF = 0; // Pins 3, 4, 5, 6
(not to mention pins 3,4,5,6 going from 2 to no number)
i got this code from the interrupts_for_dummies pdf in the white pages, so i'm assuming that this is correct code.
is it all just arbitrary, or what? what am i missing here? :ahh:
Why then, does Kevin's encoder routine use pins 1 and 6 for one side and 2 and 8 for the other?
It doesn't. It uses 1 and 7 for one, and 2 and 8 for the other. 1-6 can be hardware interrupts, and 7-16 cannot. This means that you're pretty much limited to six digital encoders.
This is in the encoder.c file:
Five things must be done before this software will work
* correctly on the FRC-RC:
*
* 1) The left encoder's phase-A output is wired to digital input
* one and the phase-B output is wired to digital I/O six.
*
* 2) The right encoder's phase-A output is wired to digital input
* two and the phase-B output is wired to digital I/O 8.
*
* 3) Digital I/O pins one, two, six and eight are configured as
* inputs in user_routines.c/User_Initialization(). If you notice
* that the encoder only counts in one direction, you forgot to
* do this step.
*
* 4) A #include statement for the encoder.h header file must be
* included at the beginning of each source file that calls the
* functions in this source file. The statement should look like
* this: #include "encoder.h".
*
* 5) Initialize_Encoders() must be called from user_routines.c/
* User_Initialization().
*
has it been changed?
Jon
It doesn't. It uses 1 and 7 for one, and 2 and 8 for the other. 1-6 can be hardware interrupts, and 7-16 cannot. This means that you're pretty much limited to six digital encoders.
This is in the encoder.c file:
Five things must be done before this software will work
* correctly on the FRC-RC:
*
* 1) The left encoder's phase-A output is wired to digital input
* one and the phase-B output is wired to digital I/O six.
*
* 2) The right encoder's phase-A output is wired to digital input
* two and the phase-B output is wired to digital I/O 8.
*
* 3) Digital I/O pins one, two, six and eight are configured as
* inputs in user_routines.c/User_Initialization(). If you notice
* that the encoder only counts in one direction, you forgot to
* do this step.
*
* 4) A #include statement for the encoder.h header file must be
* included at the beginning of each source file that calls the
* functions in this source file. The statement should look like
* this: #include "encoder.h".
*
* 5) Initialize_Encoders() must be called from user_routines.c/
* User_Initialization().
*
has it been changed?
Jon
Whoa, that's weird. I apparently have an older version; my encoder.c looks completely different from what I just downloaded from kevin.org. Yeah, that doesn't make any sense to me... it should be on 7, not 6.
Kevin Watson
30-01-2005, 16:23
Whoa, that's weird. I apparently have an older version; my encoder.c looks completely different from what I just downloaded from kevin.org. Yeah, that doesn't make any sense to me... it should be on 7, not 6.No, 6 & 8 is correct. I changed it because I got a nasty gram from someone who hadn't made I/O 7 an input, which caused the encoder to count in one direction only. 6 & 8 are inputs by default. This text was added to the readme.txt file for this very reason:
3) Digital I/O pins one, two, six and eight are configured as
inputs in user_routines.c/User_Initialization(). If you notice
that the encoder only counts in one direction, you forgot to
do this step.
-Kevin
Kevin,
So for quadrature sensors, how many can we use? I would like to use 2 others, for a total of 4 (including the L & R wheel ones). Is that possible? Which pins should I use?
Jon
No, 6 & 8 is correct. I changed it because I got a nasty gram from someone who hadn't made I/O 7 an input, which caused the encoder to count in one direction only. 6 & 8 are inputs by default. This text was added to the readme.txt file for this very reason:
3) Digital I/O pins one, two, six and eight are configured as
inputs in user_routines.c/User_Initialization(). If you notice
that the encoder only counts in one direction, you forgot to
do this step.
-Kevin
stephenthe1
31-01-2005, 07:15
yes, but I think he wants help setting up the interrupt code to support 4 interrupts, versus the two it already has. I have the same problem. I'm gonna try to add to Mr. Watson's template to handle 2 more quadrature encoders (phase a and b encoders), and I'll test it on last year's bot. I may, however, need a little help on referencing digitals 3-6 as interrupts, since they are banded together.
Mike Betts
31-01-2005, 09:51
yes, but I think he wants help setting up the interrupt code to support 4 interrupts, versus the two it already has. I have the same problem. I'm gonna try to add to Mr. Watson's template to handle 2 more quadrature encoders (phase a and b encoders), and I'll test it on last year's bot. I may, however, need a little help on referencing digitals 3-6 as interrupts, since they are banded together.
When you read port B, the bits will tell you which interrupt was "tripped".
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.