[Paul] has been working on porting over Arduino libraries for use with the Teensy microcontroller platform. This tends to be pretty simple since they both use the same Atmel chip architecture. But once in a while he finds the Arduino libraries are not what they’re cracked up to be. When looking to port over a frequency measurement library he ended up writing his own that works better and is much more portable.
He had two big beefs with the Arduino Frequency Counter Library. The first is that it required the compensation factor the be calibrated using an accurate frequency counter. That’s a chick-and-egg problem since many people who build a frequency counter with an Arduino are doing so because they don’t already have a standalone tool. The second problem is that the Arduino library was hardcoded for ATmega168 or ATmega328 chips.
This new library fixes both issues with just one trade-off. Your hardware setup must be using a crystal oscillator. You can see above in the image above that the frequency measurement is quite accurate with this method. The package also uses a thin abstraction layer which will make it easy to port to any 8-bit microcontroller which is programmed in C.