code to measure frequency

Thread Starter

prescott2006

Joined Nov 8, 2008
72
i want to use measure the frequency of the square wave input at RA4/T0CKI of PIC16F84. so how should i start writing the code? anyone can provide some draft of the c code? thanks.
 

CVMichael

Joined Aug 3, 2007
419
I am not going to write code for you becuase you did not say what C compiler you use, and the code differs on each compiler. For example I use mikroC, are you using that ?

Anyways, the way I would go about this is to connect your input into pin RB0/INT, set up an interrupt, and have a counter increment for each interrupt. Then also set up a timer at 1 second interval (or 100 ms, or 10 ms, etc.), that displays, or sends data through RS232 (you did not mention how to give the result). And have the timer reset the counter to 0 right after it displays the counter. Also make sure that your timer is accurate.
If you display the data faster than 1 second (i.e. every 100 ms) then you should multiply your couter by 10, or 100 (if 10 ms), and so on...
 

Thread Starter

prescott2006

Joined Nov 8, 2008
72
actually, i want to build a guitar tuner based on this circuit. but the source code given is in hex file, and the author use assembly language to write the code. but i wish to use c to write the coding. i use mikroc as well. i see the input in the schematic is entering RA4/T0CKI. so i think it is not appropriate to use the method that you suggest.
 

Attachments

CVMichael

Joined Aug 3, 2007
419
Since the input goes into RA4/T0CKI, then it's more likely the input is used as the clock input to the TMR0 timer/counter. So you have to set the correct registers for that...
Actually that is pretty close to what I said in the other post...

What display is it using ? I can't tell from the schematic. mikroC has some built in functions for displays.

I think you should do this in 2 steps, first get the LCD to work, to display anything, then add the couter and that's it...

Also, I hope you have the full registered version of mikroC, because I think you will be using more than 2K program (because of the LCD functions).
 
Top