I want to make an auto-ranging frequency meter to measure the frequency from Hz to some MHz but the circuit could no exceed KHz and above some KHz it become very slow to give the value and the the values it gives are not stable.
And again I'm confused on how to protect the aduino against over-voltage with Zener diode,how should i connect the Zener diode ?
Below is the circuit and the code that i used for this project:
you used no </> button to insert the code. but I can see you utilize many FLOAT variable. that is bad. And I think you not need second PulseIn() - time between two raising flank is that what you want, right?
[Over-voltage protection]u[/u] (I recommend increasing the current-limiting resistor to at least 10K, depending on the driving circuit.)
The documentation says pulseIn() works between 10uS and 3 minutes. So high for 10us and low for 10us is 20us or 50kHz.
And... I'm going to guess that processing the instructions takes some tome so you might not be able process two pulseIn() instructions in a row without extra time in-between.
Consider using an internal counter/timer and an external prescaler such as a divide by 10 (keeps the math simple) ic such as the 4017. Using a 27K resistor in series with the 4017 will give you a lot of protection. If you need it sensitive you can use a fast comparator in front of it.
Clearly expecting the meter to give you readings in MHz without an external circuit is unrealistic. It SHOULD work in principle to give reaings up to around 50kHz.
So can you be a bit more precise about the "some" kHz?
Also be aware your frequency meter will only give correct readings for a rectangular wave that exceeds the Vih and Vil for the input pin.
I guess I am getting old, 20KHz was considered the top frequency some humans could hear. You must have a very expensive audio amp and speakers to achieve that frequency. What are you using?