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 support@ccsinfo.com

Help needed with frequency counter

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







Help needed with frequency counter
PostPosted: Fri Apr 18, 2003 4:20 am     Reply with quote

Hi Picstars
i still need your help here as i have being strugling all night with this program.
its the example FREQC.C which is supposed to be a 50mhz frequency counter.
i have ran the program but i am still very confused
with the results i am getting as could understand why parts of the program were commented out?
i want to use it for the frequency range 100Hz to 10Khz
but i am getting the following results

AT 100Hz i get 11000Hz to 12000Hz
AT 1KHz i get about 13870Hz
AT 100KHz i get about 27000Hz
Could someone please tell me where i am going wrong
my program is below
Hope to hear from you soon
Isaac
#if defined(__PCM__)
#include <16F876.H>
#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)
#bit t1_overflow=0x0C.0


// #bit t1_overflow=0xF9E.0 (PIC18, Reminder)

void main() {
int cycles8, cycles;
int32 freq;
long freqc_high;
long freqc_low;

while (TRUE) {
cycles8=0;
cycles=0;
freqc_high=0;
t1_overflow=0;
set_timer1(0);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
/* ___ wait one second ___ */
while (cycles!=0xFF) { //true=3, false=4
cycles8=0; //1 cycle
//start inner loop
while (cycles8!=0xFF) { //true=3, false=4
if (t1_overflow)//true=2,false=3 //----|
{t1_overflow=0;freqc_high++;}//6 cycles // |
else // |-- 8 cycles
{delay_cycles(5);} //----|
delay_cycles(62); //x
cycles8++; //1
///2 cycles to jump to top
//math: end inner loop
//math: total inner loop=((3+8+x+1+2)*255 + 4)*255
//math: if x=62.87781 then inner loops takes 5mil instructions
//math: if x=62 then inner loop takes 4942920, have to fill 57080 cycles
}
delay_cycles(216); //y
cycles++; ///1 cycle
///2 cylces to jump to top
//math: outer=(3+1+y+1+2)*255+4=57080
//math: y=(57080-4)/255)-(3+1+0+0+1+2)
//math: if y=216.827450980392156862745098039216 then outer loop cylces is 57080
//math: if y=216 then outer loop cycles is off by 211 cycles. z=211
}
delay_cycles(211); //z
/* ___ end waiting 1 second ___ */
setup_timer_1(T1_DISABLED); //turn of counter to prevent corruption while grabbing value
if (t1_overflow) //check one last time for overflow
freqc_high++;
freqc_low=get_timer1(); //get timer1 value as the least sign. 16bits of freq counter
freq=make32(freqc_high,freqc_low); //use new make32 function to join lsb and msb
printf("\%LU Hz\r\n",freq); //and print frequency

}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 13785
Mark DSylva
Guest







Re: Help needed with frequency counter
PostPosted: Fri Apr 18, 2003 8:36 am     Reply with quote

:=Hi Picstars
:=i still need your help here as i have being strugling all night with this program.
:=its the example FREQC.C which is supposed to be a 50mhz frequency counter.

Where does it say that this is a 50Mhz freq. counter? I don't see any reference mentioning that.

:=i have ran the program but i am still very confused
:=with the results i am getting as could understand why parts of the program were commented out?

What parts are commented out? I only see some comments explaining the math, no actual code is commented out!


:=i want to use it for the frequency range 100Hz to 10Khz
:=but i am getting the following results
:=
:=AT 100Hz i get 11000Hz to 12000Hz
:=AT 1KHz i get about 13870Hz
:=AT 100KHz i get about 27000Hz
:=Could someone please tell me where i am going wrong
:=my program is below
:=Hope to hear from you soon
:=Isaac


The code is specifying a 20Mhz clock, is that what you are using?
___________________________
This message was ported from CCS's old forum
Original Post ID: 13787
isaac aiyanyo
Guest







Re: Help needed with frequency counter
PostPosted: Fri Apr 18, 2003 9:12 am     Reply with quote

:=Where does it say that this is a 50Mhz freq. counter? I don't see any reference mentioning that.
<a href="http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_freqc.c" TARGET="_blank">http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_freqc.c</a>
:=What parts are commented out? I only see some comments explaining the math, no actual code is commented out!
Yes you were right there sorry for the mislead
its all to do with my C knowlegde

:=The code is specifying a 20Mhz clock, is that what you are using?
i am using a 20Mhz clock.

Please help
Isaac
___________________________
This message was ported from CCS's old forum
Original Post ID: 13789
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