Frequency Counter 1.8Mhz

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
electrolaw
Posts: 8
Joined: Mon Mar 12, 2012 8:19 am
Has thanked: 6 times
Been thanked: 4 times

Frequency Counter 1.8Mhz

Post by electrolaw »

Dans_Frequency_Counter.fcf
(11.84 KiB) Downloaded 373 times
I needed to include a frequency counter in one of my projects and I thought I would post a stand-alone version of it in case it may help someone else who needs a simple counter for an application.

The program uses a PIC18F2550, but could easily be adapted for other chips that have a similar TMR0 and TMR1. The counter works as follows: TMR1 is used as a clock based on a 32.768Khz oscillator which is connected on pins T1OSO and T1OSI. It takes two seconds for the 16 bit TMR1 rregister to overflow. TMR0 is used as a counter with the frequency to be measured fed in to the T0CKI pin. During the time it takes the 16 bit TMR1 register to overflow, the number of overflows of the eight bit TMR0 are counted and the frequency calculated with a simple equation.

This frequency counter does not use interrupts, but rather uses the interrupt flags of TMR0 and TMR1. Therefore, I couldn't figure out how to use the Flowcode functions to do it and instead incorporated the C code to take care of that part of the program. Also, note that in the chip configuration, I think that Low Power TMR1 oscillator will need to be enabled.

The LCD part of the program looks odd because the 16x1 LCD I'm using had to be treated like it is a 16x2 LCD for it to print the lines correctly. Other 16x1 LCD's will work without having to divide up lines as I had to in the program, or of course, you could use any display and just modify the LCD properties as needed.

It's probably a good idea to use a preamp for the signal coming in to TOCKI. When I get the chance, I'm going to incorporate one in my build to see if it will make the counter more sensitive.

Two Microchip tutorials that I found to be especially helpful in understanding timers and interrupts are at http://ww1.microchip.com/downloads/en/D ... 51682A.pdf and http://ww1.microchip.com/downloads/en/D ... 51702a.pdf. According to the formulas in the second tutorial, the counter should work up to about 1.8Mhz

The hardware schematic itself is simple and I can post it if there is any interest.

One of the great things about Flowcode is the ability to seamlessly incorporate C code while using the Flowcode functions to take care of the LCD, etc. I've learned an incredible amount from reading and researching the forums and hopefully the program will help someone with their project.

Dan

Post Reply