Go to Post Cooler robots = Impressed sponsors = More money for FIRST = Easier expansion = Easier culture change. Isn't this what we want? - Karthik [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 19-02-2005, 00:26
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
Encoders, interrupts, and edge-triggering issues

I just fixed a nagging problem with our encoders tonight. The nature of the problem is such that I think many people might be suffering from it. Here's the deal:

The encoder counts wouldn't always track the motion properly. Theoretically, for one full rotation, the software should always see exactly 64 counts. On occasion, it would apparently miss counts. Even though I was sure the rate wasn't too high, I added the 7474 "Phase B Catcher" circuit. I don't know whether or not that fixed the original problem, or if I was misunderstanding what was wrong in the first place, but a new and consistent problem appeared: it would often give extra counts.

Analyzing the situation yielded a theory. If the encoder were at a point where a little bit of wiggling made the Phase A signal change, it would get an interrupt for each wiggle past that point in one particular direction, because the interrupt is configured to occur only for one edge. That theory was supported by intentionally wiggling the encoder back and forth repeatedly until it started counting with no net motion actually occurring.

To fix it, I added code to toggle the interrupt edge from rising to falling, and vice versa, each time an interrupt occurred, and to treat the Phase B signal backwards for the additional edge. Now it interrupts (and counts) twice as fast, but it never loses a count or sees an extra one.

And the 7474 circuit apparently isn't necessary -- saving almost a half ounce of weight.
  #2   Spotlight this post!  
Unread 19-02-2005, 01:10
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: Encoders, interrupts, and edge-triggering issues

Alan,

Quote:
Originally Posted by Alan Anderson
I just fixed a nagging problem with our encoders tonight. The nature of the problem is such that I think many people might be suffering from it. Here's the deal:

The encoder counts wouldn't always track the motion properly. Theoretically, for one full rotation, the software should always see exactly 64 counts. On occasion, it would apparently miss counts. Even though I was sure the rate wasn't too high, I added the 7474 "Phase B Catcher" circuit. I don't know whether or not that fixed the original problem, or if I was misunderstanding what was wrong in the first place, but a new and consistent problem appeared: it would often give extra counts.

Analyzing the situation yielded a theory. If the encoder were at a point where a little bit of wiggling made the Phase A signal change, it would get an interrupt for each wiggle past that point in one particular direction, because the interrupt is configured to occur only for one edge. That theory was supported by intentionally wiggling the encoder back and forth repeatedly until it started counting with no net motion actually occurring.
Yes, this effect is easy to produce with encoder in hand, but I can't imagine this would ever be a problem in practice because any mechanical system that you'd couple the encoder's shaft to will possess far more rotational mass than the shaft alone. This coupled mass, in general, will strongly dampen vibrations that might cause this effect.


Quote:
Originally Posted by Alan Anderson
To fix it, I added code to toggle the interrupt edge from rising to falling, and vice versa, each time an interrupt occurred, and to treat the Phase B signal backwards for the additional edge. Now it interrupts (and counts) twice as fast, but it never loses a count or sees an extra one.
It may not be a problem for you, but I suspect doubling the number of interrupts per unit time will cause problems for many people.


Quote:
Originally Posted by Alan Anderson
And the 7474 circuit apparently isn't necessary -- saving almost a half ounce of weight.
I'm not sure I would make a blanket statement like this.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #3   Spotlight this post!  
Unread 19-02-2005, 07:44
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: Encoders, interrupts, and edge-triggering issues

Quote:
Originally Posted by Kevin Watson
Yes, this effect is easy to produce with encoder in hand, but I can't imagine this would ever be a problem in practice because any mechanical system that you'd couple the encoder's shaft to will possess far more rotational mass than the shaft alone. This coupled mass, in general, will strongly dampen vibrations that might cause this effect.
It's a problem in our practice. The mechanical system to which we have connected our encoder is a very small, very light omniwheel which rolls on the carpet. Like any simple omniwheel, it bounces some as it rolls. I guarantee that without the additional interrupt-edge-switching logic we get spurious counts, and with it we do not.

We're using a 64 count per revolution encoder. At an unreasonably high 15 fps, it would normally generate about a thousand interrupts per second. We figure the PIC can easily handle "several" thousand interrupts per second, so doubling the rate shouldn't break anything. Even at the unreasonably fast rate, the time between Phase A changing and Phase B changing is greater than 200 microseconds, plenty of time for the interrupt service routine to read the Phase B state. In our application, at least, the pulse catcher circuit is not needed. Indeed, it would not work for us at all without significant modification to clock on both transitions of Phase A.

Last edited by Alan Anderson : 19-02-2005 at 07:46.
  #4   Spotlight this post!  
Unread 19-02-2005, 10:31
Mr. Lim Mr. Lim is offline
Registered User
AKA: Mr. Lim
no team
Team Role: Leadership
 
Join Date: Jan 2004
Rookie Year: 1998
Location: Toronto, Ontario
Posts: 1,125
Mr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond repute
Re: Encoders, interrupts, and edge-triggering issues

Alan,

We did exactly what you have done last year, but for different reasons. We haven't noticed the same kind of missing or phantom pulses as you've described, but last year we had only a 16 count/rev mechanical encoder handy, 0 days left to ship, and a wrist motor that needed to be limited and controlled in autonomous mode.

The 16 counts were not quite enough resolution, and gearing it was not possible due to weight and time, to get the positional accuracy we needed, so we interrupted on both the rising and falling edge, and reversed inc/dec behaviour based on the B-phase for the additional interrupts. It was a super quick and dirty way to get 2X the pulses from your encoder.


THIS year however, is a whole other story.


Not wanting to be left out in the cold again, we sourced some Grayhill 63R256s to place on our drivetrain and elsewhere. At low speeds, they performed wonderfully. Even at highspeeds, they performed wonderfully, without the 7474 signal stretcher...

But if you jerked, or bumped the robot - anything causing a momentary quick (albeit small) movement - we would often see pulses in the wrong direction, and the PID loop would compensate erroneously, sometimes causing runaway motors.

We built and installed the 7474 signal stretcher circuit, and it's cleaned everything up very nicely.

If it were my decision, regardless of your count rates, I would use the 7474. Your average count rates are one thing, but if EVER there is a situation that there will be a "bump" or other short, very fast movement where even two counts will come in very fast, then I would highly recommend the 7474.

-SlimBoJones...
  #5   Spotlight this post!  
Unread 11-03-2005, 12:41
thinkpad thinkpad is offline
Registered User
AKA: Mr. Know Nothing
no team
Team Role: Programmer
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Canada
Posts: 15
thinkpad is an unknown quantity at this point
Re: Encoders, interrupts, and edge-triggering issues

Quote:
Originally Posted by SlimBoJones
Alan,

We did exactly what you have done last year, but for different reasons. We haven't noticed the same kind of missing or phantom pulses as you've described, but last year we had only a 16 count/rev mechanical encoder handy, 0 days left to ship, and a wrist motor that needed to be limited and controlled in autonomous mode.

The 16 counts were not quite enough resolution, and gearing it was not possible due to weight and time, to get the positional accuracy we needed, so we interrupted on both the rising and falling edge, and reversed inc/dec behaviour based on the B-phase for the additional interrupts. It was a super quick and dirty way to get 2X the pulses from your encoder.


THIS year however, is a whole other story.


Not wanting to be left out in the cold again, we sourced some Grayhill 63R256s to place on our drivetrain and elsewhere. At low speeds, they performed wonderfully. Even at highspeeds, they performed wonderfully, without the 7474 signal stretcher...

But if you jerked, or bumped the robot - anything causing a momentary quick (albeit small) movement - we would often see pulses in the wrong direction, and the PID loop would compensate erroneously, sometimes causing runaway motors.

We built and installed the 7474 signal stretcher circuit, and it's cleaned everything up very nicely.

If it were my decision, regardless of your count rates, I would use the 7474. Your average count rates are one thing, but if EVER there is a situation that there will be a "bump" or other short, very fast movement where even two counts will come in very fast, then I would highly recommend the 7474.

-SlimBoJones...
Hello,
We are having a similar problem with our PID control at high speed. Could you please direct me to some information on the 7474 signal stretcher circuit. Any circuit diagrams/types of chips used would be extremely helpful.

Another thing I was thinking was putting in our PID code into the the Process_Master_IO part of the code which is being called every cycle at a faster rate than 26 ms. The thinking is if the phase-B will operate at a faster rate giving the code more consistency. If my idea is completely newbie and unfounded for, don't be cruel.

Thanks for your help.
  #6   Spotlight this post!  
Unread 11-03-2005, 14:38
Caleb Fulton's Avatar
Caleb Fulton Caleb Fulton is offline
Z = Z^2 + C ......WHEEEE!
AKA: aXvXiA
#0461 (West Side Boiler Invasion)
Team Role: College Student
 
Join Date: Dec 2002
Location: West Lafayette, Indiana
Posts: 205
Caleb Fulton has a spectacular aura aboutCaleb Fulton has a spectacular aura aboutCaleb Fulton has a spectacular aura about
Send a message via AIM to Caleb Fulton
Re: Encoders, interrupts, and edge-triggering issues

On a "whim", we purchased a bunch of "budget" encoders to see if we could get them to work (they were less than $2 each). I made a little low pass filter by adding a capacitor between the output and ground on each phase (about 0.01uF-0.1uF seems to do the trick, thus far). It helps increase the time it takes the signal to go high due to the RC time constant caused by the pull-up resistor that is supposedly at the input pin. We have yet to *really* test it, but it really seems to rid of the noise associated with the aforementioned wiggling.

By "yet to *really* test it", I mean that we've hooked the shaft of the encoder directly to a drill running on the higher of two speeds without skipping pulses. We tested it briefly on the actual robot going around 8 ft/sec and it was working acceptably well from what I could tell. The plan may be to go ahead and order the $20 encoders everyone else is using, but it would be nice to know if the noise will really be much better for an optical encoder.

If anyone has an oscilloscope and is going to be at the Boilermaker Regional, let me know....
__________________
  #7   Spotlight this post!  
Unread 11-03-2005, 16:06
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: Encoders, interrupts, and edge-triggering issues

Quote:
Originally Posted by thinkpad
Hello,
We are having a similar problem with our PID control at high speed. Could you please direct me to some information on the 7474 signal stretcher circuit. Any circuit diagrams/types of chips used would be extremely helpful.
Kevin Watson posted this schematic:
http://kevin.org/frc/encoder_phase_b...ng_circuit.pdf

It works great (though it didn't solve the more mechanical issue in our case).
Quote:
Another thing I was thinking was putting in our PID code into the the Process_Master_IO part of the code which is being called every cycle at a faster rate than 26 ms. The thinking is if the phase-B will operate at a faster rate giving the code more consistency. If my idea is completely newbie and unfounded for, don't be cruel.
No, that won't do what you want it to. The PID function is written to work correctly only if it's called at a regular rate, and the "fast loop" doesn't have a guaranteed timing. It runs quickly most of the time, but gets delayed every time the 26 ms communication arrives, and there's no easy way to determine how often it runs.

You almost certainly don't need the PID sampling to run more quickly than 39 times a second anyway. If the mechanical response of a system is faster than that, it's probably not going to need PID control in the first place.
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


All times are GMT -5. The time now is 11:53.

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