Rotary decoder chip

by georduino on Fri Oct 04, 2013 12:44 pm

Hi,
I have been using an Arduino Uno with the Adafruit Motor shield to control a DC servo motor. This package works great for controlling the motor, but I am having a hard time reading the encoder of the motor at high speeds. At full speed the encoder can output 100K counts per sec which according to my understanding from reading several posts on this and other forums is beyond the capabilities of arduino. I was wondering if there is a hardware solution to this problem i.e. a rotary decoder chip that is supported by adafruit or is easy enough for a beginner like me to interface with arduino

Thank you!
georduino
 
Posts: 3
Joined: Fri Oct 04, 2013 12:16 pm

Re: Rotary decoder chip

by adafruit_support_mike on Sat Oct 05, 2013 12:25 am

Hmm.. what kind of encoder are you using?

Reading the feedback from our analog-feedback servos (http://www.adafruit.com/products/1404) does have some limits on the number of samples you can read per second.. the built-in ADC normally runs at about 10kHz, which only allows you to sample repeating signals below 5kHz accurately. You can get up to a few hundred thousand samples per second if you're willing to live with less than the full 10 bits of accuracy though.

OTOH, when you say your encoder can put out 100k signals per second, that sounds like a digital device. It isn't exactly easy for an 8MHz processor to handle an 8kHz signal and do other things as well, but it's possible.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 7073
Joined: Thu Feb 11, 2010 1:51 pm

Re: Rotary decoder chip

by georduino on Tue Oct 08, 2013 10:53 am

Hi Mike,

Thank you for your reply. the motor that I am trying to control is this: http://www.thorlabs.com/thorcat/17600/Z812-Manual.pdf

My understanding is that the encoder is a digital device that will output about 90K counts/sec per channel at full speed. I think that the clock speed of the Arduino Uno we have is at 16 MHz.

Thank you!
georduino
 
Posts: 3
Joined: Fri Oct 04, 2013 12:16 pm

Re: Rotary decoder chip

by adafruit_support_mike on Tue Oct 08, 2013 2:28 pm

The product isn't one of ours, and the datasheet doesn't completely characterize the encoders, so take this as an educated guess:

The datasheet shows two encoder channels and mentions a Hall effect sensor, so I'm going to assume the signals are digital and run in quadrature.. signal A goes HIGH before signal B if the shaft is rotating clockwise, B arrives before A if the shaft is rotating counterclockwise. That's a standard motor sensing approach.

If those guesses are correct, you don't need to use the ADC at all. You just need to count digital pulses coming from the A and B lines, and 90kHz won't push the limits of an 8MHz or 16MHz microcontroller.

The usual solution would be to set up interrupts for two pins so they can sense when the A and B lines go HIGH or LOW. Each pin's interrupt handler would find the state of the signal it observes, then store that information to a global variable you can use in the rest of your code.

The motor's direction and speed can be derived from the quadrature signal, and from those you can calcualate displacement from an originally recorded position. The details of how much work to do in the interrupt handlers and how much to do in the main code will depend on the requirements of your application in general.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 7073
Joined: Thu Feb 11, 2010 1:51 pm

Re: Rotary decoder chip

by georduino on Thu Oct 10, 2013 1:16 pm

Thank you Mike!

I will give it a try!
georduino
 
Posts: 3
Joined: Fri Oct 04, 2013 12:16 pm