Frequency Counter( Mine Worked Up to 70MHz) Using PIC 16F628A (with Prototype PCB and Built in Crystal Oscillator) for HAM Shacks

by somnathpatra756 in Circuits > Microcontrollers

2833 Views, 1 Favorites, 0 Comments

Frequency Counter( Mine Worked Up to 70MHz) Using PIC 16F628A (with Prototype PCB and Built in Crystal Oscillator) for HAM Shacks

IMG_20210516_163916.jpg

After living in the dark age of having no instruments for measuring exotic electrical parameters like frequency, inductance , capacitance for constructing RF circuits ; I finally got the chance of making this simple yet effective counter designed by VK3BHR .He is famous for his " Surprisingly accurate LC meter" , I've made one of which also that I'll cover in a future instructable.

Gathering the Parts

Miscellaneous ------------------------------------------------------------------------------------------------------

  • PIC 16F628A microcontroller 1x
  • 7805 regulator 1x
  • 1602 LCD display 1x
  • 4MHz crystal 1x
  • 1N4148 diode 1x
  • BF199 transistor 1x ( You may replace that with 2N2222. But the upper limit of measurable frequency might decrease down to around 30MHz. More on this later.)
  • 10uH choke 1x
  • Dual male pin header strip (or use two single male pin headers in parallel)
  • 9V battery ( You can also use an external power supply as well. But to keep external noise from entering the circuit under test , it's better to use batteries )
  • A project box ( I used 4x4 PVC box which was like 50cent a piece)

Capacitors------------------------------------------------------------------------------------------------------------

  • 10uF electrolytic 2x
  • 22pF ceramic capacitor 2x (or one fixed ceramic capacitor of 22pF and one trimmer cap. of 30pF max. More on that later)
  • 0.1uF(104) ceramic capacitor 3x
  • 0.01uF(103) ceramic capacitor

Resistors--------------------------------------------------------------------------------------------------------------

  • 470R 2x
  • 1k 1x
  • 220R 1x
  • 10k 2x
  • 33k 1x
  • 10k trim pot 1x
  • And last but not least, a PC to edit the assembly code ( more on that later.......) and burn the HEX file to the MCU's flash memory.
  • Some sort of programmer to program the PIC MCU .

* Highly discourage y'all from buying the K150 programmer out there in case you need to buy a new one. I bought one and never got it to work properly on Windows 10 as the associated software is not windows 10 compatible . Running Windows 7, XP inside VirtualBox app didn't help much either. Maybe it was some weird timing issues that stopped the programmer from writing configuration bits to the MCU's memory. Rather buy a counterfeit PICKit3 if you can't get an original one. That works like a charm.

Schematic Diagram and Wiring Scheme

Xstal osc biasing.png
EmbeddedImage.gif
Wiring scheme of the counter.jpg

The built in crystal oscillator is powered from the same 5V regulated power that the PIC uses.

I didn't bother adding a buffer amp after the oscillator transistor as the counter had an input pre-amp at its input anyways. I also had the output from the crystal oscillator connected permanently to the input of the counter. You might want to switch this in and out of the counter input simultaneously with the power on/off switch of the oscillator as the input capacitance of the crystal oscillator circuit might load high impedance circuits under measurement.

Building the Hardware

IMG_20210104_201825.jpg
IMG_20210105_003237.jpg
IMG_20210105_003245.jpg
IMG_20210516_163335.jpg
IMG_20210516_163350.jpg
IMG_20210516_170710.jpg
1621432414537.jpg
1621432398517.jpg
Screenshot 2021-05-20 022342.png

Unfortunately , I had this project built quite some time ago and I forgot to took pictures of each and every stage.

Here I've added pictures of the counter before and after addition of the oscillator circuit. The small add on oscillator board is constructed in dead bug style. Notice how I've installed the socket(female pin header) for the crystal . This is done to reduce the lead inductance of the crystal to the oscillator circuit compared to if it had it been connected through discrete wires to the main circuit!. I've also included a picture and the associated EAGLE files of the PCB that I designed. The PCB doesn't include the crystal oscillator circuit. Might add that in future revision of the PCB.

On top I've also added the "press and peel" PDF file with multiple and single layout.

For people like me who don't own a printer , only one layout in a whole photo paper is quite expensive as it is often impossible to get "press and peal" method to work in a single shot and the print shops would rarely allow one (at least here in my country) to use a piece of paper with one corner cut( i.e. recycling an old paper) to make a print on it using their printer.

One information for those opting to build the PCB------ The PCB I designed, uses 2N2222 instead of the BF199 as I felt like it was hard to get hold of BF199's anymore on the market. As I said earlier, replacing BF199 tranny with a 2N2222 reduces the upper frequency limit of the counter drastically. Maybe for that very reason I couldn't measure over ~25MHz with the counter built around the PCB. Layout might be another issue too, as I'm not a professional. I'll attach the EAGLE .brd files here also for those who wanna modify the layout for optimal performance.

As it was found out that the PCB design was not optimal, I preferred to build the circuit on a piece of veroboard using BF199 as the input preamplifier ,AND VOILA! The counter measures 77MHz which you can see in the included picture, where I've connected it to a FM transmitter I built a while back and couldn't understand why I was unable to receive it onto a FM radio!!! Now I know why XD.

Editing the Software(Optional) and HEX for Burning the PIC

Frequency counter VK3BHR.jpg
IMG_20201230_195837.jpg
VK3BHR frequency counter code modification to add '.' after 1's of KHz

A thought of adding an extra '.' after the 1's of KHz to the display occurred to me as it would've made reading the display at a glance easier than reading KHz and Hz jumbled up together. My guess regarding why VK3BHR didn't include this in his code is that all he had available back then was 16 characters LCD (16*1 or 8*2). So, adding the '.' would've left only two blank spaces on the first line.

( XX.XXX.XX(space)MHz(space)(special mode indicating suffixes with 3 letters) i.e. 17 characters in total.

So, this made me to shift the special mode indicating suffixes to the second line and this created problems, which how I fixed , is discussed in the YouTube video attached here. I've included the modified HEX file and the ASM file in .txt format of the source code , as for some reason it's not possible to load .asm files at instructables. Just open the .txt file in notepad and change it's extension to .asm.

`

=

The Outro

If you need the original ASM file and want to learn more about this project, go over to https://sites.google.com/site/vk3bhr/home/fm2/sou...

There, the process of using the special functions of the counter e.g. calibrating, IF offset etc are described too.

Hoping the information to be adequate enough for y'all to build it.

Happy building...................................