OK I'm brain dead! Sorry, Actually, another solution is to duplicate the 1 & 2 coding for 3 and 4.
In encoder.c cut and replace the interrupt handler for 3 and 4 with 1's (or 2's) interrupt code
Code:
void Encoder_1_Int_Handler(void)
{
// Encoder 1's phase a signal just transitioned from zero to one, causing
// this interrupt service routine to be called. We know that the encoder
// just rotated one count or "tick" so now check the logical state of the
// phase b signal to determine which way the the encoder shaft rotated.
if(ENCODER_1_PHASE_B_PIN == 0)
{
Encoder_1_Count -= ENCODER_1_TICK_DELTA;
}
else
{
Encoder_1_Count += ENCODER_1_TICK_DELTA;
}
}
#endif
Changin all the 1s to 3s or 4s
so for 3 it becomes
Code:
if(ENCODER_3_PHASE_B_PIN == 0)
{
Encoder_3_Count -= ENCODER_3_TICK_DELTA;
}
else
{
Encoder_3_Count += ENCODER_3_TICK_DELTA;
}
}
#endif
The code expects the direction signal on the B pin which for 3 is digital input 13. Since it expects a high or low for direction it just so happens that will work for the signal from the encoder/divider.
I THINK that's the only file you need to change. I'll read through it again but I believe everything else is transparent to the interrupt handler. I can't really est it but it looks right and would be easy to implement. You CAN change 5 and 6 the same way but you mentioned you're only using 3 encoder/dividers.
Duh Me! I was so wrapped up in how I do it I didn't bother to think there was another way even after you mentioned that 2 was working. Hope I didn't throw you off!
Steve
Quote:
Originally Posted by Keo-san
We are using three quadrature banebots encoders with divider kits in interrupts 2, 3, and 4 (we broke off one of the pins in 1 by accident). We are also using the standard Kevin encoder code. Counting for encoder 2 works with no problem but 3 and 4 remain at zero. I switched the encoders on 2 and 3 to see if it was an encoder problem and the same thing happened, 2 worked but not 3 and 4. I've looked around and interrupts 1-2 are different from 3-6 which need the Port_B so I think the problem might be related to that. Thanks a ton for the help!
|