Frequency Counter using PIC and PicBasic
Hello to everybody !
I'm new to this forum and have a question to start with.
I would like to build a frequency counter using a PIC like like 16F628 (or other if necessary) and a small LCD-Display.
I have already setup the PIC and the 16x2 LCD on a piece of breadboard. The PIC is running on a 20MHz Crystal.
So far I have managed to print characters to the LCD.
My goal is to count frequencies from 0Hz up to 20MHz or whatever is possible using a PIC.
The resolution should be as good as 1Hz (at least in the lower ranges).
I have tried the COUNT statement but it didn't give the expected range and resolution.
I have found some examples on the web, but thy're all written in ASM, and I don't know ASM.
At least did these examples show that my goal should be achievable. (even up to 50MHz)
Could one of the experts on the board give mesome hints how to solve the problem using PICbasic?
many thanks !
16F628 and frequency counter
Dear Pictron,
I have written a pbp program for the frequency counter by using 16F628. I have used TMR1 which is working as 16 bit.
The first trick is the TMR1 which is working on the back I mean it is not related with your program. The second trick is to use fixed periods such as 1000 ms - 100 ms - 10 ms - 1ms for counting and making sampling during these periods. The only problem with PBP is the timing. I have used pause command but I have seend that it is not enough precision to use that command and I decided to use a timing section written in ASM language.
I made a very good frequency counter which is working also as auto range. There are 4 different measuring mode on counting the frequencies between 0 and 40 MHz.
- 0- 65 KHz, Mode 0 , 1000 ms sampling period
- 65KHz-650 KHz , Mode 1, sampling period 100 ms.
- 650KHz - 6,5 MHz Mode 2, sampling period 10 ms.
- 6,5 MHz - 40 MHz, mode 3, sampling periode 1 ms.
I used also one divider (U664) for counting frequencies between 40 MHz up to 1200 MHz and one switch was selecting the inputs as LF and HF.
If you have enough knowledge you can write your own program with these instructions.
ERO