I’m looking for a frequency counter library to measure the speed of a 3 wire fan. After testing a fan, it seems that the frequency output from the tachometer pin is twice the frequency of the rotations. i.e.
fan frequency = tachometer frequency / 2
So to read a fan speed of 3000 RPM you need to read a frequency of at least a 100Hz square wave.
Have any frequency counting libraries been ported to the spark core yet?
@waspinator, if duty cycle is not important (which it is not in your application), you can count the pulses on a pin using an interrupt (rising or falling edge only). Then, using SparkIntervalTimer, create a timer that fires off an interrupt every second or fraction thereof. At every timer interrupt, you take the pulse count and reset it for the next cycle. If the timer is set to 1 second, then the number of pulses represents your rotations per second or RPS which, when divided by 60 is revolutions per minute or RPM. If your rotation is very slow, then you can increase the timer interval accordingly.
I am not sure how you measured the frequency of the “tachometer pin” but if you were measuring both rising and falling edges of the signal, the “frequency” would be double since every period of the signal has a rising and falling edge. If you need help putting this together, let me know.
I like that FreqPeriodCounter library because it has debouncing built in. With interrupts, you have to implement your own debouncing code, add an external debouncing RC filter, or just get lucky with a signal that doesn’t bounce. Things to keep in mind
Okay, I got it to read RPM readings with the code below. You have to connect the power supply ground pin to the Spark Core and pull the tachometer pin on the fan high through a 10k resistor before connecting it to pin D4. It works with both 3.3V and 5V levels. (not all pins support 5V though, but D4 does)
I had to divide the frequency by two as I speculated earlier. I tried running the interrupt on RISING to avoid it, but then I could never get counter.ready() to equal true.
Hello!
I’d like to use freqCount.h in my project, but I can’t understand how to include it in my project in a private way (this library is not in the community libraries and I have not understand how to use them in a project)
Could you please help me?
Thank you!
@ScruffR already answered in another thread, but including non-community libraries in the Web IDE simply requires a few cut and paste operations. Open web IDE and recall whatever project you are working on. Create a new tab (click the “+” in the top right corner) and name the tabs: “FreqPeriodCounter.cpp” and “FreqPeriodCounter.h”. Go to @peekay123 's Github repository and copy the contents of each of those files and then paste them into your newly created tabs. Done.
Sorry! I've read this thread after a while and seemed to be more appropriate.
Thank you. I had some problems in saving firmware acting like that but I'll try with this library too. Have you already used this library with particle photon? Does it fit with photon hardware?
Thank you!
I just compiled the example from the githup repo and it compiled without error. Here’s a shared app of the example. There must be something else in your code causing the issue. Posting the raw errors would help identify what the issue is. Posting your code or a shared link is also preferable.