Log in

View Full Version : Encoder help


E_Unit
10-02-2007, 17:06
I am using an optical shaft encoder with 128 clicks/revolution. I have set up the kevin.org encoder code but am only receiving one direction for feedback (0 and -1). I am curious if anyone else is having this problem or if anyone knows how we might get it to give us feedback for two directions.

JBotAlan
10-02-2007, 20:21
I'm having trouble understanding your post. Do you mean that when you spin the shaft of the encoder one direction, you get -1, and the other direction you get 0? Does the counter count at all? I think there's a debug mode; look in the header file and enable it if you see the option.

You may have the encoder wired incorrectly. Which digital input is it plugged into? Which encoder do you have? Can you point me to a spec sheet?

JBot

JHale
15-02-2007, 18:43
(From the same team)

W have the Phase A signal hooked up to Digital IO 1, and Phase B hooked up to Digital IO 11 as per the Kevin.org code.

When we print off the value from Get_Encoder_1_Count(); all that is returned is either 256 or 260 without any change when the encoder is rotated.

When we print off the value of digital_io_01, all that we are able to see is a -1 or a 0 (Which is odd because the ios should be showing 1 or 0, not a negative).

Also, when we reset the encoder count after each call of the count, the encoder alternates between 1 and 0. When you are turning it forward, we get a 1, and backwards a 0. However, when we allow the code to handle counting, all we see are 256 or 260.

I am reading through the code and will be trying the Quadrature code tonight.

Thank you!

Bharat Nain
15-02-2007, 18:45
Don't forget to look at the FAQ: http://www.kevin.org/frc/encoder/

Alan Anderson
15-02-2007, 23:19
When we print off the value from Get_Encoder_1_Count(); all that is returned is either 256 or 260 without any change when the encoder is rotated.

How are you printing it? Note that the function returns a long integer. If you're trying to print it with a %d format, you'll only get the topmost two bytes.

JBotAlan
16-02-2007, 11:02
How are you printing it? Note that the function returns a long integer. If you're trying to print it with a %d format, you'll only get the topmost two bytes.

That's what I was thinking too--printf() is very particular about the data type coming in.

To print out the encoder count, you could typecast it to an int for printf:
printf("Encoder 1 is %d\r\n", (int)Get_Encoder_1_Count());

would do it, I think.

I can't seem to find the documentation for the printf function, so I can't give you the %whatever value you need to make a long int print...I'm not even sure if it's possible directly. Just typecast it as I showed, and it should give you a good value out.

JBot