View previous topic :: View next topic |
Author |
Message |
kalisaitan
Joined: 15 Jul 2013 Posts: 4
|
Problem to measure time period |
Posted: Mon Jul 15, 2013 8:42 am |
|
|
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
|
|
Posted: Mon Jul 15, 2013 9:27 am |
|
|
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
|
|
Posted: Mon Jul 15, 2013 10:06 am |
|
|
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..........
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Mon Jul 15, 2013 11:31 am |
|
|
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
|
|
|
kalisaitan
Joined: 15 Jul 2013 Posts: 4
|
|
Posted: Mon Jul 15, 2013 7:02 pm |
|
|
thanx but i am beginner in programming,
i have no concept actually how code works |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 15, 2013 7:30 pm |
|
|
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
|
|
Posted: Tue Jul 16, 2013 6:40 am |
|
|
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
|
|
Posted: Tue Jul 16, 2013 7:29 am |
|
|
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
|
|
Posted: Tue Jul 16, 2013 10:09 am |
|
|
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
|
|
Posted: Tue Jul 16, 2013 11:43 am |
|
|
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 |
|
|
|