An ATtiny2313 Frequency meter |
![]() |
Written by Vladimir Mitrović |
The input signal should be TTL or CMOS compatible, with an amplitude of at least 2 Vpp. Diodes D1 and D2 limit the input voltage if its amplitude exceeds 5 Vpp. S2 is used as a display-hold button. How we can measure high frequenciesWe can measure high frequencies by counting input pulses within a precisely-defined time interval. In its simplest form, it can be done as shown in this example: Counter1 = 0
Config Timer1 = Counter , Edge = Falling
Wait 1
Stop Timer1
The 16-bit Timer/Counter1 is configured as a counter, counting pulses on the T1 input pin. The counting starts as soon as the counter has been configured and stops after 1 second. If the initial value in the Counter1 register is 0, as is the case here, its value after one second will match the frequency of input pulses. Very simple indeed, but such a simple program has two limitations:
Therefore, an assembler routine has been written which lasts exactly one second. Apart from being accurate, this routine also counts the number of Counter1 overflows. The final result is a 32-bit number and is accurate to +/-1 digit: frequency = number_of_overflows * 65536 +
Counter1
The highest frequency that could be measured as described above is 232, i.e. about 4 GHz. Such a high frequency cannot be measured with this microcontroller. With a 20 MHz crystal, the microcontroller can measure frequencies up to 10 MHz. It should be noted that the microcontroller itself cannot accurately measure frequencies that are beyond the upper frequency limit. For example, a frequency of 10.2 MHz will be measured as 9.8 MHz. This error is caused by the way the microcontroller detects level changes at the input pin and it cannot be detected by software. An ATtiny2313 Frequency meter ![]() Shop area |
Last Updated on Tuesday, 04 June 2013 13:37 |