# Determining optical rotary encoder RPM

I hope the first part of this question isn't too physics based for this forum but I am trying to use an optical rotary mask encoder such as this one (Optical Encoder Pair Kit) to determine the RPM of a brushless 1:50 geared DC motor. The website above mentions that the package comes with 3 or 5 teeth wheels which correspond to 12 and 20 counts per revolution respectively and that for a geared motor you should multiply by the gearing ratio. I want to use the 5 tooth wheel to get the maximum resolution but I do not understand why using a 5 tooth wheel will give 20 counts per revolution. Why not 5, does it have something to do with there being 2 channels on the output?

To determine the RPM I am thinking that I will have to setup an interrupt in my microcontroller to add 1 to a variable (call it pulse counter) everytime the photodiode on the encoder spikes, then increment a revolutions variable when the pulse counter and the calculated number of counts per revolution correspond and then have a timer on an interrupt which will check the number in the revolutions variable, divide by 60 and output the result as an RPM value.

Is this a valid approach or is there a better way to do this?

Each tooth changes the state of the sensor twice when it passes over. 5-tooth wheel will do it 5x2 = 10 times. There are two sensors on board, so altogether you have 10x2 = 20 output transitions per revolution. They call it CPR.

If you look at single channel you will see 5 pulses per revolution, or PPR. The CPR = 4xPPR.

I want to use the 5 tooth wheel to get the maximum resolution

For high speed motors there is no practical difference in RPM resolution between 3 and 5-tooth wheels. It only affects how fast you have to count pulses. So, if you have fast motor and slow microcontroller it makes sense to use 3-tooth.

Of course, if you planning to control motor speed with your microcontroller and the slowest possible speed goes down to, say 30 RPM then 5-tooth will be more precise for momentary speed measurements. However, as you continue counting and adjusting the calculated value the difference will again be negligible.

The formula 6000 / (RPM x CPP x Tsec) gives you theoretical precision for given sampling period Tsec. For example at 30,000 RPM and 1 second sampling time the precision of 3-tooth wheel is 0.017%, while for 5-tooth it is 0.01%.

• yes, for the 5 tooth wheel the correct angular offset (for 90 degrees phase offset) is 36 or106, or 180 degrees. for three teeth 60 or 180 but those sensors are at 90 degrees :( – Jasen Jul 22 '18 at 9:42
• @Jasen I guess it is the case of "you get what you paid for". The description implies the speeds in 30,000 RPM range, however. For these speeds the teeth and offset are pretty much irrelevant. – Maple Jul 22 '18 at 18:10
• I gave the wrong numbers above. correction: for 3 teeth (edges are separated by 60 degrees) the angle between sensors should be 30, 90, or 150 degrees. for 5 teeth (edges every 36 degrees) optimum angular separation is 18, 54,90,116, or 152 degrees, so both wheels give balanced phasing with that sensor board. – Jasen Jul 22 '18 at 22:03
• @Jasen It does not matter. I just did the same calculations and indeed, with sensors at 90 deg both 3 and 5 will give correct phase offset. But then I downloaded PCB photo and measured actual angles. Depending on which part is the focal point of that sensor I got 60, 85 and 105 degrees. 85 is close, but no cigar. – Maple Jul 22 '18 at 22:18
• Also, consider this: at 30,000 RPM and sampling period 1 sec the difference in precision of 3 and 5 wheels is about 0.007%. – Maple Jul 22 '18 at 22:30

Here visualization shows why there will be more counts per revolution than number of tooth - https://www.youtube.com/watch?v=v4BbSzJ-hz4&feature=youtu.be&t=61

And here is a video series on how to make DIY encoder whith explanations on how it works - https://www.youtube.com/watch?v=dPBKTZw_xi4

Hope this helps