Earlier this year I decided to teach myself microcontroller programming. One of the reasons for this was the desire to understand and build a frequency counter based on these devices. There are several PIC counter designs available on the Internet all based on Microchip's Application Note AN592. These designs use the PIC's asynchronous counter pin with an internal 1:256 prescaler and two 1 byte registers to get a total of 3 bytes counting range. At the end of the gate period, the counter pin is toggled until it rolls over thus extracting the third byte of information. Examples include:
1. The Weeder frequency counter ported to the PIC16F84 chip by Peter Cousens. This counter is autoscaling and displays the frequency in Hz, kHz or MHz. It uses an external gate (74HC132) to control the input.
2. The OM3CPH (Peter Halicky) frequency counter. This is the simplest scheme using the fewest parts.
3. The JG6DFK/QRP frequency counter. This counter can be used with an external prescaler for very high frequency measurement and has switch selectable ranges. Beware that the source code is written in Akizuki assembler and will not assemble with MPASM without modification.
Although all these counters have their desirable features, I wanted to get the full 3 byte's worth of resolution out of the counter and read to single Hz. I chose to modify the Weeder counter because it had a nice autoscaling feature.
Here is what I did to modify this code to create FCOUNTER.ASM:
The original code was designed to give only 7 digits of resolution although the maximum 3 byte value (16,777,215) fills 8 digits. The Weeder/Cousens code simply read "overflow" when the count exceeded 10,000,000. To get the 8th digit, the code uses a full 1 second gate period on all ranges and first divides the count by 10,000,000 instead of 1,000,000. A 4th byte is used to carry any overflow. In that event, the gate period is reduced to 0.1 second and the display only reads to 10 Hz resolution. If the input frequency falls below 16,777,216 the gate period reverts again to 1 second.
The circuit is the same as that used by Weeder/Cousens except that the E and RS pins are reassigned so that E is driven from RA2 and RS is driven from RA0 (reverse of that shown in diagram). Please note that pin 9 of 74HC132 is also switched to RA0 (still on RS line). Readers should also be aware that there is an error in the circuit diagram posted by Cousens. The RB0-7 data pins should directly connect to their corresponding DB0-7 pins on the LCD display (not inverted as shown).
Other useful info:
"How to use intelligent L.C.D.s" Part 1 and "How to use intelligent L.C.D.s" Part 2.
Myke Predko discusses LCD displays.
Need a source for PICs? try:
Digi-Key or
Dr. Anderson also sells small quantities at bulk prices.
Here are some pictures of the finished product. Click on image for larger view:
October 2000