Quad Encoder Problem


Closed Thread
Results 1 to 37 of 37

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: Quad Encoder Problem

    I have to admit, Ioannis, the code was grabbed from an example here and implemented on my side using a Grayhill encoder which only triggered the interrupt once per detent. Works perfectly with that device, With the CUI ACZ11, I added the check on the ISRCounter but it **does** work - both CW & CCW rotations are captured correctly.

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Quad Encoder Problem

    I tried CCW rotation again last night and it does seem to get confused every once in a while - either decrements by 2 or sometimes even increments. Doesn't happen often enough to be too much of a problem, but I would like to make the code as efficient as possible.

    Not sure what else I can do in the ISR, though. If I only need one edge to check the rotation direction then I could do as Henrik suggested and turn off 2 of the edge interrupts; that way, it would only hit the ISR twice. I could do the RotEncDir determination on the first interrupt then set a flag to ignore the 2nd interrupt, then reset those after the 2nd.

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,139


    Did you find this post helpful? Yes | No

    Default Re: Quad Encoder Problem

    I stil cannot see how this piece of code can be true:

    Code:
    RotEncDir = New_Bits.1 ^ Old_Bits.0
        IF RotEncDir = 1 Then
    If you follow what Henrik has posted on that pulse train diagram at #21, you will see that after the above XOR, the IF RotEncDir = 1 statement will always fail and the ELSE will be executed.

    Ioannis

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Quad Encoder Problem

    The New_Bits will be the same for A & B, but the Old_Bits should still have PORTA.0 (B pin of encoder) as 1 for the last falling edge interrupt, won't it?

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,139


    Did you find this post helpful? Yes | No

    Default Re: Quad Encoder Problem

    I don't think so after the 4 step counter. At that moment both will be zero.

    Ioannis

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Quad Encoder Problem

    But experimentally it works, both for CW & CCW. I'd love to optimize this code for full quad cycle encoders like the CUI ACZ11 one I'm using, but I'm at a loss as to what to change (other than trying Henrik's suggestion of reducing the number of edges to 2 from 4).

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Quad Encoder Problem

    Hi,
    Change the code so that you interrupt on one edge of one channel - only. (The rising edge of channel A for example).
    In the ISR, poll "the other" channel, if it's low you're moving in one direction, if it's high you're moving in the other.
    Verify that it works at "any" speed you may turn the encoder.

    /Henrik.

Similar Threads

  1. RF600E & RF600D encoder/decoder problem
    By Megahertz in forum Off Topic
    Replies: 0
    Last Post: - 17th April 2012, 17:18
  2. using Quad UART
    By harryweb in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 30th April 2011, 00:13
  3. quad encoders
    By cpayne in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th March 2007, 17:49
  4. Quad encoder problems
    By smitty505000 in forum mel PIC BASIC Pro
    Replies: 51
    Last Post: - 5th October 2006, 22:44
  5. Encoder problem
    By precision in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th September 2006, 22:21

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts