Is that 1 count error repeatable. That is, do you see if every single time it rotates 10 revs? Is it cumulative, does it increase for every 10revs back and forth?
So, the only real way for the software encoder to fail would be signals happening to quickly for the interrupts to respond, right? (I think).
If you zoom right into the rising and falling edges of the encoder, ns/div type timescales, do you see any glitches or signal bounces on the rising or falling edges. I often see them on falling edges, but it's possible on rising edges too.
Sort of. What I am seeing is statistical. I have never seen the HW encoder deviate. However, I get some 0's and some 1's for counts with the SW. I've done 100 revs and back, most of the time it's 0, but sometimes not. I've done 10 revs fwd and 11 revs back, all kinds of tests and I don't get any definitive results. It's not bad enough to say it's always off.
This is with no USB Serial active during runtime. No other interrupts are enabled. I'm not using any interrupts, save for what may be in each library.
What's frustrating, and more than a little irritating, is the huge difference in how the two encoders work. The HW seems to be initialized in some sort of way that is reporting the same count, if I go 11T fwd and 10T rev. (I never pass the encoder wheel resolution, how could it know?) But the SW enc reports the difference in counts which is one revolution plus minus error.
I'd like them to report the same way, but both libraries are a bit opaque. That's a fancy way of saying both are NOT WELL DOCUMENTED. There's a dearth of examples, save for the trivial cases.
I'm going to write a better program. It will do the test say 10 times and report on the deviation for each trial.
I see no evidence of glitches on either rising or falling edges, not over 1000's of edges.
Here's 4 runs, using HWenc, and SWenc.
Code:
Using HW encoder
Initial position = 65536
Number of revolutions before reversal = 10.000000, 11.000000
IRQ_TEMPERATURE_PANIC = 0
IRQ_USB1 = 128
IRQ_ENC1 = 32
Final position = 65536
Error position = 0
Error position = -4096.000000
Using HW encoder
Initial position = 65536
Number of revolutions before reversal = 10.000000, 11.000000
IRQ_TEMPERATURE_PANIC = 0
IRQ_USB1 = 128
IRQ_ENC1 = 32
Final position = 65536
Error position = 0
Error position = -4096.000000
Using HW encoder
Initial position = 65536
Number of revolutions before reversal = 10.000000, 11.000000
IRQ_TEMPERATURE_PANIC = 0
IRQ_USB1 = 128
IRQ_ENC1 = 32
Final position = 65536
Error position = 0
Error position = -4096.000000
Using HW encoder
Initial position = 65536
Number of revolutions before reversal = 10.000000, 11.000000
IRQ_TEMPERATURE_PANIC = 0
IRQ_USB1 = 128
IRQ_ENC1 = 32
Final position = 65536
Error position = 0
Error position = -4096.000000
Using SW encoder
Initial position = 65536
Number of revolutions before reversal = 10.000000, 11.000000
IRQ_TEMPERATURE_PANIC = 0
IRQ_USB1 = 128
IRQ_GPIO6789 = 32
Final position = 69633
Diff, final-init = 4097
Error position = 1.000000
Using SW encoder
Initial position = 65536
Number of revolutions before reversal = 10.000000, 11.000000
IRQ_TEMPERATURE_PANIC = 0
IRQ_USB1 = 128
IRQ_GPIO6789 = 32
Final position = 69631
Diff, final-init = 4095
Error position = -1.000000
Using SW encoder
Initial position = 65536
Number of revolutions before reversal = 10.000000, 11.000000
IRQ_TEMPERATURE_PANIC = 0
IRQ_USB1 = 128
IRQ_GPIO6789 = 32
Final position = 69633
Diff, final-init = 4097
Error position = 1.000000
Using SW encoder
Initial position = 65536
Number of revolutions before reversal = 10.000000, 11.000000
IRQ_TEMPERATURE_PANIC = 0
IRQ_USB1 = 128
IRQ_GPIO6789 = 32
Final position = 69634
Diff, final-init = 4098
Error position = 2.000000
Same IRQ priority. Count mode is different. One is the reverse of the other. SWenc is occasionally off. This is driving me nuts. Encoders are on the same pins. +/-1 is ok, I guess, not +2. But missing a full rotation on the HW? How does it know what a rotation is? I never passed that information to it? A (unlucky) coincidence?