View previous topic :: View next topic |
Author |
Message |
davidbue
Joined: 05 Nov 2007 Posts: 28 Location: Denmark
|
My first timer routine. |
Posted: Thu Mar 20, 2008 1:48 pm |
|
|
Hi everybody!
I have been spending the whole day trying to make my first timer routine. I just cannot get it to work!
I'm using the pic18f2220 with internal oscillator. What I'm trying to do is bacically getting the following test to work:
Code: |
void main{
while(1){
*Start timing*
delay_ms(100); //Making a dummy-delay between start and stop time
*Stop timing*
printf("%3.2f seconds has passed",the_time)
}
}
|
Forgive me for posting such a silly problem. I do know that this is trivial to all of you, and I really feel silly to ask. I have been reading help contents and example files all day, and I feel so dumb. Nevertheless I hope that one of you guys will take the time to write up a short example for me.
Thank you very much.
Best regards
David |
|
![](templates/subSilver/images/spacer.gif) |
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Mar 20, 2008 2:05 pm |
|
|
What you need to do is post a 'complete' listing of your code that can be compiled, without errors, and tested. The code you have posted is incomplete. We have no clue how you are configuring the PIC or how you are handling your variables. We have no clue how 'the_time' is manipulated or what kind of variable it is.
Post a complete, simple and short, listing that is error free.
Ronald |
|
![](templates/subSilver/images/spacer.gif) |
davidbue
Joined: 05 Nov 2007 Posts: 28 Location: Denmark
|
|
Posted: Thu Mar 20, 2008 2:24 pm |
|
|
Hi Ronald.
I've tried so many things today to get my code to work. Currently it looks like this:
Code: |
#include "C:\Documents and Settings\Administrator\Desktop\temp_projekt\timer_test.h"
void main()
{
long value1;
long value2;
setup_timer_0(RTCC_INTERNAL);
setup_oscillator(OSC_8MHZ|OSC_TIMER1);
while(1){
value1=get_timer0()
delay_ms(100) //Dummy delay
value2=get_timer0()
printf("%u",value2-value1);
}
}
|
What I try to is bacically at a given point in my code, to start measuring time, and then stop measuring a bit further on. After that I'd like to send the time measured through my serial link. (to hyperterminal)
Hope this helps.
Best regards
David |
|
![](templates/subSilver/images/spacer.gif) |
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Thu Mar 20, 2008 3:46 pm |
|
|
davidbue wrote: | What I try to is bacically at a given point in my code, to start measuring time, and then stop measuring a bit further on. After that I'd like to send the time measured through my serial link. (to hyperterminal)
Hope this helps.
Best regards
David |
Read this thread on measuring time.
http://www.ccsinfo.com/forum/viewtopic.php?t=26177
There are other way that also work but this is a good place to start. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 20, 2008 5:23 pm |
|
|
CCS has an example file which shows how to use a timer to measure
a pulse width:
Quote: | c:\program files\picc\examples\ex_pulse.c |
|
|
![](templates/subSilver/images/spacer.gif) |
davidbue
Joined: 05 Nov 2007 Posts: 28 Location: Denmark
|
|
Posted: Sat Mar 22, 2008 11:07 am |
|
|
Wohoo!
I got my timer routine to work! Thank you to everybody that helped me!
Have a nice weekend.
Best regards
David |
|
![](templates/subSilver/images/spacer.gif) |
|