Log in

View Full Version : Question about Gear Sensor


beefy23
28-03-2008, 14:38
I have tried to look for some guides about Gear tooth sensor, but what I`ve found doesn`t really help me.

Some stuff is ambiguous for me.

What are the meanings of quadrature encoder`s states, what does each of them tell me about?

What is Get_Encoder_1_Count() and Get_Encoder_2_Count() , and what`s the meaning of the number in the name of the function.

-I use MPLAB

Thank you in advance.

JamesBrown
28-03-2008, 15:01
I have tried to look for some guides about Gear tooth sensor, but what I`ve found doesn`t really help me.

Some stuff is ambiguous for me.

What are the meanings of quadrature encoder`s states, what does each of them tell me about?

What is Get_Encoder_1_Count() and Get_Encoder_2_Count() , and what`s the meaning of the number in the name of the function.

Thank you in advance.

Quadrature encoders are similar in purpose to gear tooth sensors but are different in functionality. A quadrature encoder has an additional channel that indicates the direction the encoder is being turned.

In Kevin Watson's FRC code the functions like Get_Encoder_1_Count() return the net number of pulses sent by the encoder plugged into the port as declared in the encoder.h file. The numbers are used to distinguish between encoders, I believe Kevin's code allows for 6 to be used at a time.

The value returned by Get_Encoder_1_Count() can be converted into distance traveled since the encoder was last reset by multiplying the value by the ratio of encoder turns to wheel turns then by multiplying by the wheel circumference.

beefy23
28-03-2008, 15:21
Quadrature encoders are similar in purpose to gear tooth sensors but are different in functionality. A quadrature encoder has an additional channel that indicates the direction the encoder is being turned.

In Kevin Watson's FRC code the functions like Get_Encoder_1_Count() return the net number of pulses sent by the encoder plugged into the port as declared in the encoder.h file. The numbers are used to distinguish between encoders, I believe Kevin's code allows for 6 to be used at a time.

The value returned by Get_Encoder_1_Count() can be converted into distance traveled since the encoder was last reset by multiplying the value by the ratio of encoder turns to wheel turns then by multiplying by the wheel circumference.

And how do you know which analog input to receive the information?

JamesBrown
28-03-2008, 15:29
And how do you know which analog input to receive the information?

Encoders and Gear tooth sensors are both traditionally digital sensors, you can find what ports to use in encoder.h

beefy23
28-03-2008, 15:36
Encoders and Gear tooth sensors are both traditionally digital sensors, you can find what ports to use in encoder.h

how could it be a digital sensor? it has more than 2 possibilities..
and where can I see exactly what the ports are in encoder.h?

Tottanka
28-03-2008, 15:50
how could it be a digital sensor? it has more than 2 possibilities..
and where can I see exactly what the ports are in encoder.h?
it does not have more than 2 options...

JamesBrown
28-03-2008, 16:00
For encoder 1 phase A goes to dig_in 1 phase b to dig_in 11
encoder 2 uses 2 and 12, 3 uses 3 and 13, ans so on.

There is not more than one option, the encoder or gear tooth sensor just pulses once for every set fraction of a rotation, ie when ever the gear tooth sensor senses a gear tooth. This pulse triggers an interrupt in Kevin's code and that tallies the number of pulses, adding one for each forward pulse and subtracting one for each reverse pulse. This tally is returned by get_encoder_count.

Alan Anderson
28-03-2008, 16:40
What are the meanings of quadrature encoder`s states, what does each of them tell me about?

The word "quadrature" refers to two signals which are out of phase with each other by one quarter of a cycle. The signals on a quadrature encoder are digital, and there are four possible combinations: 00, 01, 11, and 10. Notice that they don't "count" in binary; instead, only one of the signals changes for a transition between states. A change from 00 to 01 indicates the encoder is turning in one direction; a change fom 01 to 00 indicates it is turning in the other. Here's the full list of possibilities:


from to direction
00 01 forward
00 10 reverse
01 11 forward
01 00 reverse
11 10 forward
11 01 reverse
10 00 forward
10 11 reverse


A simple way to use quadrature encoders is to use interrupts to detect a transition from 0 to 1 on one signal (usually called Phase A), and look at the state of the other signal (Phase B) at that time to decide which direction the sensor is turning. That only uses two of the possible eight changes, but it's sufficient: 01 to 11 is forward, and 00 to 10 is reverse.

beefy23
28-03-2008, 18:15
The word "quadrature" refers to two signals which are out of phase with each other by one quarter of a cycle. The signals on a quadrature encoder are digital, and there are four possible combinations: 00, 01, 11, and 10. Notice that they don't "count" in binary; instead, only one of the signals changes for a transition between states. A change from 00 to 01 indicates the encoder is turning in one direction; a change fom 01 to 00 indicates it is turning in the other. Here's the full list of possibilities:


from to direction
00 01 forward
00 10 reverse
01 11 forward
01 00 reverse
11 10 forward
11 01 reverse
10 00 forward
10 11 reverse


A simple way to use quadrature encoders is to use interrupts to detect a transition from 0 to 1 on one signal (usually called Phase A), and look at the state of the other signal (Phase B) at that time to decide which direction the sensor is turning. That only uses two of the possible eight changes, but it's sufficient: 01 to 11 is forward, and 00 to 10 is reverse.

but how can you easily get the bits content? Can you please write a code(I work in MPLAB). Thanks.

Alan Anderson
04-04-2008, 16:38
Can you please write a code(I work in MPLAB). Thanks.

Kevin Watson (http://kevin.org/frc) has written exactly what you need, and makes it available to all. Here (http://kevin.org/frc/frc_encoder.zip) it is, complete with detailed instructions for adding it to your project in MPLab.

Jared Russell
06-04-2008, 23:59
Do as above, but note that the gear tooth sensors in the kit have only a single phase. This means that the encoder code will only count either up or down.

If you want direction information (i.e. a count that goes up when rotating one way, and down when rotating the other), you need to estimate it based on other factors (such as commanded motor direction, etc.).