View previous topic :: View next topic |
Author |
Message |
Apok
Joined: 02 Feb 2012 Posts: 2
|
Need help, counting seconds |
Posted: Tue Feb 07, 2012 6:57 am |
|
|
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
|
|
Posted: Tue Feb 07, 2012 8:09 am |
|
|
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: 9225 Location: Greensville,Ontario
|
|
Posted: Tue Feb 07, 2012 8:24 am |
|
|
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
|
|
Posted: Tue Feb 07, 2012 8:58 am |
|
|
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: 9225 Location: Greensville,Ontario
|
|
Posted: Tue Feb 07, 2012 9:13 am |
|
|
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
|
|
Posted: Tue Feb 07, 2012 9:16 am |
|
|
EX_STWT.C _________________ David |
|
|
|