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

My first timer routine.

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



Joined: 05 Nov 2007
Posts: 28
Location: Denmark

View user's profile Send private message Visit poster's website

My first timer routine.
PostPosted: Thu Mar 20, 2008 1:48 pm     Reply with quote

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
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Mar 20, 2008 2:05 pm     Reply with quote

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
davidbue



Joined: 05 Nov 2007
Posts: 28
Location: Denmark

View user's profile Send private message Visit poster's website

PostPosted: Thu Mar 20, 2008 2:24 pm     Reply with quote

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
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Thu Mar 20, 2008 3:46 pm     Reply with quote

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.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 20, 2008 5:23 pm     Reply with quote

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
davidbue



Joined: 05 Nov 2007
Posts: 28
Location: Denmark

View user's profile Send private message Visit poster's website

PostPosted: Sat Mar 22, 2008 11:07 am     Reply with quote

Wohoo!

I got my timer routine to work! Thank you to everybody that helped me!

Have a nice weekend.

Best regards
David
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