- 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.
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
Then just copy the code to your MikroC editor.Then initialize Timer0 as a counter.You have to write the code
T0CS_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.
T0SE_bit=0;
TMR0IE_bit=1;
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.
Aw, this was an incredibly good post. Finding the time and actual effort to make a great
article… but what can I say… I procrastinate a whole lot and never
seem to get anything done.