Hello, welcome to our forum.

It looks like you have registered but you have not yet posted and messages. Our requirements are that you must post at least two messages, to allow the moderators to review your registration, before you will be allowed access to the full range of forum areas.

Please make a couple of posts, until then you may see a notice that says you are banned from certain forum areas.


Thank you.

Remove Text Formatting
Loading...

+ Reply to Thread
Page 3 of 3 FirstFirst 123
Results 81 to 89 of 89
  1. #81
    cbrun17's Avatar
    cbrun17 Guest

    Default Re: decoding quadrature encoders

    Hi Henrik,

    I changed the display routine as you described and it does work much better. I sure do over think some of this stuff... I did have to increase the pause to 250ms to allow for the display to update since it seemed to trip over itself a little more frequently this way.

    I believe moving to either serial LCD or 7 seg LED might be the better solution.

    Thanks again for your expert advise.

    Chris
    Last edited by cbrun17; - 11th February 2017 at 20:28.

  2. #82
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    988

    Default Re: decoding quadrature encoders

    Excuse me Henrik, If you read the spec. sheet you can set the interrupt edge for the INT0 and INT1. It is not required to set it each time. Also the interrupt routine look like:
    '************************************************* ********************
    INC_C: 'INTERRUPT SERVICE ROUTINE FOR EXTERNAL INTERRUPT-0
    '************************************************* ********************
    POSITION = POSITION + 1
    @ INT_RETURN

    '************************************************* ********************
    DEC_C: 'INTERRUPT SERVICE ROUTINE FOR EXTERNAL INTERRUPT-1
    '************************************************* ********************
    POSITION = POSITION - 1
    @ INT_RETURN

    That's all there is to it.
    Dave Purola,
    N8NTA
    EN82fn

  3. #83
    Join Date
    May 2013
    Location
    australia
    Posts
    1,086

    Default Re: decoding quadrature encoders

    When I added the mcu context save routine the display crashed. It will ~ work if I move the shaft slowly, however, moving quickly caused the code to trip over itself and lockup the screen.
    My first guess was that when jumping out of the ISR, the next return in the main program uses the most recent return address on the stack and returns to the point the interrupt occurred, crashing the program.
    I have not tried your code but can assure you that it is essential to save the mcu context upon isr entry and to restore it on exit . restoring the context without saving it can only lead to tears, not saving it can only lead to tears.

    so good luck with that


    dave
    the chip used here in this somewhat hijacked thread is a 16F876 it has only one "INT" pin your suggestion just cannot work in that case.
    afaik no pic16 chips can respond to rising and falling levels on an INT int pin simultaneously
    its one or the other. as henrik says to do a full quadrature decode every edge needs to cause an interrupt.
    RBC int can do it a single INT int cannot , the intx edge would need to be toggled on every interrupt .

    secondly that circuit with all its extra bits cannot use the full resolution of a encoder its a 1x decode.

    thirdly since the portb rbc pins on a 16F876 are schmidt trigger type inputs and if the chip is close enough to
    the re (opto type not mechanical)no other components are required at all to do a full 4x decode , why complicate it ?
    This is more entertaining than Free to Air TV

  4. #84
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,010

    Default Re: decoding quadrature encoders

    Excuse me Henrik, If you read the spec. sheet you can set the interrupt edge for the INT0 and INT1. It is not required to set it each time. Also the interrupt routine look like:
    Dave, I think you're misunderstanding what I'm saying.
    The circuit you linked to is x1 decoder, effectively provoding 1/4 of the encoders available resolution. Your simply counting the individual lines of the A and B channels respectively. If that's enough, perfect go right ahead but if you need the full resolution of the encoder (as is the case here) then it's not going to cut it.

    To use the full resolution of the encoder each and every edge of the two signals needs cause the counter the change up or down. If the encoder is connected directly to INT0 and INT1 it means that the edge causing the interrupt needs to changed on every interrupt so that it "catches" the falling edge after a rising edge etc. It's certainly doable if the PIC allows you to do it (not all do) but it does complicate things.

    By using interrupt on change this is handled automatically because ANY change on ANY pin causes an interrupt so you will "catch" every edge (rising AND falling) automatically and you just need to decode the gray code in the ISR. From any given state (there's only four) you can only get to two other (valid) states, one is forward the other is backwards.

    Look at this NI page on qudrature encoders, about half way down is a comparison of x1, x2 & x4 decoding.

    /Henrik.

  5. #85
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    988

    Default Re: decoding quadrature encoders

    Henrik and Richard, I understand what it is you are trying to accomplish. The problem becomes noise and the ability of the micro to intercept the interrupts. When you are trying to capture each and every edge in a mechanically noisy environment you will undoubtedly miss an edge or two. The key to properly designing an encoder into a mechanical design is the encoder resolution. Trying to get 4x the resolution from an encoder is indeed one way to fail if the encoder is of a higher resolution than is required. I have been designing encoders into mechanical fixtures for almost 40 years. I would rather have the processor executing code rather than constantly servicing interrupts in a mechanically noisy environment. It's just my way of thinking. Good luck...
    Dave Purola,
    N8NTA
    EN82fn

  6. #86
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,010

    Default Re: decoding quadrature encoders

    If you need a certain resolution and a certain speed then it's going to result in a certain number of "counts" per second (ie a certain number of interrupts per second) no matter if you're doing x1 or x4 decoding, won't it?

    The difference is that with the former you need an encoder with 4 times the number of cycles compared to the latter. As far as the number of interrupts that micro needs to service there's no difference.

    In this particular case we don't know what the speed is but we know that Chris needs (or wants) a resolution of the 0.25 degrees, which his 360CPR encoder will provide with x4 decoding. He could exchange his encoder for one with 1440CPR and do x1 decoding but given that the speed at which the enocder is being moved is the same there will be an equal number of "counts" per second. Doing the x4 decode in software is however a bit more complicated than x1, I'll give you that :-)

    As far as noise goes I don't see the difference in running a 360CPR encoder doing x4 decoding and running a 1440CPR encoder doing x1 decoding.

    And if using an external decoder circuit, like the one you linked to, there's no need for any interrupts at all, just have two counters count the up/down pulses and differentiate periodically.

    /Henrik.

  7. #87

    Default Re: decoding quadrature encoders

    Quote Originally Posted by cbrun17 View Post
    Thank you Richard. I will test this and let you know the results.

    Also, though the encoder is optical, I am going through a 74C14 hex Schmitt trigger with rc filtering to remove any stray noise. all cabling from the encoder is shielded. Monitoring the output results in clean square wave with fast rise and fall times.

    Chris
    Out of curiosity, what R/C values did you find to be optimal on your schmitt triggers?

    Picster

  8. #88

    Default Re: decoding quadrature encoders

    Quote Originally Posted by picster View Post
    Out of curiosity, what R/C values did you find to be optimal on your schmitt triggers?

    Picster
    Ok, I did some trials myself and ended up with R1=100k, R2=33k, C=0.1uF working well with Schmitt trigger inputs on the PIC I'm using (see circuit attached). That's with a detented encoder, using the same values for the two rotary outputs AND the built-in pushbutton.
    Name:  schmitt.jpg
Views: 19
Size:  11.2 KB

  9. #89
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,495

    Default Re: decoding quadrature encoders

    I would use 10th of this values.

    Ioannis

Similar Threads

  1. Quick thoughts: DT Ints with encoders
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 7th January 2010, 02:01
  2. PMDC SERVO MOTOR WITH quadrature encoder DRIVE ?
    By phoenix_1 in forum Schematics
    Replies: 37
    Last Post: - 22nd November 2009, 20:45
  3. 32-bit Quadrature Counter With Serial Interface
    By precision in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th June 2008, 02:49
  4. quad encoders
    By cpayne in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th March 2007, 18:49
  5. "momentary" IR decoding
    By sporker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th June 2005, 01:53

Members who have read this thread : 33

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