Rotary encoders

I have some micro metal gear motors I've soldered Pololu 3.3V optical rotary encoders onto micro metal gear motors. These have a direct analog output. I thought from a quick read of the instructions they might be tuned to work on digital inputs. If you read all the way to the bottom it suggests using comparators.

That's going to be a pain, because what you compare to is going to have to be adjustable. I can't get anywhere near the output voltage Pololu claim, and the two signals have quite different voltages on the one I've experimented with so far.

A rotary encoder generates two signals. Going forward, one signal will be 90 degrees forward of the other, and going in reverse, the opposite.

The rising edge of one signal can be used to trigger a capture of the other signal which can be used to determine the direction.

The capture needs to happen within 1/8th of the period of the encoder signal to be reliable. The motor could run up to 30K RPM, The encoders have 3 arms or 5 arms, I think this means the signal is 3x or 5x the frequency of the motor. This is (30K/60)*5 = 2.5KHz, so the period is 400us.

For better or worse, I've tried this using MBED in the first instance, using an STM32F303K8 Nucleo board.

400us/8 = 50us. I need to sample every 50us in order to be within 1/8th of the zero crossing. When I detect that, I sample the other channel.

MBED only offers one way of sampling - which is ask for a sample and wait until it's done, but the STM32F303K8 can complete a sample in 0.2us! Even if mbed is insanely inefficient, I should be able to do this without any additional hardware: I can use the ADC and signal processing.

The hardware could just sample both channels on a schedule, and interrupt the application on completion. If I used Chibios I could easily do this, however I'm wasting < 1% of the CPU doing it synchronously. On a board with slower ADC (and most are much slower than this) this could be a good idea.

The code could also be auto zeroing: just by tracking the minimum and maximum of the output signal and averaging the two. This means you don't need to use an oscilloscope to measure the signals and get things working. That's TBD.

Here's some code.



Popular posts from this blog

3D Printer ramblings

Balance Bot V2

Robot arm