It is a pity not to make an easy
frequency counter as there are two timers/ counters on the
8051.
An interval of 50 milliseconds is obtained by programming Timer 0, eventually leading to gate times of 0.05 second and 0.5 second. By switching in a 10 times prescaler, an effective gate time of 0.01 second is also available. Timer 1 is set as a 16 bit counter, keeping track of negative transitions at P3.5. On the standard 8051 all timers count up.

The input buffer is not needed for TTL or 5V CMOS, but better leave it alone: As per its specification, it will withstand the output of 15 Volt CMOS. The selector is controlled by P3.4.
A minor problem is present in that the pulses counted are really supposed to be synchronised to the effective device clock of 921 KHz, (assuming the traditional 11.059MHz crystal). Adding a two times divider to the 131KHz and 921Khz range improves matters, as the output mark to space ratio is always one. The maximum operational frequency (including the prescaler) is 4.6 MHz. An essentially random count is recorded for higher frequencies, but the program guards against such readings in the following manner:
-
If the results from the 0.5 second and 0.05 second gate times are basically equal, the 0.5 second frequency is given (it is of higher resolution)
- Similarly, if the 0.05 and 0.01 readings are much in agreement, the 0.05 second result is shown
-
A second 0.01 measurement is otherwise taken and given if similar to the first. Else an overflow is indicated to the user
The site would like to point out that the timers' overflow flag must be cleared explicitly. Reading the flag or writing to the timer will not be any good. This was the first and only problem met in this project.
The resolution can be increased ten times in the 921KHz and 4.6MHz range by selecting a gate interval which is ten times longer. The number of overflow events is then recorded.
For the time being the results are sent serially to a PC, but an on board LCD could have been driven equally well.
Here is the
source code and
executable files for this project.
It has not been mentioned in the
89S8252 page that the reset capacitor needs to be
tantalum, or the board remains in a state of perpetual initialisation. This seems to be unclear in the original article.
The 7401 is an unusual choice for a selector, but the site was at the countryside during construction. Pull up resistors of 4.7k are added to open collector outputs, to prevent the design from becoming marginal. A 100nF ceramic capacitor is soldered directly across the supply pins of the counter.
In last month's sweep generator page, it seems that an old version of the sweep program has crept. This will be corrected soon.
There are some errors in the finite element programs, though they don't really make a difference to the results. They will be corrected by the time the next computational electromagnetics page has appeared.
For my own code: Valid XHTML 1.0!