Rotary Encoder to measure velocity

Hello Arduino folks

I’m writing my bachelor in mechanical engineering, and I’m building a test bed for measuring impact forces and energy absorbing abilities. It this process, I have to measure angular velocity of a part and to do so I have chosen a rotary encoder together with an Arduino mega 2560. The problem is just; I’m totally new at programming, and don’t got the time to “fully” understand the coding language. My question is. Do you know where I can find an already complete code for measuring angular velocity? Which I can use to get inspiration from? The encoder is an old Leine & Linde AB, with 500 ppr, and runs on 24V (I have used voltage regulators to get an input on 5V). The velocity won’t exceed 5 rad^-1. I have tried some of the codes from the “get started”, and they all work nicely, expect that it seems the Arduino cannot keep up with the impulses it gets from the encoder, could this be the case? Do any of you happen to have a code that works for something like this? If would be much appreciated.

Best regards Mads Larsen

I think that you will be very lucky to find any ready made code to meet your requirements. You have obviously tried to read from the encoder. Please post an example of the program that you tried that caused you to conclude that the Arduino could not keep up with the impulses from the encoder. A circuit diagram would also be helpful in understanding what you are doing and how.

What do the figures that you quote relate to in respect of the maximum number of pulses to be read in a period and/or the minimum time between pulses ?

I find these statements incompatible:

I’m writing my bachelor in mechanical engineering

I’m totally new at programming, and don’t got the time to “fully” understand the coding language.

I find it difficult to believe that you've gotten through 4 years of an engineering degree without learning programming. A sad state. Good luck getting a job without being able to make a computer do what YOU want it to do. Or your employer wants it do to.

Perhaps you missed the word "mechanical" there? They do program, but its in Gcode... ;)

Perhaps you missed the word "mechanical" there?

No, I didn't. I have a BSME, from the University of Maryland, so I know what is involved in getting the degree. By the end of my freshman year, I was a relatively capable programmer. The date on my degree is 1979, when computers were far less prevalent than they are today.

On the electrical side:

The encoder is an old Leine & Linde AB, with 500 ppr, and runs on 24V (I have used voltage regulators to get an input on 5V).

Using voltage regulators for signal voltage translation is not the proper method and is bound to cause problems. You should rather use resistor voltage divider networks or purpose designed voltage translation ICs. Perhaps a schematic drawing of what you have and a link to your encoder datasheet would be helpful to get you something that can be made to work.

500 ppr is fairly high resolution and you certainly don't need that to determine angular velocity. You might look for 5 volt encoders with much lower resolution as those will put less load on the CPU. If timing one revolution of the object would suffice, you could also make your own 1 ppr (or more) encoder with a reflective optical or magnetic sensor.