![]() |
|||||||||||||||||
![]() |
|
Custom Search
Readers
comments
|
|||||||||||||||
Schematics and C code for a PIC frequency counter operating up to about 50 MHz.A Liquid
Crystal Display Based
frequency counter project...
"Download Your Essential Guide To Logic Level MOSFETs" "This is completely Free" CLICK HERE to DOWNLOAD NOW
Sponsored Links...
This PIC frequency counter project uses an LCD to display the frequency and PIC timer 1 (TMR1) to measure the input signal.
Since the measurement time is 1 second the final count is actually the frequency of the input signal. Using the 1
second measurement time also gives a frequency resolution
of 1 Hz. Get a frequency counter nowHere's a selection of frequency counters that you can buy on Ebay (if you don't want to make up your own then you can get a bargain here - and it will have all the front end circuitry made for you). Just click on the Counter you want and start bidding. Click here to see more frequency counters on ebay. Specification
Note: The exact maximum operating frequency is determined by the PIC input pin characteristic. click here. You only need to recompile the pic frequency counter files if you want to change the source code or examine how the code works using the built in simulator since the hex file to program the chip is included in the download. For the general theory of operation of this circuit and notes on frequency counting of this pic frequency counter click here. PIC frequency
counter schematic using LCD and TMR1. Pic frequency counter HardwareThe hardware is simple and the main blocks are shown in the diagram below.
The LCD is used in 4 bit mode interface so you only need 4 data lines and three control lines and it then fits into a single 8 bit port. The crystal oscillator is simply a crystal and two capacitors connected to the PIC oscillator port at OSC1 and OSC2. The capacitors can both be fixed at the same value unless you want to tune it using a frequency reference. If you don't have an accurate reference then use fixed capacitors. The PIC micro can be any type that has a Timer 1 hardware and and has enough memory to hold the program. The LED is toggled at the end of every gate time to indicate that the processor is alive - so if there is no input signal you can tell that the software is working. You can program the PIC in circuit through the ICSP connector. PIC frequency counter SoftwareProject files for the PIC frequency counterCompiler project files C Source files. Header files. Output files Brief description
All other header files contain prototypes. PIC frequency counter code operation.The code uses the built in LCD driver routines which are automatically included by the compiler. Note automatic include is unusual but it seems to work well in mikroC. Interrupts are not used only the flags that can be polled (timer overflow) are activated. frequency_counter_4MHz_LCD_TMR1.cThis file contains the port initialization, gate loop and main routine. After initialization the code enters an endless loop where it continuously performs a measurement and display operation. After an accurate 1 second delay the counter result is processed and displayed on the LCD. The gate loop is tuned to just below a millisecond so that the caller (in main) can adjust the exact delay taking account of any delays caused by calling the gate loop routine itself. Note that the timer overflow is polled within the gate loop - the extra statements in the else part of the if statement allow constant execution time whether the condition was true or false. This allows the loop time to be accurately calculated since it always has the same execution time. delay.cDelay routines were created using machine code so that they have a fixed execution time i.e. they do not change as the compiler re-optimizes the code. They are also fixed in memory location to avoid bank change problems. bcd.cThis routine was created in machine code to save space on the smaller chips and it also results in faster code than using the built in routines for long multiply and divide. It uses the Add 3 method to convert the unsigned long into an ASCII value that can be displayed on the LCD. bit.hThis contains macros for bit manipulation which should be compiler independent.
Jump from pic frequency counter page to to Best Microcontroller Projects Home Page. |
|||||||||||||||||
|
|
|||||||||||||||||
|
|||||||||||||||||