View previous topic :: View next topic |
Author |
Message |
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
Elapsed Time |
Posted: Sat Mar 09, 2013 6:24 am |
|
|
Dear Friends, I have a function where I have input on INT1. Now I need to check the elapsed time between two inputs on the same interrupt. How I can implement it because I have no idea from I can start.
Thanks |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Sat Mar 09, 2013 6:51 am |
|
|
I found the solution. I used the get function
Code: | value=get_timer1(); |
from where I can know how I configured the Timer; which resolution from the .h file? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sat Mar 09, 2013 7:00 am |
|
|
The first place I'd look is in the EXAMPLES folder !
CCS kindly supplies a working program for you.
hint: 'stopwatch'.
probably 99% of the code required for 99% of the 'projects' can be found in the EXAMPLES folder....
that's just one of the benefits of using their compiler!
hth
jay |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Sat Mar 09, 2013 7:10 am |
|
|
temtronics, I am dealing with ms and ns and not seconds. I saw the examples, that's why I came here |
|
|
nurquhar
Joined: 05 Aug 2006 Posts: 149 Location: Redditch, UK
|
|
Posted: Sat Mar 09, 2013 7:20 am |
|
|
When you get it working for ns post the code. It will be interesting see how to accuratly handle the interrupt latency. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1345
|
|
Posted: Sat Mar 09, 2013 12:42 pm |
|
|
Working in ns makes things very difficult. Even running a dsPIC at 80 MHz only gives an instruction clock period 25ns, so each instruction in code will take 25ns (or more). For ms timing, you might look at a chip with input capture on it. You can set it up to trigger and record a time stamp for you, giving you some leeway to do other things.
Most likely, a solution in ns is going to be something completely tailored to your setup so you are unlikely to find many solutions from others on that. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sat Mar 09, 2013 2:21 pm |
|
|
Quote: |
ms and ns and not seconds.
|
what about the other lonely magnitude ??
are uSecs the orphans here ???
Usecs and above you can resolve pretty well on a pic with a fast enough clock and capture / compare AND
depending on the range of time you want to measure -
by using more than one approach
but nano-secs ?? you will need significant EXTERNAL ($$) hardware design to
slip into that range of resolution, as a Pic alone is not gonna resolve that based on realistic Fosc values |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Sat Mar 09, 2013 4:20 pm |
|
|
let keep it up to ms at the moment. When using the value=get_timer1() and I receive a value of 175, that means a value from 0-255? I can use the following formula to represnt the value to seconds:
13ms is the resolution of the Timer
thanks |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sat Mar 09, 2013 5:36 pm |
|
|
Timer1 returns a 16 bit integer.
If you press F11 when your project is open, you'll get the 'CCS help' files...simply scroll down to get_timerx() in the builtin_functions list.
Without seeing your code as to PIC, clock source, timer1 setup we can't tell you exactly what the returned value relates to.
hth
jay |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sun Mar 10, 2013 1:31 pm |
|
|
what pic are you using ??
18Fxxxx ? 16Fxxxx ? other ? |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Sun Mar 10, 2013 1:38 pm |
|
|
I am using the 18F4550 and the XTAL of 20MHz |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Mar 10, 2013 2:28 pm |
|
|
aaronik19 wrote: | let keep it up to ms at the moment. When using the value=get_timer1() and I receive a value of 175, that means a value from 0-255? I can use the following formula to represnt the value to seconds:
13ms is the resolution of the Timer
thanks |
I can't begin to understand what you're trying to say.
We need loads more information:-
1) Time range(s) to measure.
2) Required resolution(s).
3) Compilable code to test.
4) Compiler version.
5) ............
Mike |
|
|
|