I want to measure frequency in range of 20KHz-40KHz the accuracy can be few hertz.
I think of useing the CCP in capture mode (div by 16)
and timer0 div by 1.
The device is 16F819 or 16F877.
1. Can someone help me with a simple code for that? or give me another idea how to do it?
2. Is it posible to read the CCP value at the CCP event without an interrupt
or I must wait for the Interrupt to read the CCP value
Thanks.
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
Re: Frequency meter
Posted: Tue Jan 06, 2004 11:43 am
edi wrote:
I want to measure frequency in range of 20KHz-40KHz the accuracy can be few hertz.
I think of useing the CCP in capture mode (div by 16)
and timer0 div by 1.
The device is 16F819 or 16F877.
1. Can someone help me with a simple code for that? or give me another idea how to do it?
2. Is it posible to read the CCP value at the CCP event without an interrupt
or I must wait for the Interrupt to read the CCP value
Thanks.
You can use the 16 bit timers to count instruction cycles and have a period of fixed time. You can use another timer to count rising edges on it's external clock input pin. You may then compute cycles per time and then convert to frequency. I have not used the CCP module to measure frequency but I know it can be done. I dont think that you can get the same level of accuracy with the CCP module that you can get using timers. The method using timers will only work on a periodic signal. For capture of a single cycle to determine frequency the CCP module is better.
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Tue Jan 06, 2004 1:07 pm
Here are links to some tachometer examples which use
the CCP. These are for the CCS compiler. Both of these
contain full source code. Also, you can search this board
for CCP, or tachometer, and find various routines that
are helpful.
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