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.
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
(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!
Don’t forget to look at the FAQ: http://www.kevin.org/frc/encoder/
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
", (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