View previous topic :: View next topic |
Author |
Message |
SocMatt
Joined: 07 Jun 2004 Posts: 6
|
frequency counter |
Posted: Tue Jun 15, 2004 2:26 am |
|
|
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
|
|
Posted: Tue Jun 15, 2004 4:15 am |
|
|
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
|
|
Posted: Tue Jun 15, 2004 4:44 am |
|
|
Im using a PIC16F876. Which pins would be appropriate for this purpose.
Cheers |
|
|
Paolino
Joined: 19 Jan 2004 Posts: 42
|
|
Posted: Tue Jun 15, 2004 5:05 am |
|
|
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
|
|
Posted: Tue Jun 15, 2004 5:12 am |
|
|
I forgot: I used PIC16F876 and then also PIC18F252. No problem with both PICs.
Bye |
|
|
SocMatt
Joined: 07 Jun 2004 Posts: 6
|
|
Posted: Tue Jun 15, 2004 5:35 am |
|
|
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
|
|
Posted: Tue Jun 15, 2004 9:50 am |
|
|
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. |
|
|
|