Hello.I am working on a frequency meter project.Processor 18F2420 8 Mhz internal oscillator As signal i am using a 50 Hz square wave (5Vp-p) that comes from a frequency generator.
On the oscilloscope i can measure 50 Hz to the T0CKI pin.
I use Timer0 for external edge counter (high to low) T0CON=0b00111000; . Inside interrupt of Timer1 i calculate the frequency.
Timer 1 interrupt occurs every 40 msec.
The problem that i have is i get a 51 to 52 Hz indication and not 50 Hz as i should.Also as i raise the frequency the error gets bigger
I used two methods to calculate frequency.I had the same error in both of them.
Here is the first (simple) method that i calculate frequency.Every 1 sec i stop Timer0 ,read the T0 counter value that equals the frequency i need :
Here is the second method that i calculate frequency.Now i dont sytop - restart Timer 0 i let it in count all the time and every time i calculate freq i save the current value of Timer 0 (pulses variable) as
previous pulses ( pr_pulses variable) :
P.S. I changed from internal 8 Mhz to an external 8 Mhz and i get 50 -51 Hz indication instead of the previous 51- 52 Hz , but still there is an accurasy problem cause this 1 Hz error in 50 Hz it gets 3-4 Hz error on 200 Hz input frequency and so on
Thank you for your time.
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Thu Jan 24, 2008 11:46 am
Use the forum search page to search for:
Quote:
tachometer
There are many posts with sample code and a discussion of how to use
the CCP module in Capture mode to find the frequency of a signal.
http://www.ccsinfo.com/forum/search.php
RLScott
Joined: 10 Jul 2007 Posts: 465
Re: Frequency meter calculation error
Posted: Thu Jan 24, 2008 1:34 pm
jojos wrote:
...there is an accurasy problem cause this 1 Hz error in 50 Hz it gets 3-4 Hz error on 200 Hz input frequency and so on
This would tend to indicate that your 50 Hz and 200 Hz are not accurate. How did you check them? An o-scope timebase is not good enough for the small errors you are talking about. The other thing to check is the accuracy of the 40 msec. Timer 1 interrupts. You could toggle an I/O bit every time you enter the Timer 1 ISR and then see if you really are getting exactly 25 interrupts per second.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum