Getting speed using Pololu wheel encoders and AVR Library

I am using the complete wheel, motor, encoder kit from Pololu.

I have successfully used the AVR library to get the count of the encoder.

What I now need is to calculate the speed of rotation based on this count.

Where I am having problems is to determine time, this is mostly because I dont know a lot about interrupts.

I am using an arduino.

Si If I could determine the time the speed would simply be the number of “clicks” in a time period.

If anyone has any resources, code or examples I would greatly appreciate it!

Hello.

Can you just use the Arduino’s millis() function for your timing? For example, have your main loop check how many new encoder counts have occurred in the past 10 or 100 ms. Note that if your wheels are turning slowly enough, you might want to transition from measuring encoder counts in a fixed time period to the time between successive encoder edges.

Updating the speed in a timer interrupt will give you better accuracy, but that might not be necessary, especially if your main loop isn’t doing very much. If you want to see how to do a timer interrupt, you can look at the Arduino source code to see how millis() works.

- Ben