Go to Post It is going to be a water game. Sorry, I thought everybody knew that. :ahh: - FrankJ [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 09-11-2005, 18:05
Issues Issues is offline
Registered User
FRC #0525
 
Join Date: Nov 2005
Location: Iowa
Posts: 11
Issues is on a distinguished road
Why are four states needed with Quadratuer encoders?

I did a search and I couldn't find an answer to this.

First of all I want to know if my idea of how these things work is right. For each Quadratuer encored there are two digitial pins used set as inputs. So each pin can be 1 or 0 which means there are four possible combinations right? To me a wheel can have three states: forward, backward, and at rest. So what is the forth combination used for? Or is it used at all!
  #2   Spotlight this post!  
Unread 09-11-2005, 18:20
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: Why are four states needed with Quadratuer encoders?

Quote:
Originally Posted by Issues
I did a search and I couldn't find an answer to this.

First of all I want to know if my idea of how these things work is right. For each Quadratuer encored there are two digitial pins used set as inputs. So each pin can be 1 or 0 which means there are four possible combinations right? To me a wheel can have three states: forward, backward, and at rest. So what is the forth combination used for? Or is it used at all!
you are looking at the input to the encoder. The two signals are needed so the encoder can determine which way it is moving, as well as how fast its moving.

It gets better. The encoder also remembers the previous level of those two signals. Based on how they change it can then determine which way its rotating.

The output of the encoder is not really a set of states, its a vector speed (signed variable), or for some, a vector distance, clocked out at fixed intervals..

look at an actual encoder disk, think about what happens as it rotates, and it will make more sense to you.
  #3   Spotlight this post!  
Unread 09-11-2005, 18:23
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: Why are four states needed with Quadratuer encoders?

there is a good illustration in this thread, about 3 or 4 posts down:

http://www.chiefdelphi.com/forums/sh...ture+encode r
  #4   Spotlight this post!  
Unread 09-11-2005, 18:49
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Why are four states needed with Quadratuer encoders?

Expanding on what Ken said, and using the encoder wheel he linked to (note that there are many different types of encoder wheels)....

Imagine that you have two sensors , A and B, that are placed on the radius of the encoder such that A is over the inner encoded band and B is over the outer. The way that the encoder wheel is laid out, if sampled properly, A and B will never change states at the same time.

Knowing this, the following table describes the valid state transitions. (assume 0 = dark and 1 = light)
Code:
Previous AB     Current AB
     00               01         - Counterclockwise               
     00               10         - Clockwise

     01               11         - Counterclockwise
     01               00         - Clockwise         

     11               10         - Counterclockwise              
     11               01         - Clockwise

     10               00         - Counterclockwise              
     10               11         - Clockwise
Transitions such as 00->11, 01->10, 10->01, 11->00 tell you that there was rotation, but you don't know which direction the rotation was.

So to answer your original question, you have 4 states because there are 4 states that your encoder is reporting.
  #5   Spotlight this post!  
Unread 09-11-2005, 19:44
Unsung FIRST Hero
Al Skierkiewicz Al Skierkiewicz is offline
Broadcast Eng/Chief Robot Inspector
AKA: Big Al WFFA 2005
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1996
Location: Wheeling, IL
Posts: 10,792
Al Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond reputeAl Skierkiewicz has a reputation beyond repute
Re: Why are four states needed with Quadratuer encoders?

Issues,
Building on what has already been presented, a quadrature encoder is one in which the outputs ( in this case two) are electrically 90 degrees apart. It is common to divide a circle into four parts and these are normally called quadrants. Quadrature is a term to show that signals are in adjacent quadrants but not opposite.
A simple encoder can be built using a wheel with half the rotation colored black and half white. By using two light sensors placed such that one is 90 degrees of rotation behind the other one you can determine not only how fast the shaft is turning but what direction. For this simple encoder, it will require at least 180 degrees (one half the wheel) of rotation to get one tach pulse and 270 degrees (more than one half the wheel) of rotation to get two tach pulses and determine the direction the shaft is moving. (See Dave's table above.) This type of encoding is simple to use and decode with software or a few logic gates. If you add more light and dark spaces one the wheel you increase the accuracy.
For instance if you are sensing a wheel that has a circumference of 10 inches and you use a disk that is half white and half black, the minimum distance you can measure is 5 inches (10"/2 sections). If you divide the disk into 10 sections, alternating white and black, you can measure 1 inch (10"/10 sections), etc.
__________________
Good Luck All. Learn something new, everyday!
Al
WB9UVJ
www.wildstang.org
________________________
Storming the Tower since 1996.
  #6   Spotlight this post!  
Unread 09-11-2005, 21:26
Mike's Avatar
Mike Mike is offline
has common ground with Matt Krass
AKA: Mike Sorrenti
FRC #0237 (Sie-H2O-Bots (See-Hoe-Bots) [T.R.I.B.E.])
Team Role: Programmer
 
Join Date: Dec 2004
Rookie Year: 2004
Location: Watertown, CT
Posts: 1,003
Mike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond repute
Re: Why are four states needed with Quadratuer encoders?

A good whitepaper, written by Dan Katanski of FRC240, discussing quadrature encoders can be found at http://www.chiefdelphi.com/forums/pa...le&paperid=283
__________________
http://www.mikesorrenti.com/
  #7   Spotlight this post!  
Unread 10-11-2005, 10:17
Issues Issues is offline
Registered User
FRC #0525
 
Join Date: Nov 2005
Location: Iowa
Posts: 11
Issues is on a distinguished road
Re: Why are four states needed with Quadratuer encoders?

Thank you for the feedback. The colored wheel illistration was helpful. I still have a question. I looked at how you set up the code and I think I get it, but what edge should be set for interupt? For the machine to keep up with the state changes wouldn't you want to interupt both when it goes from white to black and from black to white?
  #8   Spotlight this post!  
Unread 10-11-2005, 10:58
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Why are four states needed with Quadratuer encoders?

Absolutely, you need to catch both the rising and falling edge.

If you watch only one edge,for the sake of argument let's use the rising edge (0->1) , you will only ever be looking at the following transitions...
00->01 00->10 01->11 10->11
Compare that to the table above and you'll see that you're only getting half the story. Watching only one edge will definately not work for the normal usage.
  #9   Spotlight this post!  
Unread 10-11-2005, 11:23
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: Why are four states needed with Quadratuer encoders?

Quote:
Originally Posted by Issues
Thank you for the feedback. The colored wheel illistration was helpful. I still have a question. I looked at how you set up the code and I think I get it, but what edge should be set for interupt? For the machine to keep up with the state changes wouldn't you want to interupt both when it goes from white to black and from black to white?
how you decode the signals will determine the resolution and max input speed of your 'speedometer'.

Note that the drawing on the other page is only a crude illustration to show how it works. Most encoder wheels have hundreds, or thousands of marks, instead of 4 or 8.

I think you can use one of the signals as a clock, and the other as the data, if you register on both edges of the clock. Using interrupts will lower your max speed reading (when the interrrupts start to overrun each other).
  #10   Spotlight this post!  
Unread 10-11-2005, 11:36
Joe Johnson's Avatar Unsung FIRST Hero
Joe Johnson Joe Johnson is offline
Engineer at Medrobotics
AKA: Dr. Joe
FRC #0088 (TJ2)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Raynham, MA
Posts: 2,648
Joe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond repute
Re: Why are four states needed with Quadratuer encoders?

Some times, you don't always have 90 degrees between the two sensors or you don't always have exactly 50% duty cycles (a.k.a. even ON and OFF times). In these cases, folks often ignore edges to improve on velocity calculations.

By calculating velocities based on rising edge to rising edge of the same channel (or falling to falling) you can avoid the problems associated with non-50% duty cycles and variations in phasing between A & B*.

Note that we don't always get to spec out the encoder we'd like in an ideal world so we sometimes end up with the phasing and the duty cycle of the sensors being non-constant due to changes in velocity, temperature, voltage, etc. It is not ideal, but what is?

This tends to be more of a problem with calculating velocities than positions.

Joe J.

*you can still get a velocity calc at every edge, but you have to keep 4 different times in memory and subtract the appropriate past time from the current time. Also, you need to be careful during transitions from CCW to CW or vise versa. It is surprisingly easy to write code that blows up (or at a mininum gets the wrong answer) during direction changes.
__________________
Joseph M. Johnson, Ph.D., P.E.
Mentor
Team #88, TJ2
  #11   Spotlight this post!  
Unread 10-11-2005, 14:16
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Why are four states needed with Quadratuer encoders?

Quote:
Originally Posted by Issues
Thank you for the feedback. The colored wheel illistration was helpful. I still have a question. I looked at how you set up the code and I think I get it, but what edge should be set for interupt? For the machine to keep up with the state changes wouldn't you want to interupt both when it goes from white to black and from black to white?
It turns out that you only need to generate an interrupt based on one edge of one of the phases. If you set things up to interrupt on the rising edge of the A phase, you will be be notified about two state transitions: 00->10 and 01->11. The level of the B phase at the time tells you immediately which direction the encoder is turning. You only get information for one transition out of four, but that's usually more than enough. In order to track the relative motion of the encoder continuously, the interrupt service routine just needs to increment or decrement a value based on what the B phase is.

Occasionally details in the imperfect real world make it necessary to get fancier than that, but the very simple scheme is generally sufficient.
  #12   Spotlight this post!  
Unread 11-11-2005, 13:30
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Why are four states needed with Quadratuer encoders?

Quote:
Originally Posted by Dave Scheck
Absolutely, you need to catch both the rising and falling edge.... ...Watching only one edge will definately not work for the normal usage.
Just to pile on, and expand a bit on what Alan says above, you only need to interrupt on one edge. Here's the entire interrupt handler from some code I wrote:

Code:
void Left_Encoder_Int_Handler(void)
{

// The left encoder's phase-A signal just transitioned
// from zero to one, causing this interrupt service
// routine to be called. We know that the encoder just
// rotated one count or "tick" so now check the logical
// state of the phase-B signal and increment or decrement
// the Left_Encoder_Count variable.
if (LEFT_ENCODER_PHASE_B_PIN ==0)
{
Left_Encoder_Count -= LEFT_ENCODER_TICK_DELTA;
}

else

{
Left_Encoder_Count += LEFT_ENCODER_TICK_DELTA;
}

}
LEFT_ENCODER_TICK_DELTA is #define'd as either 1 or -1. This works great for velocity control and most of the time for position control. If I remember correctly, several months ago Alan mentioned that he had a problem using this scheme in his position control application because his mechanism would sometimes stop right on a tick mark and generate a bunch of spurious interrupts, which would cause problems because the phase-b signal might change before the ISR could read it. In this case you need to add some hysteresis in the form of a state machine to track the states and increment/decrement the counter correctly. This approach increases reliability at the cost of greatly increasing the time spent in the ISR, which will decrease the maximum tick-tracking rate of your encoder software. I'll add this capability to my encoder code in the near future and update the documentation.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #13   Spotlight this post!  
Unread 11-11-2005, 14:05
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Why are four states needed with Quadratuer encoders?

Quote:
Originally Posted by Kevin Watson
If I remember correctly, several months ago Alan mentioned that he had a problem using this scheme in his position control application because his mechanism would sometimes stop right on a tick mark and generate a bunch of spurious interrupts, which would cause problems because the phase-b signal might change before the ISR could read it.
That's not quite how the problem manifested itself. The B phase isn't going to be changing at all when the encoder is hovering at an A phase transition, so the time it takes to read it isn't really an issue. The actual problem is that this simple scheme only notices the 0->1 transition, and ignores the 1->0 transition that accompanies a miniscule reverse motion of the encoder. Instead of recognizing that the encoder is "vibrating" at one spot, the software ends up counting things as if the encoder were continuously moving in one direction. Our solution was to set the hardware to interrupt on both the rising and falling edges, and complicate the interrupt service routine accordingly to recognize all four possibilities instead of just two. (That was difficult because our position tracking system used three encoders, and the RC only has two digital inputs capable of being configured to interrupt on both edges.)
  #14   Spotlight this post!  
Unread 11-11-2005, 14:22
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Why are four states needed with Quadratuer encoders?

Kevin, Alan, thanks for your clarification.

I guess I should have been a little more clear when I used the word "absolutely". My interpretation was that Issues intended to use both channels of the encoder to get the best resolution possible, which to my understanding, was to catch both edges of both channels.
  #15   Spotlight this post!  
Unread 11-11-2005, 15:02
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Why are four states needed with Quadratuer encoders?

Quote:
Originally Posted by Alan Anderson
That's not quite how the problem manifested itself...
Okay, got it. I'll incorporate a fix in a new version of my ISRs.
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2005 FRC Team Update 14 Jeffrafa General Forum 43 01-03-2005 15:52
Code: Toggle on Tap Dave Scheck Programming 0 11-02-2005 18:07
Autonomous Camera Integration GregC Programming 2 06-02-2005 14:34
State Machines doyler Programming 7 11-01-2005 00:53
Mechanical Wheel Encoders? Jaine Perotti Electrical 15 04-12-2004 22:46


All times are GMT -5. The time now is 21:05.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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