Help! It’s not displaying the data frrom the encoders. Please any help would be appreciated asap
we checked the encoders and they are wired correctly.
we are trying to print the functions which should return the values in the code.
Thank you.
Help! It’s not displaying the data frrom the encoders. Please any help would be appreciated asap
we checked the encoders and they are wired correctly.
we are trying to print the functions which should return the values in the code.
Thank you.
Are you sure you followed all the steps in the encoder readme for enabling the encoders? I.E. uncommenting the #defines in encoders.h to enable the encoders?
Yes we followed the readme and are still getting zero
Yes I am on cgront’s team
Do we have to call an encoder function after initialization?
if so Where?
somebody please respond to this please:ahh:
We need help!:eek:
posting the code that isn’t working is always a good way to get help.
we can not because its the whole project.
How are you getting the data out of Kevin’s variables? Do you just have a printf grabbing it out? Or do you hand it to one of your variables and then printf? How do you know it’s really zero? Did you do the printf right? I messed up and spent two days futzing with encoders when the problem was in a printf call once.
Can you try to show me the parts of the code where the Encoders are dealt with? Forget Kevin’s code, show me what you did?
Ari.
first of all did you make that function or did you add an exsiting function to the program your making are you getting an linking error or what maybe the globals are wrong
(are you using easyc)
Did you remember to #include <stdio> ? Did you do something like:
int myVar = 0;
printf(“This is %d”,myVar); ?
In encoder.h, we modified it to have the digital imputs 12 and 13 for encoders 1 and 2.
From encoder.h:
#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:
#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.
Hey Cgront, Its Randell if your reading this I need you to get my memstick and give it to me tomorrow at robotics
You said you have encoders 1 & 2 for 12 & 13?
Those are phase B from what I see in the code.
Have you edited the phase A digitial i/o’s?? Are they still getting 1 & 2?
How are you trying to print the functions? The Get_Encoder… functions return long integers. If you try to print them using the %d format, you’ll likely get zero unless the encoders have turned far enough to start setting the high bytes of the value.
Also, here’s my standard question for problems of this type: what exactly does “wired correctly” mean?
The encoders need to be plugged into digital inputs 1 through 6. Those digital inputs are interrupt pins, and without interrupts, kevin’s code doesn’t work.
Ithink that we are wired correctly
Do we have to call any function besides Encoder Initialization oroutside the readme?
Wouldn’t you rather be certain that the wiring is correct? If you tell us exactly how it’s connected, we can tell you if there’s something you misunderstood about the wiring and need to change to make it work.
Here is a quick program I wipped up in easyC you can use to test your encoders.
Encoder 1 - Plug into I/O Port 1 (Channel A)
Plug into I/O Port 7 (Channel B)
Encoder 2 - Plug into I/O Port 2 (Channel A)
Plug into I/O Port 8 (Channel B)
Source:
void OperatorControl ( void )
{
StartQuadEncoder ( 1 , 7 , 0 ) ;
StartQuadEncoder ( 2 , 8 , 1 ) ;
while ( 1 )
{
PrintToScreen ( "Encoder 1: %5ld Encoder 2: %5ld
" , (long)GetQuadEncoder ( 1 , 7 ), (long)GetQuadEncoder ( 2 , 8 ) ) ;
}
}
Attached is pre compliled program incase you don’t have easyC installed. You can upload it to your robot with IFI loader.
help_encoder.zip (18.1 KB)
help_encoder.zip (18.1 KB)