How I measure frequency on pin? Pls sample code. I have measure frequency 200Hz - 800Hz.
Pls help me
How I measure frequency on pin? Pls sample code. I have measure frequency 200Hz - 800Hz.
Pls help me
stafil - what approach have you tried?
How accurate and precise do you need? Is digitalRead
'ing the status of a pin and timing using micros
good enough?
stafil - additional information to gbulmer's question...
If your signal is below the level at which you can set an interrupt using a GPIO pin (or if you don't know what level it will arrive at, or you are dealing with a 'complex' waveform) then you may need to use an ADC and this means you'll need to do some signal processing work.
Based on what you've said then in a noiseless environment you would (theoretically) need to sample over a window of ~10 ms at a rate > 1600 Hz to get a good result and then apply a DFT to get the information that you require. The DFT part is not too onerous, there are various code examples and libraries out there on the web. For example, http://sourceforge.net/projects/kissfft/ (caveat: this was the first link I found on Google for 'embedded fft library', and may or may not be compatible with the Maple, I don't know, I've never tried it!)
But of course we must (usually) deal with noise so I'd suggest sampling at 6400 Hz and a window of 10 ms to get a nice, 'power of two' number of samples within the window, pad this up with zeros to a total length of 128 samples and do any required filtering to minimise noise prior to the DFT. If you need help designing a filter then I can recommend this: http://www-users.cs.york.ac.uk/~fisher/mkfilter/ (it's saved me a lot of work in the past!)
If you have a lot of noise, a known signal frequency and just want to check for the presence of the signal then you could even use a software-PLL or the cross-correlation of the sampled data with 'specimen' data and make a judgement based on their output as to whether the signal is present. (But these are probably massive overkill!)
Final thought (after a brief re-read of my DSP notes), if you need to detect a number of tones (fixed frequencies) in the range then you could also use the Goertzel algorithm, this provides a lower computational load. There's a nice article over at embedded.com on the use of this along with a code listing: http://www.embedded.com/design/configurable-systems/4024443/The-Goertzel-Algorithm
You must log in to post.