Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Encoder Problemo (http://www.chiefdelphi.com/forums/showthread.php?t=54455)

cgront 18-02-2007 14:19

Encoder Problemo
 
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.

robind 18-02-2007 14:21

Re: Encoder Problemo
 
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?

Seamus 18-02-2007 14:41

Re: Encoder Problemo
 
Yes we followed the readme and are still getting zero
Yes I am on cgront's team

Seamus 18-02-2007 15:19

Re: Encoder Problemo
 
Do we have to call an encoder function after initialization?
if so Where?

Seamus 18-02-2007 16:19

Re: Encoder Problemo
 
somebody please respond to this please:ahh:

Coz 18-02-2007 16:25

Re: Encoder Problemo
 
We need help!:eek:

Tureyhall 18-02-2007 16:30

Re: Encoder Problemo
 
posting the code that isn't working is always a good way to get help.

Coz 18-02-2007 16:32

Re: Encoder Problemo
 
we can not because its the whole project.

Ari Allyn-Feuer 18-02-2007 16:58

Re: Encoder Problemo
 
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.

jesusescobar 18-02-2007 17:02

Re: Encoder Problemo
 
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)

BossOfTheGame 18-02-2007 17:06

Re: Encoder Problemo
 
Did you remember to #include <stdio> ? Did you do something like:

int myVar = 0;

printf("This is %d",myVar); ?

cgront 18-02-2007 17:40

Re: Encoder Problemo
 
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.

Scandellous 18-02-2007 17:56

Re: Encoder Problemo
 
Hey Cgront, Its Randell if your reading this I need you to get my memstick and give it to me tomorrow at robotics

benhulett 18-02-2007 22:18

Re: Encoder Problemo
 
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?

Alan Anderson 18-02-2007 23:41

Re: Encoder Problemo
 
Quote:

Originally Posted by cgront (Post 580922)
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.

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?

meatmanek 18-02-2007 23:53

Re: Encoder Problemo
 
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.

Seamus 19-02-2007 10:09

Re: Encoder Problemo
 
Ithink that we are wired correctly

Do we have to call any function besides Encoder Initialization oroutside the readme?

Alan Anderson 19-02-2007 10:23

Re: Encoder Problemo
 
Quote:

Originally Posted by Seamus (Post 581554)
Ithink that we are wired correctly

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.

Kingofl337 19-02-2007 13:03

Re: Encoder Problemo
 
1 Attachment(s)
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:
Code:

void OperatorControl ( void )
{
      StartQuadEncoder ( 1 , 7 , 0 ) ;
      StartQuadEncoder ( 2 , 8 , 1 ) ;
      while ( 1 )
      {
            PrintToScreen ( "Encoder 1: %5ld  Encoder 2: %5ld\n" , (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.


All times are GMT -5. The time now is 00:30.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi