hi all;
i am using pic 16f877 with 20 MHz crystal ; i want to enter pulses from generator. i want to calculate the width of the pulse. my program give me reading to 10Khz, i face problem to read frequencies higher than 10K.
if any one has code plz tell me
lot of thanx
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Wed Mar 19, 2008 1:41 pm
Quote:
I want to calculate the width of the pulse.
See this CCS example file:
Quote:
c:\program files\picc\examples\ex_ccpmp.c
elec.eng Guest
Posted: Wed Mar 19, 2008 10:02 pm
thanx for ur help but i use this code with my pic , and i still face the same problem , the basic cct for the pic 16f877 \ 20mhz such as for 16f877\ 4mhz instead i use 5pf at the 20mhz crystal
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
pulses
Posted: Sun Mar 23, 2008 8:44 am
if your capacitors 5pf change to 15 or 22
see bellow examples. ccp will latch timer1 when interrupt
best regards
joseph
Code:
//example1
//for consecutive frequency measurements
int frequencytime=0;
short int frequencycalcflag=0;
enable_interrupts(INT_CCP1);
void frequency_calculating ()
{
if (frequencycalcflag==1)
{
// "calculating the frequency"
frequencycalcflag=0;
}
}
#int_CCP1
void CCP1_isr()
{
set_timer1(0);
frequencytime=CCP_1;
frequencycalcflag=1;
}
//example2
//if the time for calculations (in pc) is too short, use as bellow
int frequencytime=0;
short int startflag=0;
//when you want to measure frequency start by enabling int.ccp1
enable_interrupts(INT_CCP1);
#int_CCP1
void CCP1_isr()
{
set_timer1(0);
if (startflag==1)
{
frequencytime=CCP_1;
disable_interrupts(INT_CCP1);
// "calculating the frequency"
startflag=0;//for the next time frequency check
else
{
startflag=1;
}
}
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