CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Frequency Measurement Using CCP2 Module

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
arup
Guest







Frequency Measurement Using CCP2 Module
PostPosted: Tue Apr 08, 2008 10:41 pm     Reply with quote

Dear Sir,
Pls help on following query.

Application : Frequency Measurement Of half wave rectangular wave form of frequency 20 Hz to 80 Hz.

Hardware : PIC18F6585 . Crystal OSC . 20 MHz. The above mentioned signal is fed to ccp2 pin(pin no 40)

Pls note Micro circuit is battery backed up.

Development Tools : CCS C COMPILER

Method : I have used CCP2 module and timer3 as time base for this.

Code:

setup_ccp2(CCP_CAPTURE_RE); // Configure CCP2 to capture rising edge
setup_timer_3(T3_INTERNAL|T3_DIV_BY_8|0x08); // Start timer 3 ,prescaler  /8 ,
enable_interrupts(INT_CCP2); // Setup interrupt on rising edge     


In interrupt routine,
On first rising edge I have reset the timer3 . and on next rising edge I have taken CCP2 register value. So this will be my timer counter(16 bit) between two rising edge.
From the above details we can calculate timer3 frequency = 625000 Hz.
Code:
#define  FREQ_CONST  625000L 

1) so Frequency of subjected waveform = (unsigned char)(FREQ_CONST / timer counter )
Is this above method is OK ? any betterment using CCP2 module only.?

2) When power goes off , the signal at micro ccp2 pin will be at low state. Supposing that just before power gets off micro has detected a rising edge and reset the timer3 .Now micro will not get a rising edge until power comes .So I can’t update frequency(let’s say in last calculation frequency was 49 Hz) .But I have to detect the frequency .

To solve this ……
I have created a 10ms time base using timer0.At every 10 ms I will increment a counter
Code:

Void  f1_10ms(){

Zxcntr++;

}

I will reset that counter whenever there is rising edge found.In case of power goes off this counter will not reset .So I will check 5 such count i.e 50 ms and conclude that frequency is zero and reset that counter.

Is this method correct and reliable ? Could anybody suggest me for any better method ?

Regards,

Arup
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 08, 2008 11:12 pm     Reply with quote

There are several threads on using the CCP to find the frequency.
Just search for:
Quote:

tachometer

Here is the search page link:
http://www.ccsinfo.com/forum/search.php
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group