How to read the counts from the encoders...?

hello,

We are using Arduino-Uno with Pololu DC high torque motors with encoders. How can we read the counts coming from the encoders using Arduino-Uno...? Is there any library that works more efficiently for getting counts.....? The encoder gives counts very fast. At full speed(80 RPM), the count-period is 170 microseconds. And at the half speed, the count-period is 220 microseconds. How can we get the counts so quickly....?

Please suggest any library(also suggest how to install the library) or any programs.....?

At full speed(80 RPM), the count-period is 170 microseconds. And at the half speed, the count-period is 220 microseconds.

There's something wrong with these values because at half speed the pulse period must be twice as long as for full speed.

There are several libraries and code samples for this area. Which one to use depends on your usage, needs and hardware. That reminds me: where are the links to the used hardware?

How can we get the counts so quickly....?

With an external interrupt this speed is absolutely no problem for an Arduino. Depending on your precision needs you may need one or both external interrupts for this.

Hello pylon,

Thanks for replying.

Can you suggest me any libraries or programs for simply counting the pulses using Arduino-Uno. I'm new to the arduino.

You can attach change interrupts to nearly any pin, and the arduino library gives you interrupt support for pins 2 and 3. 100us is no problem, but your CPU load will be a little high. Especially if it's a quadrature encoder (i.e. you need to decode two pins to discover direction of rotation) this is almost certainly what you need to do. Lots of examples of code out there that read a quadrature encode from pins 2+3.

If you just want to count pulses, hook the encoder to D5, which is the clock pin (T1) for Timer1. If you read the mega328 datasheet carefully, you can get the hardware timer to count pulses for you. However you have no guarantee that you will inspect the pulse count in your main code synchronously with its updates, so your frequency measurements will jitter. This approach is only good if you have a longish averaging period.

If you want to directly measure pulse period, hook the encoder to D8, which is the ICP1 input to Timer1. That will allow you to directly measure the period of the pulses using whatever frequency you program into Timer1. Again with the datasheet. I can post some C that does this if you like, but no guarantees that it will suit your problem.

avikhirsariya712:
Hello pylon,

Thanks for replying.

Can you suggest me any libraries or programs for simply counting the pulses using Arduino-Uno. I'm new to the arduino.

I repeat: Where is the link to the hardware used?

Link for the DC high torque motors with encoder........

In my calculation this motor gives you about 89┬Ás (60s/80rpm/8400ppr) pulse period time.

In the playground (Arduino Playground - RotaryEncoders) you can find many information (including libraries) to work with rotary encoders. Your motor seems to have a quadrature encoder, so you can use almost any information found on that page.