Quadrature encoder counting error 18F2431

Discussion in 'Embedded Systems and Microcontrollers' started by camerart, Jan 6, 2016.

  1. camerart

    Thread Starter Active Member

    Feb 25, 2013
    517
    30
    Hi,
    For some time I have had problems with the Quadrature encoder of an 18F2431. I'll point out that the opto disk is home made, and because of this thought it must be my fault. I've re-wired it with each output wired with a screened cable grounded only at the circuit end. The opto disk is set to 4x update mode, so 1/count for each change. The opto disk has 9Black/9clear segment, and geared 100:1 so 4x9x100 = 3600.

    I've run it oscillating fast and slow, passing zero and not passing zero, checking on the error amount, but today I found a pattern. For every full turn of the output, approx 1.7 degrees is added on or subtracted depending which way the output is running, and no other errors.

    Can anyone shed any light on this please?

    Camerart.
     
  2. Picbuster

    Member

    Dec 2, 2013
    374
    50
    please check tris registers and switch anaX for the channels used off.
    At default they seems to be analogue.( I was popping into that behave while measuring phase shift with a pic. Took me hours to find)
     
  3. JohnInTX

    Moderator

    Jun 26, 2012
    2,345
    1,028
    If the error is constant per rev and you have a scope, look carefully at the phase relationship between the two channels for an entire revolution. Any runout, wobble etc. in your wheel can cause problems here. Also make sure your detectors are located such that their focus / detection points are exactly in the center of their respective bars and that their output signals are solid for the entire revolution.
    You'd be surprised how tricky it can be to get a home-rolled encoder working reliably and how quickly small errors can stack up.
    If all of that is solid, a constant error per rev would suggest that the encoder is reading OK but something in the math may be off. Problems in detecting the signals, not responding fast enough to interrupts/polls etc. usually show up as erratic operation (wrong direction, missing pulses etc) rather than a constant error per rev.
    Good Luck.
     
  4. Alberto

    Active Member

    Nov 7, 2008
    169
    36
    There is an high possibility that the 1.7 degrees/ turn that you claim "ADDED" is due to an error in the gear ratio that is not 100:1 but sligthly less. Check with the manufacture which is the maximum tollerance for the product you are using.
     
    camerart and JohnInTX like this.
  5. camerart

    Thread Starter Active Member

    Feb 25, 2013
    517
    30
    I've just thought of an idea, that may tell me something, quickly. If I can change the MAXCNT CAB3BUFL from 3599 to 7199, it should tell me if it is something to do with the zero cross over, as it will cross over every two revs of the output, instead of one. How do I change it? At the moment it is
    CAP3BUFL = 0x0f CAP3BUFH = 0x0e.

    C.
     
  6. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,804
    833
    Try
    CAP3BUFL=0x1f
    CAP3BUFH=0x1c

    3,599 decimal is 0x0E0F hexadecimal. The high nibble is 0x0E (CAP3BUFH). Similar for the low nibble, we get 0x0F!
    7,199 decimal is 0x1C1F hexadecimal. Breaking that into 0x1F for the Low nibble and 0X1C for the high nibble, gets what you want.
     
  7. camerart

    Thread Starter Active Member

    Feb 25, 2013
    517
    30
    Hi,
    Alberto, Exactly 100:1 gear ratio.
    Picbuster, remind me again, if I don't find the error please.
    Djsfantasi, Thanks, no difference.
    JohninTX, See video: (Right click, 'save link as' then Change TXT to AVI) The video appears to show that the sensors aren't lined up squarely, also it seems to be running eccentricity. I presume that if the sensors are square, then the wave will be also square, is this correct?

    Actually even though this opto has errors, it appears to be constant, so it isn't out of the question to use it, as the output shaft won't move many revolutions. (I'll re-build it when I need this motor) I need two motors for my project, and made four, this is one of the 'rejects' and used on a test bed.

    If you agree with my fault finding, I think I will carry on with the project, taking this into consideration.

    C.
     
    • QEI.txt
      File size:
      211.7 KB
      Views:
      7
    Last edited: Jan 7, 2016
  8. JohnInTX

    Moderator

    Jun 26, 2012
    2,345
    1,028
    The vid brings back memories of doing this myself.. and yeah, you can watch it and almost see the wheel wobble-wobble-wobble watching the traces. My observations align with yours.
    The sensors are a bit off - wobble notwithstanding, you don't have a solid 90deg between the phases. Some of this is mechanical but some is electrical too. The lower trace is a lower amplitude than the upper trace and both have notable risetimes which are different than the fall times. Assuming the input thresholds are constant and identical (and they probably aren't), the effect is more phase jitter in the system. When I ran a similar-looking encoder into an interrupt-on-change affair, I was surprised to see how much the trigger points varied from cycle to cycle even. If you think about it, its not unexpected. A logic high can be anything that is above the specified Vin-low. The Vin-high is the voltage you have to apply to guarantee a logic 1 but the input will switch way before then in most cases. The actual switching point varies depending on the whims of the port itself. As long as you are pushing nice square logic levels into the port, the switching points are the same in time. A signal with a slow rise time will likely exhibit switching at various - but still legal - points on the rising signal, adding to phase error.

    I finally used comparators with hysteresis on the opto outputs to create known switching points and that fixed lots of the problems I see here.

    For the slotted wheel, I got excellent results using a chemically milled stainless steel one on a machined aluminum bobbin. It ran very true and its contribution to jitter and phase errors was negligible. Along with the comparators and careful attention to placing the retro-reflective optos it was very solid, even without the fancy QEI interface. Eventually, the SS wheel was discarded for a plastic one with lower resolution for cost savings. Some of the wobble returned but the comparators and other improvements kept things out of trouble.

    Hope that helps, keep up the good work!
     
  9. camerart

    Thread Starter Active Member

    Feb 25, 2013
    517
    30
    Hi JohninTX,

    Woke up this morning with a design for a guide for lining up the sensors, when I fix them to the adjusting brackets in future. These brackets need to be able to swing out so that the opto disk can be fitted. See photo:

    Also a way of centralising the opto disk while gluing. I will stick a disk with its centre not cut out, onto a shaft that will slide into the disk fitting. See photos: If this is turned while the glue is setting on the opto disk, I will be able to see how the two of the match at different points of 360deg, and hopefully correct any eccentricity.

    I use my old but ok oscilloscope with care as it sometimes gives slightly off readings due to the switch internals needing a clean:)

    Thanks for the explanation of the logic switching. I got to thinking about the the repeated nature of the readings that show the 2x degree error, whether slow or max speed. See below:

    Alberto, As explained above, I had doubts about the readings, so fitted a crank onto the opto end of the gearbox and found that for 1x rev of the output shaft, 99.5 turns was needed. The 1/2 turn is adding 2degrees to the output. I'm glad I double checked. Thanks for the answer.

    C.
     
    JohnInTX likes this.
  10. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
    hi C,
    That rotational error in your system could explain why my programs work OK in my hardware, as I use a commercially sourced encoder to pre-check my software.

    E
     
    JohnInTX likes this.
  11. dannyf

    Well-Known Member

    Sep 13, 2015
    1,809
    361
    What the problems are, I can assure you that they have nothing to do with your circuits, and your code, or your test set-up. So look somewhere else.
     
  12. camerart

    Thread Starter Active Member

    Feb 25, 2013
    517
    30
    Ok D, thanks.

    Eric,
    You used a quality encoder connected to a motor, I used a quality motor/gearbox and home made encoder. The odds of where the error lied was definitely in the home made encoder. I may never have found it!

    Thanks to all who replied, especially Alberto.

    Camerart.
     
Loading...