Optical Quad Encoder, Problem of skipped steps
Matthias09
Posts: 47
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
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
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