Panteltje's freq_pic page

Panteltje's freq_pic page


Here you find the asm source code for a Microchip PIC 16F648A program to measure frequency, and display it via the PC RS232 serial port.
It also works with my USB to RS232 adaptors.
I found a nice auto ranging frequency counter online here:
Did not have those 7 segment displays, considered a LCD interface, but why not use RS232, and power it from the RS232 too?
Just a probe you can bring along with your laptop, saves weight :-)
So.. modified that code a bit:-)
This is what the output looks like when it is measuring it's own crystal (20MHz):

This is how simple it is, only 7 components:

A more clear diagram, with thanks to Nick Pyner:

Build it into a metal D connector shell, used a phono stereo plug and used the dremel to make it pointy:

This is the modified asm source for a PIC 16F648A:
Click here to download counter-0.3.asm
This source was assembled with gpasm-0.13.5 beta, may not work with mplab.
Resolution of this version is 1 kHz on the MHz range, and 1 Hz on the kHz range.

This is the latest version, resolution is 32 Hz on the highest frequency, 1 Hz on the low ones, 8 digits out:
Click here to download counter-0.4.asm
In the asm source you can select which of the three output fields are printed by simply uncommenting a line.
The first field is intended for parsing in Linux (or any other OS), that way you can call system() on some frequency, and do anything.
The second field prints 8 digits in Hz with leading zero surpression.
The third field prints 5 digits in MHz or kHz using auto ranging.
I am using awk in a script, and ptlrc to read the data, here a funny example:
ptlrc -d /dev/ttyS0 -b 1200 | awk '{if($1 == 50) {sysstring=sprintf("echo HELLO mains hum, and you are in Europe\r"); system(sysstring) } }'

This is the print configuration I am using:

The crystal will need a trimmer to set it to exact frequency, used 2 x 68 pF here.
Total cost... maybe 10 $?

Can be used without ground (100pF input cap), but you can use ground too.
Decided not to use an input amplifier, as I mainly measure signal levels that are high enough, the 100 pF will limit current.
It still works down to <50 Hz with a few volt, as the input cap of the PIC is only a few pF, and the impedance is very high.
When measuring my CB transmitter's output of MHz, I connect the output with the crocodile clips to the metal shell,
this works as the metal is floating, and the very small capacitance to the PIC circuit is enough for a stable display.
Do not connect more then 5V pp RF to the input pin.
I used the CB transmitter's digital readout to set the exact frequency by selecting the two capacitors on the crystal, needed 2 x 68 pF in my case!
I do not know why I had to pull that crystal several kHz down for an exact readout, it is marked 20.000 MHz.

Just before closing it.
Note the cut away edge of the phone jack, so it will fit tight in the D connector shell:

Wiring it:

More wiring:

Had to cut the pins of the PIC, and actually also cut part of the DIP package with a dremel so it would all fit:

If you use freq_pic with any prescalers and or frequency offset, or even just want a simple Linux command line communication program for it, check out freq256:

other projects