![]() |
Phase A and Phase B on encoders
Hey all!
I've been looking through Kevin Watson's encoder code on his website (http://www.kevin.org/frc/). I'm trying to learn about how to make these things work, but I do know that there are two connections to the encoders. A phase A and phase B. I only saw references to phase B inside the code like pinouts to the digital inputs on 11 to ???. Where would the phase A connectors go? And why arn't they in the code? Maybe its in some file that I wouldnt know?? Thanks! |
Re: Phase A and Phase B on encoders
Phase A would be connected to the appropriate interrupt. Kevin's code is set to interrupt on a low to high logical change of phase A, which will indicate that the wheel is turning. Once you know that the wheel is turning, you can read phase B to find out in which direction it is going.
|
Re: Phase A and Phase B on encoders
Quote:
|
Re: Phase A and Phase B on encoders
Ohh I see.. So if I wanted to have Encoder1 on digital i/o #1 and #2, and Encoder2 on digital i/o #3 and #4.. I would set...
Code:
#ifdef ENABLE_ENCODER_1Code:
#define ENCODER_1_PHASE_B_PIN rc_dig_in02If you see any problems in this code, let me know because I am also learning :D Thanks every body! |
Re: Phase A and Phase B on encoders
Quote:
You should not change anything in encoder.c. It would be better to assign the Phase-B pins to not be on an interrupt pin (ie digital inputs 1-6). I'd suggest reading Kevin's encoder_readme.txt about the differences between the different ways encoders 1&2, 3&4, and 5&6 are implemented. Because of those differences, it would be best to keep both encoders on similar channels. |
Re: Phase A and Phase B on encoders
Quote:
Digital inputs 1 and 2 are the "natural" ones to use for Phase A of a pair of encoders. They can be set to cause separate interrupts on either a low-to-high or high-to-low transition of the signal. Inputs 3-6 are able to cause interrupts as well, but they all share the same interrupt bit in the processor, and they will trigger the interrupt on both rising and falling edges. The Phase B lines don't need to be connected to interrupt-capable inputs, and should generally go to input 7 or higher. |
Re: Phase A and Phase B on encoders
So I should just scrap the entire idea of moving the interupts from #1 and 2 :] . It might just be easier to use the normal interupt pins..
|
Re: Phase A and Phase B on encoders
What Alan is saying is to attach:
Encoder #1 Phase A to Digital Input #1 Encoder #2 Phase A to Digital Input #2 Encoder #1 Phase B to Digital Input #7 Encoder #2 Phase B to Digital Input #8 And I completely agree. This is the most efficient use of pin assignments. Regards, Mike |
Re: Phase A and Phase B on encoders
We are having problems with our Autonomous code. It seems that we bought 100 count quadrature encoders because we did not want to over load the processor with interrupts, but we dont get enough counts per program loop unless we are going nearly full speed. After reading some of the info about interrupts it seems that we can use different digital I/O pins and trigger on the rising and falling edge of our pulse to effectively double the amount of counts we get per program loop.
Can we also connect the 'B' side of the encoder to an interrupt and effectively quadruple the amount of precision by counting the rising and falling edges of both the 'A' & 'B' channel of the encoder? Would this be any different than multiplying the single channel count by '4'? |
Re: Phase A and Phase B on encoders
You may also want to donwload and read this whitepaper on using quadrature encoders. We found it very helpful, insightful, and should help you understand the workings better.
http://www.chiefdelphi.com/media/papers/1490 |
Re: Phase A and Phase B on encoders
Thanks for all the help everyone! The encoders work perfect :D..... just having another problem now.. I made a new post on the programming forum regarding the camera + encoder
|
Re: Phase A and Phase B on encoders
Quote:
Multiplying the existing count of the rising A interrupt by 4 doesn't tell you the encoder has moved further, it only changes the units it's expressed in. That's like multiplying your salary by 100 - okay, you then know how much you made in pennies, but it doesn't let you buy more stuff than you could before. Each actual interrupt you see tells you the encoder has absolutely, positively moved. Extra interrupts are more like extra dollars in your salary - always a nice thing:) . The complexity of your interrupt hander code goes up to correctly interpret the order of the additional interrupts, so you keep track (state machine style) of whether the encoder is rotating forwards vs backwards and when it jitters or changes direction. E.g., if the A line rises then falls again before the B line changes (either up or down) then you've reversed direction. Or an A fall followed by a B rise is the opposite of an A fall followed by a B fall. You have to know if you should be adding or subtracting encoder counts. |
| All times are GMT -5. The time now is 03:16. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi