Encoder library missing pulses

Status
Not open for further replies.
I guess I was mainly wondering whether in some circumstances, encoder jitter (as described on pg 811 of the MK20DX128 manual) might affect the accuracy of the encoder library count, even if the code is working as intended - as I think you've clearly demonstrated. In other implementations of quadrature decoders, I've usually seen some kind of input filtering (eg. the digital filter on pg 750, or the RC filter used in the Microchip app note). It wasn't entirely clear to me whether this jitter would just be reflected as a fluctuation in the count, or whether it would actually cause a mis-count, i.e., to lose the actual position.
I've tested a few thousand direction reversals with my Avago optical encoder (brushed motor) and haven't had mis-counts (the encoder has an extra index channel, so it's easy to verify).

From what I understand about the Cortex M3/M4 interrupt system, you will get an interrupt for both pulse edges, even for an extremely short pulse (too short for the interrupt to finish processing the first edge). So unless you have noise on encoder channels A and B at the same time, there shouldn't be any count error (the short pulse will simply be an up/down fluctuation in the count).

So, if you get a reasonably clean signal to the Teensy, you should be just fine.

@Will: I think at this point it's quite clear that your hardware setup is screwed up. Looking at Pauls video, the AMT encoder puts out a very clean signal and the T3 can definitely count correctly.

Brushed motors can generate huge amounts of noise. You should get out a scope to see what's going on with your setup.
 
Paul, having carefully and conclusively demonstrated that the encoder library is correct, at least you now have a testbed for library regression testing!
 
Yup. I build test hardware for most widely used Arduino libraries.

I actually have a big box of parts, displays and breakout boards for another few dozen libraries, just waiting to be built up and tested.... and documented. If only there were more hours in each day......
 
Sorry for bringing up this old thread.

I am trying to replicate your test project after finding it on youtube.

I am using two arduion unos and a nema17 4-wire bipolar motor connected to a HY-DIV268N driver.

The only thing that is the same is the encoder and the code you wrote, with some modification of the motor wire setup, where i use accelstepper 2-wire config with 1 puls and 1 dir output.

And on the other uno i use the basic example and connect the encoder to pin 2,3 the interrupt pins, and it works but not as good as your test.

And just to make things clear, i thoght at the beginning that you used the encoder to compensate the motor, but as i have figured out reading this thread i've come to the conclusion that you dont. So how the *** can you make it compensate? :)

I actually want to use the encoder to calculate if the motor is overshooting or lagging due to obstacles or weight forcing the motor to miss or add steps, and then correct it.

How would you implement that functionality in this example using the accelstepper library?

Thanks for all the help so far :)
 
Status
Not open for further replies.
Back
Top