Shop OBEX P1 Docs P2 Docs Learn Events
Issues with quad encoders, second phase is missing counts?? — Parallax Forums

Issues with quad encoders, second phase is missing counts??

rwgast_logicdesignrwgast_logicdesign Posts: 1,464
edited 2013-12-28 21:46 in General Discussion
Im having a really weird issue, I built two Quad encoders and I just went to tweak there placement and do a final bolt down with lock tight. Well I noticed that on my left quad encoder one channel is reading a much lower frequency than the others. All three encoder channels were reading about 480hz at 3.7v, The fourth channel which would be the lower one used to determine direction on the left wheel is only reading about 200hz. In reality I guess this isnt too important since it is not the encoder reading the speed. But whats bugging me is the wave form looks perfect! Im not seeing missing counts or longer pulses on the direction channel... Here is a picture showing the frequency at the bottom and the waves...

scope.gif
1024 x 576 - 159K

Comments

  • WildatheartWildatheart Posts: 195
    edited 2013-12-28 01:36
    But whats bugging me is the wave form looks perfect! Im not seeing missing counts or longer pulses on the direction channel... Here is a picture showing the frequency at the bottom and the waves...

    Can you post an Oscope shot that zooms in on a single wave form of ch 1 and ch 2? I'm seeing a strong 10 and a strong 01,but the necessary 00 & 11 conditions aren't so clear.
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2013-12-28 10:15
    Hmmm I,m not understanding what you mean by meeting the 00 & 11 condition. I decided to add quite a few pictures to be as through as possible because I am even more confused. The wave forms are 90 degrees out of phase, but I can tell the directional encoder channel 2 in the pics below is pulsing for a little less time, this is just how the sensors are positioned relative to the size of the encoder disc. I had to make my discs bigger when I changed to a twelve transition pattern to get 360 counts per rev. I also plan on hooking this all up to an LM339 comparator with a 1V reference set as the low condition, this way I get perfect square waves. Ok this is why im acually more confused!! Every encoder read at 480hz, except the second phase of the left encoder in the shot above. When I started changing the horizontal timing the scope started reading that encoder as being the same speed as the rest. Here is a picture of the accual encoders along with the best screen shots I could get at 500 and 200us...


    200us.gif
    500us.gif

    sensors.jpg
    wheel.jpg
    finished.jpg


    So I guess the new question is, are these encoders going to work even with the slightly shorter pulses on channel two?
    1024 x 576 - 133K
    1024 x 576 - 138K
    1024 x 577 - 92K
    1024 x 577 - 99K
    1024 x 577 - 86K
  • ercoerco Posts: 20,256
    edited 2013-12-28 10:35
    Two possible issues, first is your sensors are not properly spaced (distance apart) WRT the encoder disk.

    Second is more problematic, your TCRT5000 sensors are not good for this application. They are relatively large and have no real directional isolation, just a minimal shield between the LED and PTX. They will give you a loosey-goosey output signal, not a sharp transition. Do you have any (electronic) filters or Schmidt triggers on this to give you a sharper signal to your micro? All I see is some resistors on your sensor PCB.

    You could try to add a small tube to your sensor (at least the phototransistor) to make it more directional. Paint it flat black.

    If you want a great sensor for DIY encoders, try these: http://www.junun.org/MarkIII/Info.jsp?item=48

    http://forums.parallax.com/showthread.php/149740-Rare-Wheel-Encoder-Sensors-Available-Strike-Now!
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2013-12-28 10:56
    No filtering yet, I plan to add an lm339 comparator to clean up the signal. I just boosted the voltage to my sensors and then connected them to a DSO to see about what I could expect when I start filtering... this is what im looking at

    dso.gif


    Still out of phase a little bit, but much better. I know you use encoders all the time erco.. in your opinion is the signal above good enough? Im definitely going to see what I can do about getting the best transition point with the comparator and try to get the sensors a bit more directional too.. just wondering if where im at now is even close to acceptable or if the two encoder phases have to be absolutely perfectly 90 degrees off no exceptions!?

    I have no problems buying the sensors you recommend above, but I would really just like to get what I have working so I can move on to this part of the software ASAP.
    1024 x 576 - 88K
    dso.gif 88.1K
  • WildatheartWildatheart Posts: 195
    edited 2013-12-28 11:39
    Try adjusting the spacing of your sensors to replicate the waveform pictured below. Notice that there are 4 states if your encoders are properly phased (spaced): 00 (low/low), 01 (low/high), 10 (high/low), and 11 (high/high). A properly written Q encoder program must consider all 4 states to give you accurate counts. Although your pulses look pretty good and should work without additional filtering, I use a 74hc14 to provide a sharper wave form as shown below. I'd start by adjusting your sensor spacing, and also make sure you're using properly written Q encoder program.

    Well, I can't seem to upload the image this morning, but if you search the internet images for Q encoder wave forms you'll clearly see the 4 necessary states.

    Shift the lower channel shown to the left a bit to give you a better 90 degree phase shift.
  • ercoerco Posts: 20,256
    edited 2013-12-28 11:51
    A LM339 will help. Be sure to ground all unused input pins and add a feedback resistor (1-10M) for hysteresis, both to avoid oscillation. Good read on using a 339 as a "signal conditioner" at http://list.dprg.org/archive/1998-July/005620.html

    Per wild@, spend some time optimizing your encoder spacing for best results.
  • WildatheartWildatheart Posts: 195
    edited 2013-12-28 12:04
    Doesn't matter if channel A pulse is a bit longer than channel B pulse - just try to get B shifted a bit to the left to give your program enough time to see the 4 states.
  • jmgjmg Posts: 15,173
    edited 2013-12-28 14:26
    ... just wondering if where im at now is even close to acceptable or if the two encoder phases have to be absolutely perfectly 90 degrees off no exceptions!?

    90' is the ideal point for best margin, and gives linear LSB edges.

    A good Quad decoder, will still work, even with switching skewed a long way from 90'.

    One problem with skew, is the Quad state decision time, needs to complete inside the smallest dT at highest speed, so you compromise the highest attainable speed.
  • jmgjmg Posts: 15,173
    edited 2013-12-28 14:35
    All three encoder channels were reading about 480hz at 3.7v, The fourth channel which would be the lower one used to determine direction on the left wheel is only reading about 200hz.

    The Propscope display does not make sense - the waveforms do not match the reported numbers ?
    Both traces show just under 5 cycles in 10ms, but the numbers do not agree.
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2013-12-28 17:11
    @JMG So what is going on? I get the exact same frequency for both phases on the right encoder, and it seems as though the frequency's don't match up on the left encoder at a 1ms division or higher, anything lower and the propscope shows close to matching frequency's.

    I will try conditioning the signal as well as I can then moving the sensors back a little farther if need be, as that will require some precision drilling. Thanks for all the info and links guys.
  • jmgjmg Posts: 15,173
    edited 2013-12-28 18:17
    @JMG So what is going on? I get the exact same frequency for both phases on the right encoder, and it seems as though the frequency's don't match up on the left encoder at a 1ms division or higher, anything lower and the propscope shows close to matching frequency's.

    Sounds like the PropScope is less than ideal in how it calculates Freq, if you swap sources, does the error swap, or stay on Ch1 ?

    Do you have another measurement instrument choice ?

    eg try the frequency counter included here
    http://www.daqarta.com/
  • Duane DegnDuane Degn Posts: 10,588
    edited 2020-10-29 13:26
    My bet is it's some sort of setting issue. There are other screen captures that look fine.

    Have you seen my hardware thread about encoders? One of the first things to take into account is the placement of the sensors. For example the ActivityBot encoder openings are are spaced 11.25 degrees apart (360/32). In order to get the sensor positioned correctly I placed them 14.06 degrees apart (11.25 * (5/4)). Since the openings were too close together for a 90 degree offset I used a 360 + 90 offset. 360 in this case is a full encoder cycle.

    Since your cycles are 60 degrees apart, you'd want your sensors spaced either 15 degrees apart or 75 degrees apart (45 degrees should also work). You might be able to adjust this angle by moving your sensors radially from the center of the disk. You want one sensor to be right in the middle of a stripe (either color) and the other sensor to be right at a transition between colors.

    You can get away with the encoders not being aligned just right as long as each transition can be caught separately.

    I think my encoder software could distinguish the transitions as long as there were 6 us between the transitions. I think there's other software with even better resolution.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2020-10-29 13:22
    Have you tried reading the encoders with the Propeller yet?

    Be aware that Kye's QE object turns out to have a bug. Wildatheart found it. The object doesn't catch all the transitions.

    I'm pretty sure it doesn't count transitions accurately either. Kye posted another object in the tread I previously mentioned. I've looked at it but it's over my head (as much of Kye's stuff is).
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2013-12-28 19:38
    @JMG, this is definitely an issue with the prop scope, I got my multimeters out and for some reason they all read 0hz, even my pricey 100+ ones..? Do DMMs only count AC frequency, i.e + and - cycles? So I remember my Bus Pirate has a frequency counter on it. I plugged it in and tested all four encoder lines at around 500hz. As far as my prop scope goes it does not matter what channel I use to read my bottom left encoder 1 or 2. it always gets the frequency wrong, but only on that one encoder... very odd.

    @Duane I have not tried to read the encoders using the Propeller yet. That is the next step. Im really doing whatever I can to try to not have to redo my sensor boards or re-drill my chassis.Basically what Im taking away from what you said above is that I should be fine as long as the encoders are in the right states for at least 6uS, and if I want my encoders have perfectly out of phase signals Im going to have to offset my sensors at 15 or 75 degrees and not 90?
  • jmgjmg Posts: 15,173
    edited 2013-12-28 19:55
    @JMG, this is definitely an issue with the prop scope, I got my multimeters out and for some reason they all read 0hz, even my pricey 100+ ones..? Do DMMs only count AC frequency, i.e + and - cycles?

    Try AC coupling (ie a series 0.1uF) ?
    So I remember my Bus Pirate has a frequency counter on it. I plugged it in and tested all four encoder lines at around 500hz. As far as my prop scope goes it does not matter what channel I use to read my bottom left encoder 1 or 2. it always gets the frequency wrong, but only on that one encoder... very odd.

    It is strange that it is not even a 2:1 error - looks like a bug, and may be related to Phase, or trigger thresholds.
    Does it change if the trigger channel changes ?
    The icon shows a trigger point on a single cycle, but the screen does not show exactly where it is extracting the Freq info from. (ie Threshold used, how many cycles are included, and how it manages whole cycle inclusion)

    Perhaps the PropScope Logic analyser mode includes a Freq Ctr ?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-28 19:58
    @Duane I have not tried to read the encoders using the Propeller yet. That is the next step. Im really doing whatever I can to try to not have to redo my sensor boards or re-drill my chassis.Basically what Im taking away from what you said above is that I should be fine as long as the encoders are in the right states for at least 6uS,

    Yes, the loop reading the encoders take about 6us (though that included PWM generation) and you don't want both the A and the B channels to have both transitioned during one loop of the PASM code. As long as the transitions occur in separate loops the direction will be detected correctly.
    and if I want my encoders have perfectly out of phase signals Im going to have to offset my sensors at 15 or 75 degrees and not 90?

    The problem here is where using two different systems when we talk about degrees. There's the degree around the encoder disk and there's the degree within an encoder cycle. The two are not the same. They would be the same if your encoder disk had one black stripe which took up half of the disk. In this case the degrees of the encoder cycle would match the degrees around the disk.

    Let's assume for a bit that you do have one big black stripe. Now lets say the black/white transition is at zero degree on the disk. You'd place one sensor inline with this transition and the other one in the center of either the black or the white area. In this case the sensors are 90 degrees out of phase.

    If instead of a single black stripe you now had two so each section took up a quarter of the disk. If you left your sensors in the same location you'd now have both sensors over a transition point. While the sensors are still 90 degrees apart around the disk, they're 180 degrees out of phase in relation to the encoder cycle. To fix this you'd move one sensor so it's in the middle of a black or white section.

    The important thing to remember is:
    Duane Degn wrote: »
    You want one sensor to be right in the middle of a stripe (either color) and the other sensor to be right at a transition between colors.

    Some of your readouts look like they're 180 degrees out of phase and not 90. You do not want both channels to transition at once.
  • WildatheartWildatheart Posts: 195
    edited 2013-12-28 21:14
    Im really doing whatever I can to try to not have to redo my sensor boards or re-drill my chassis.

    You may be adjusting one or both sensors only a few thousands of an inch. I found that slightly slotted fastening holes work well to adjust the sensors (for close to 90 degrees out of phase). Use a small rat tail file or the side of your drill to elongate the mounting holes - shouldn't require a major rework to your bot or your board. Set your scope to observe a single set of pulses and lock the sensors down as detailed above.

    I'm using a 30 slot disk with a pair of TCST2103 optical slot switches and had to do exactly as I'm suggesting here. I also had to reduce the encoder slot size to a width of about .025 inches to keep my TCST's in the same plane.
    260 x 194 - 27K
    208 x 156 - 24K
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2013-12-28 21:46
    Thanks Duane I got it now, I'm not sure any encoder tutorial has ever explained this correctly most of what I have read just say the sensors need to be offset 90 degrees.

    Wildatheart I have already super glued the sensors and potted the board in rubber, so my easiest option may be to just print a new disk. Second best option is to probably just remake the two sensor boards.
Sign In or Register to comment.