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 counter

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



Joined: 07 Jun 2004
Posts: 6

View user's profile Send private message

frequency counter
PostPosted: Tue Jun 15, 2004 2:26 am     Reply with quote

Hi

I need a frequency counter and had success using the example code ex_freqc.c, however now i need the frequency counter to work over two channels.
Can i reproduce the code for two channels or is it specific to that input pin of the PIC.

Any help would be most appreciated

Matt
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 4:15 am     Reply with quote

What PIC are you using? Most of the PICs feature two capture inputs as well as an external interrupt input which also can be used for this purpose.
SocMatt



Joined: 07 Jun 2004
Posts: 6

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 4:44 am     Reply with quote

Im using a PIC16F876. Which pins would be appropriate for this purpose.

Cheers
Paolino



Joined: 19 Jan 2004
Posts: 42

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 5:05 am     Reply with quote

I made a frequency counter, but I wrote my own code. I think it works in a very similar way of ex_freq.c by CCS. One of the firmware version allowed a double reading. I suggest you to use timer2 as time base and read frequencies directly from pin C0 and pin A4.

Best wishes.

Paolo.
Paolino



Joined: 19 Jan 2004
Posts: 42

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 5:12 am     Reply with quote

I forgot: I used PIC16F876 and then also PIC18F252. No problem with both PICs.

Bye
SocMatt



Joined: 07 Jun 2004
Posts: 6

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 5:35 am     Reply with quote

What way would you setup timer_2 as it is different from timer_1 and i have not used it before?

Cheers
Paolino



Joined: 19 Jan 2004
Posts: 42

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 9:50 am     Reply with quote

You can setup timer2 as a timer counter, to keep the time base. For example, setup timer2 to generate an interrupt each 100 ms. In the #INT_TIMER2 routine you count the edge you got from C0 and A4. Then you consider that freq=number_of_count/100_milliseconds. Take care that C0 can be configured as counter exactly as A4, but the counter in C0 in asyncronous with the OSC frequency. The counter in A4 is NOT! So do not pump up too much with the frequency or you will get mesaurement errors from A4. The time base you will use on timer2 must be setup on your needs... I can not design it for you...

Please, take note of the datasheet of PIC16F876; there are very simple block diagrams on how the counters work.

Best regards.

Paolo.
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