Engineer In Wonderland

Tribulations of using 1/duration to measure frequency

I have a sub-project – to measure rpm using a disc with 48 slots.

This is part of the cnc lathe project, and as it is for speed control the display needs to update three to four times a second.

If it could update every 1.25s, the answer would be easy: simply count input pulses for that time to get an rpm number as the 1.25s takes care of 48 slots and the x60 for Hz to rpm conversion.


However, this is longer than a third of a second.


Head scratching for a few hours over a few days came up with reciprocal counting, but not a good method to decide how many slots of the 48 to count for best resolution at different speeds.

Looking up ‘reciprocal counting’ caused a ‘why didn’t I think of that’ moment:
For 0.33s, count all slots passing and (separately) a reference clock, then divide one count by the other.

Doh

Synchronising the slot counting with reference counting makes it better – count the reference only for the part of the 0.33s duration which whole input cycles occur.

I think the equation is:

input freq = 1/(period of input) = (number of input cycles)x(reference frequency)/(number of reference cycles)

Then rpm = freq x 60/48 to allow for the slotted disc

As the input is pretty slow (4.8kHz max), this pulse stream can be used to interrupt an Arduino.

The interrupt service routine can keep a rolling interrupt count, plus store the timing of the latest interrupt using micros(), so that the main line program can pull these numbers out each display cycle (via a double buffer), compare them with the previous display cycle, and make the necessary division.

Now to find time to implement it…

Steve Bush

Steve Bush is the long-standing technology editor for Electronics Weekly, covering electronics developments for more than 25 years. He has a particular interest in the Power and Embedded areas of the industry. He also writes for the Engineer In Wonderland blog, covering 3D printing, CNC machines and miscellaneous other engineering matters.

Leave a Reply

Your email address will not be published. Required fields are marked *

*