In encoder.h, we modified it to have the digital imputs 12 and 13 for encoders 1 and 2.
From encoder.h:
Code:
#ifndef _encoder_h
#define _encoder_h
#define ENABLE_ENCODER_1 //right
#define ENABLE_ENCODER_2 //left
#define ENCODER_1_PHASE_B_PIN rc_dig_in12 //right
#define ENCODER_2_PHASE_B_PIN rc_dig_in13 //left
#define ENCODER_1_TICK_DELTA 1
#define ENCODER_2_TICK_DELTA 1
From userroutinesfast.c:
Code:
#pragma code
//#pragma interruptlow InterruptHandlerLow save=PROD,section(".tmpdata")
#pragma interruptlow InterruptHandlerLow save=PROD //encoder
void InterruptHandlerLow (void)
{
unsigned char int_byte;
unsigned char Port_B;//encoder
unsigned char Port_B_Delta;//encoder
if (PIR1bits.RC1IF && PIE1bits.RC1IE) // rx1 interrupt?
{
#ifdef ENABLE_SERIAL_PORT_ONE_RX
Rx_1_Int_Handler(); // call the rx1 interrupt handler (in serial_ports.c)
#endif
}
else if (PIR3bits.RC2IF && PIE3bits.RC2IE) // rx2 interrupt?
{
#ifdef ENABLE_SERIAL_PORT_TWO_RX
Rx_2_Int_Handler(); // call the rx2 interrupt handler (in serial_ports.c)
#endif
}
else if (PIR1bits.TX1IF && PIE1bits.TX1IE) // tx1 interrupt?
{
#ifdef ENABLE_SERIAL_PORT_ONE_TX
Tx_1_Int_Handler(); // call the tx1 interrupt handler (in serial_ports.c)
#endif
}
else if (PIR3bits.TX2IF && PIE3bits.TX2IE) // tx2 interrupt?
{
#ifdef ENABLE_SERIAL_PORT_TWO_TX
Tx_2_Int_Handler(); // call the tx2 interrupt handler (in serial_ports.c)
#endif
}
else if(PIR1bits.TMR2IF && PIE1bits.TMR2IE) // timer 2 interrupt?
{
PIR1bits.TMR2IF = 0; // clear the timer 2 interrupt flag [92]
Timer_2_Int_Handler(); // call the timer 2 interrupt handler (in adc.c)
}
else if(PIR1bits.ADIF && PIE1bits.ADIE) // ADC interrupt
{
PIR1bits.ADIF = 0; // clear the ADC interrupt flag
ADC_Int_Handler(); // call the ADC interrupt handler (in adc.c)
}
else if(INTCON3bits.INT2IF && INTCON3bits.INT2IE) /* The INT2 pin is RB2/DIG I/O 1. */
{
INTCON3bits.INT2IF = 0;
// printf("Left Interrupt hit\r");
// Left_Encoder_Int_Handler();
}
else if(INTCON3bits.INT3IF && INTCON3bits.INT3IE) /* The INT3 pin is RB3/DIG I/O 2. */
{
INTCON3bits.INT3IF = 0;
// printf("Right Interrupt hit\r");
// Right_Encoder_Int_Handler();
}
else if (INTCONbits.RBIF && INTCONbits.RBIE) // encoder 3-6 interrupt?
{
Port_B = PORTB; // remove the "mismatch condition" by reading port b
INTCONbits.RBIF = 0; // clear the interrupt flag
Port_B_Delta = Port_B ^ Old_Port_B; // determine which bits have changed
Old_Port_B = Port_B; // save a copy of port b for next time around
if(Port_B_Delta & 0x10) // did external interrupt 3 change state?
{
#ifdef ENABLE_ENCODER_3
Encoder_3_Int_Handler(Port_B & 0x10 ? 1 : 0); // call the encoder 3 interrupt handler (in encoder.c)
#endif
}
if(Port_B_Delta & 0x20) // did external interrupt 4 change state?
{
#ifdef ENABLE_ENCODER_4
Encoder_4_Int_Handler(Port_B & 0x20 ? 1 : 0); // call the encoder 4 interrupt handler (in encoder.c)
#endif
}
if(Port_B_Delta & 0x40) // did external interrupt 5 change state?
{
#ifdef ENABLE_ENCODER_5
// Encoder_5_Int_Handler(Port_B & 0x40 ? 1 : 0); // call the encoder 5 interrupt handler (in encoder.c)
#endif
}
if(Port_B_Delta & 0x80) // did external interrupt 6 change state?
{
#ifdef ENABLE_ENCODER_6
// Encoder_6_Int_Handler(Port_B & 0x80 ? 1 : 0); // call the encoder 6 interrupt handler (in encoder.c)
#endif
}
}
}
We called Initialize_Encoders in User_Initialization.
We would like some suggestions about checking the wires incase the code is properly set up.
__________________
some of Murphy's Laws of Computing
1)When computing, whatever happens, behave as though you meant it to happen.