Determining motor RPM using quadrature encoder and VHN5019 driver

Hello,

I have a query regarding determining the rpm of the dc motor using magnetic encoders. I am using a VHN5019 DC motor driver, 156:1 Metal Gearmotor 20Dx44L mm 6V, 93 RPM and 170 mA with no load, 110 oz-in (7.9 kg-cm) and 2.9 A at stall and Magnetic Encoder Pair Kit for 20D mm Metal Gearmotors, 20 CPR, 2.7-18V.
I am enclosing the photograph of the connections. The motor runs fine.


Although the motor runs fine, the rpm value doesn’t equate with the no-load rpm of 93 or closer. I am enclosing the serial monitor snapshot and the code.

Any help/thoughts would be greatly appreciated!

readencoderedit.ino (2.9 KB)

Hello.

It looks like the way your interrupt service routine is being handled, it will only count one tick when encoder A changes and not every time encoder B changes, which would result in your measurement being half of the actual speed. That seems to match up with your results (e.g. measuring 44 RPM when you expect around 93 RPM).

If you want to only use one interrupt and the resolution of your readings is not critical to your application, you might consider just changing the CPR in your code to 10. Otherwise, you might consider using an interrupt for each encoder channel or looking at other implementations used in the Arduino RotaryEncoderLibrary documentation as a reference.

Brandon

Hello Brandon,

Thanks for the input and the documentation reference, that sorted it out.

Vishal

1 Like