I would like to measure the frequency of an external digital input with the Zx328n.
My range is 100 Hz to 1 MHz.
I want it to be as accurate as possible.
The accuracy is the number one requirement.
If a small number of external chips are necessary, that would be ok.
If 'C' or asm needs to be written, that would be ok too.
I have searched the forum, and have not found what i need.
Can any one help with this?
Thank you
Richard
frequency counter
Re: frequency counter
Probably the simplest way to do this would be to use InputCaptureEx(). The tricky part will be selecting the clock rate that will work over the range you've indicated.rich wrote:I would like to measure the frequency of an external digital input with the Zx328n. My range is 100 Hz to 1 MHz.d
An alternate strategy would be to use the signal that you intend to measure as the external clock source for the 16-bit timer and then let the timer run for a fixed period of time. Given the accumulated timer count and the known time period you can calculate the frequency. With this strategy you would want to let the timer run for a small enough time such that the 16-bit count doesn't overflow at the highest frequency you expect but which is also large enough to get a large enough count to get the desired accuracy with the lowest frequency you intend to measure. This may be difficult to attain given that you have specified four orders of magnitude of range. It may be necessary to make the measurement using a multi-step process with diminishing accumulation duration until the timer doesn't overflow.
- Don Kinzer
T0 is the external clock input for Timer0. T1 is the external clock input for Timer1. T2 is the external clock input for Timer2. Timer1 is the 16-bit timer while the other two are 8-bit.rich wrote:I have not checked but if the 'T0' for 'T1' pins go to a 16 bit counter[...]
On the mega328P, D.5 is T1.
To time the duration of the frequency measurement, you may be able to use the GetElapsedMicroTime() routine. If that doesn't give you sufficient accuracy you may need to use Timer2 and a special interrupt service routine.
- Don Kinzer