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

Need help, counting seconds

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



Joined: 02 Feb 2012
Posts: 2

View user's profile Send private message

Need help, counting seconds
PostPosted: Tue Feb 07, 2012 6:57 am     Reply with quote

Hello, I don't have any experience using timers with CCS C, and I am not getting it by manual.

I want to calculate how many seconds passed from moment A to moment B. Anyone can help me how I do this in CCS C?

Micro: PIC18F
External crystal: 20 Mhz

Thanks
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Feb 07, 2012 8:09 am     Reply with quote

Generally the strategy is to set up a timer interrupt to trigger every 1ms or so. Inside that interrupt you increment a count of milliseconds. At moment A read the count of milliseconds. At moment B read again and subtract. You may need to scale things to make sure counters don't overflow without being noticed.

There is probably an example in the compiler examples directory, but I don't have it on this PC.
_________________
The search for better is endless. Instead simply find very good and get the job done.
temtronic



Joined: 01 Jul 2010
Posts: 9181
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 07, 2012 8:24 am     Reply with quote

Yup, example in the examples folder, it's the 'stopwatch' program.It's been an example since PCM V2.529 (1998-1999).

Easily to modify for the op purpose.
Apok



Joined: 02 Feb 2012
Posts: 2

View user's profile Send private message

PostPosted: Tue Feb 07, 2012 8:58 am     Reply with quote

temtronic wrote:
Yup, example in the examples folder, it's the 'stopwatch' program.It's been an example since PCM V2.529 (1998-1999).

Easily to modify for the op purpose.


Hey,what example folder are you talking? on this one -> "C:\Program Files (x86)\PICC\Examples" i cannot find anything called 'stopwatch'

Thanks
temtronic



Joined: 01 Jul 2010
Posts: 9181
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 07, 2012 9:13 am     Reply with quote

Hmm...

I didn't say 'stopwatch' was the program name
stopwatch was in single quotes and is NOT the filename. Illegal back then(8.3 rule).Also didn't have .C as the extension.

There's

EX_STWT.C
EX_STWT1.C
EX_STWT.2.C

... in my examples folders....

in all versions of PCM from at least v2.540 to date.


If you look at the examples you'll see it.

Or you can have Windows search for any program that has 'sttopwatch' as text within and file in the Examples folder.

CCS kindly supplies a LOT of useful code snippets in dozens of programs but you have to open them and see what's inside!
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Tue Feb 07, 2012 9:16 am     Reply with quote

EX_STWT.C
_________________
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