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

Problem to measure time period

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



Joined: 15 Jul 2013
Posts: 4

View user's profile Send private message

Problem to measure time period
PostPosted: Mon Jul 15, 2013 8:42 am     Reply with quote

I want to measure the frequency of the square wave input at RA0 of PIC16F877A.
So how should i start writing the code in C for CCS compiler??
Crystal frequency is 1MHz.
THANKS
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon Jul 15, 2013 9:27 am     Reply with quote

1) Have a go yourself, post code here when/if you get stuck.
2) Read the forum guidelines.
3) Tell us the frequency range of your signals.
4) Search here and google for similar code, it's been done before.


Mike
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Jul 15, 2013 10:06 am     Reply with quote

consider using either the CCP circuit
or the timer1 ext input with a gate from timer0

you may need a prescalar depending on frequency..
and your crystal frequency may be too low for higher input freq counts.

all these factors are inter related

thats my hardware advice
now per Mike
get coding..........

Very Happy Very Happy Very Happy Very Happy
Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Mon Jul 15, 2013 11:31 am     Reply with quote

Look at EX_FREQC.C. Except for having to change the clock (it is setup to use 20MHz), this is a complete example of how to do this. Except using the CCP input not RA0. Trying to do it on RA0, would limit the possible frequency supported to only a few hundred Hz.

Best Wishes
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon Jul 15, 2013 2:21 pm     Reply with quote

Try this as a link for starters.

http://www.ccsinfo.com/forum/viewtopic.php?t=47653&start=0&postdays=0&postorder=asc&highlight=exfreq

Mike
kalisaitan



Joined: 15 Jul 2013
Posts: 4

View user's profile Send private message

PostPosted: Mon Jul 15, 2013 7:02 pm     Reply with quote

thanx but i am beginner in programming,
i have no concept actually how code works
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 15, 2013 7:30 pm     Reply with quote

If you don't know anything about code or electronics or anything, you
shouldn't be asking questions on the forum at this point in time.
You should be looking at tutorials on the net:

Here's a video by CCS on how to use their compiler to write a program:
http://www.ccsinfo.com/videos/QuickStartVideo.wmv

Also you should answer questions that people ask you, such as what is
the range of input frequencies that you want to measure ?
kalisaitan



Joined: 15 Jul 2013
Posts: 4

View user's profile Send private message

PostPosted: Tue Jul 16, 2013 6:40 am     Reply with quote

i mean i understand about basic programming.But
I have no such concept about to measure Time period..

i want to measure frequency range of about 40 to 80 Hz
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Jul 16, 2013 7:29 am     Reply with quote

kalisaitan,

Do you actually own the CCS 'C' compiler? In your first post, locked and now deleted, you asked for help writing a 'Hi-Tech C' program. Suddenly,
a few hours later, you posed the exact same question, but this time you switched your query to the CCS compiler. You have been referred to the
CCS example programs, and other resources, but up to now, you haven't shown that you have actually done anything on your own. Personally, I think
you are trying to get us to do your homework assignment, and you have no actual interest in learning PIC programming.

John
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Jul 16, 2013 10:09 am     Reply with quote

the concept you need to solve this is for frequency/period/time:

T=1/F

you do understand that right ?

and the examples already cited ought to give you guidance.
have you read them yet?
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Tue Jul 16, 2013 11:43 am     Reply with quote

Since you mention "40-80hz", it sounds like measuring power line frequency. You don't mention accuracy, but if you are intending to read that to several digits to the right of the decimal, you need to consider measuring over multiple waves and taking the average or some other way of accurately measuring the time as well as how you are going to accurately measure the "period" of the wave (zero crossing or ??? )

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
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