Shop OBEX P1 Docs P2 Docs Learn Events
Optical Quad Encoder, Problem of skipped steps — Parallax Forums

Optical Quad Encoder, Problem of skipped steps

Matthias09Matthias09 Posts: 47
edited 2009-08-10 16:14 in Accessories
Hi folks,

I use SX/B to read an optical encoder (US Digital, 360ppr, 2 channels, 1 indexchannel).

I use a port-based interrupt, that fires, whenever Channel A has a falling edge. Then I check channel B for high/low and depended on that count one degree up or down. The problem I have is, that the interrupt routine seems to skip steps. When moving the encoder axis to the left and right several times, and coming to the original position back, it never has the same reading (5-10 degrees difference). What can I do?

I think, my interrupt routine is too big, so it neglects following interrupts. However, outsourcing with Sub routines is not possible, reducing the routine also not, as I have to find the index channel first. My principal idea would be not only finding the reference point with the index channel initially, but everytime I bypass it and 'resetting' the current calculated angle value to the initial one.

My program is attached. It is part of a bigger program (hence the variable array), but works on its own.

Thanks guys! Thanks.

Matthias

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-08-10 01:20
    Your problem is due to not using the same edge to both increment and decrement. The proper way to do this is to switch the channel A edge that you trigger on whenever you get an interrupt. Then, assuming channel B is high when the interupt occurs, increment on a rising edge, and decrement on a falling edge. Otherwise, as you've discovered, you will accumulate errors when you change directions.

    -Phil
  • Matthias09Matthias09 Posts: 47
    edited 2009-08-10 14:39
    Phil,

    thanks for the thought. TO verify I got it right:
    Status quo: I only detect falling edge on Channel A
    Your idea: Detect both falling and rising edge on Channel A, and in order to do so, after e.g. having detected a rising edge, switch the edge detection mode to 'detect lower edge'(and vise versa).
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-08-10 16:14
    Yes, that's right. And only register a count +/- when the other channel is high.

    -Phil
Sign In or Register to comment.