I have to read 5 different frequencies(square wave) up to 20KHz by polling 5 different pins. Im using a single timer interrupt only,for every 1 millisecond. Polling of the pins would be done in the ISR.
The algorithm i have thought of so far is: 1.Count number of HIGH 2.Count number of LOW 3.Check if sum of HIGH+LOW=Time period. This algorithm seems slow and is not practical.
Is there any Filter functions that i could use to check the frequency at pin so that all i have to do would be to call that function? Any other algorithms, for frequency detection would be good.
I am restricted to only 1 interrupt in my code(timer interrupt)
you need to take in mind what are the input signal properties
speed
I would code it with your constrains like this (it is just C++ pseudo code not using your platform):
s[]
p0=p1; p1=get_pin_state(i); if ((p1)&&(p0!=p1)) { T[i]=t[i]; t[i]=0; }
How would I do this without your odd constraints?
s
orHz
if needed[notes]