I need to measure the switching frequency of an open collector output. The waveform will be square shaped and the frequency range is specified as 0 to 5kHz. First of all I don't want to count pulses because I want to determine the duty cycle as well. So here comes my problem:
For this task I explicitly need to use an ATMega16 without any external circuitry (except crystal)
I know there is a pretty simple way of determine frequency and duty cycle, and I already did use this technique: hook the signal to an interrupt, combine it with an asynchronous timer, do a little bit of math and done!
Now this works pretty well with the 16 Bit timer module but not so great with one of the 8 Bit timers since those overflow much faster.
Now I'm curious if I can determine the accuracy of this technique beforehand, e.g without testing it out.
I know the frequency reading will mostly depend on the timers frequency: the higher, the better. An 8 Bit timer running at @ 2MHz (prescaler 2 ; from 16MHz) should give me a basic 0.5us per LSB resolution which looks pretty good on paper. Combined with a 16 Bit overflow register I theoretically could measure up to one second time period. But I know this won't work: updating the 16 Bit overflow register would take too much instructions in the ISR and effectively wreck my accuracy. So is there any way of getting reasonable accuracy (+-5%) from a single 8 Bit timer module in the specified frequency range (0...5kHz)?