First of all, I would like to apologize in advance. I have sort of asked this question a few different ways. But since that first question, I have managed to get a little more up to speed and I think I can finally ask an intelligent, useful question to finally resolve this.
You see, I have an application where I need to detect 9 different tones and then act on those tones. The tones are 5V TTL level already, so no analog hardware is needed.
At first I was trying to trying to measure the frequency of the tones and asked questions because I was having a lot of trouble getting a stable reading. Then once I got a stable method, I was asking about how to put the routine into an interrupt (while dealing with noise rejection). I got all very good answers from others, but in the end what I thought I wanted is not really what I needed.
So, the 9 tones are 200HZ apart. They are all divisible by 200. (1400, 1600, 1800, etc...) So while experimenting with various methods it dawned on me that what I really wanted was to set up a hardware counter with a 5ms gate and count the number of times it overflows. This would give me 7 for 1400Hz, 8 for 1600Hz, etc...
The Freqcount library is doing exactly that. If I set the gate length to 5ms, I get a number like 7, 8,9, etc... and it even allows for the tones not being exact. This is just what I want.
Now, why I am asking yet another question:
The freqcount library has alot of features and overhead because it is intended for counting frequency. I also need to add some features into the concept to completely support what I am trying to do in my application. I already know the exact frequencies I want to detect and I already know that they will be exactly 200HZ apart.
I am also afraid of breaking the library trying to add my own parts to it because I definitely do not understand counters enough to know how to not break it.
I have a feeling that what I want to accomplish can be done in a dozen or so lines of code if I understood the hardware counter a bit more.
What I want to do:
- Set up the hardware counter to overflow every 5ms and generate an interrupt each time it overflows.
- In the interrupt, I want to keep a count of the number of times that it overflows.
- I do not currently need any PWM in my application, but would like to disturb the Arduino core as little as possible.
I have been trying to read different tutorials on the counters to understand how they work, but nothing seems to be clicking for me enough to implement the above.
I am not asking for hand-holding here, but if someone could point me to some great tutorials in the hardware timers (specifically in external counter mode) that have an application close to what I am trying above, I would be really appreciative.
Or, if someone would be gracious enough to show me some code to do the above and be kind enough to help me understand it, you would be my hero.
It seems like what I am looking to do is an abuse of the counters, because I can't seem to find any tutorials or examples that fit just right.
It could even be that I am not using the right terms.