Sunday, September 14, 2014

Frequency measurement using two timer

frequencyThis tutorial is about measuring the frequency of a signal.To count a signal frequency many techniques are available.After some googling results in a delay method which makes a 1 second delay, by the meantime a counter counts the pulses.Then the number of pules will be the frequency of the signal. But it makes some problem such as
  • When it makes delay microcontroller cpu is idle for 1 second.
  • It reduces the speed of the process.
  • Other works are stopped at the time of frequency measurement.
So we need a solution where we can measure frequency as well as all the problems will be solved.
Actually the solution is very easy.You have to use two timer at a time.One timer as a counter and another one is used to make a delay.As timer can run freely without disturbing the cpu and can generate interrupts so all problems will be vanished and calculation will be more accurate and smart.
In this tutorial PIC16f873 is used,codes are written in MikroC Pro For PIC ,whole project are simulated in Proteus 7.6. You can download the all the files (including ISIS schematic,MikroC Project files) from the link given below the post.
Here Timer1 is used to make a delay of 1 second.You can make any time delay using a timer just take help of a very good tool called Timer Calculator which can generate code according to your need. Just input your controller frequency,the timer you want to use,the time delay you want.According to my need it was like below
 image
Then just copy the code to your MikroC editor.Then initialize Timer0 as a counter.You have to write the code
T0CS_bit=1;
T0SE_bit=0;
TMR0IE_bit=1;
Now open the project file which you downloaded and build it.Open the .DSN schematic file in Proteus and load the hex.A pulse of frequency 1000Hz is fed to T0CKI pin.Then run the schematic.If there is no error then Lcd will show exactly 1000Hz.You can change the frequency.
frequency
You can add your code according to your project and just take the value of frequency when you need. If you have any problem to understand the tutorial please put a comment or mail me.Don,t forget to share the post.
Download the project files from here.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.