View previous topic :: View next topic |
Author |
Message |
otavio_fisica
Joined: 20 Jul 2006 Posts: 29
|
Count Time between events and store it in a variable |
Posted: Thu Jul 20, 2006 8:04 am |
|
|
Hi every one. I am a new user of the pic technology. This forum has really been usefull for me and I hope to learn this technology so as to contribute to future new users.
Now, I have a problem. I use the PIC12F675 and I what I need to do is to count time between two events (pressing button, for example), and to store this value in a variable. Summarizing:
-----------
-> The person presses a button, so one pin of the pic is high for some moment and then it is low again. The pic will identify this, and this will indicate it has to start counting time.
-> The person presses the button again. The pic identifies this again and now it indicates it has to stop counting the time and to store it in a variable, because I will need to make some calculus with it later.
------------
And help with this code would be welcome.
NOTE: What if this time is of the order of units of milliseconds??
I really apreciate any contribution. |
|
|
Ttelmah Guest
|
|
Posted: Thu Jul 20, 2006 8:23 am |
|
|
Depends on a whole range of things. What is the likely 'range' of timings required?. What else is the chip expected to 'do' while waiting?. What sort of accuracy do you require?.
Beware trying to count a 'mechanical' switch to times of a few mSec, since most switches will 'bounce' when made/broken, and if you try to count this sort of period, you may see several counts for a single closure. This is why most 'keyboard' routines debounce the switch (by testing multiple times over an interval), and debouce periods of perhaps 5 to 10mSec are often needed to deal with this...
If you want really good accuracy, then you would be much better off using a larger PIC with a hardware CTC.
Best Wishes |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Jul 20, 2006 1:19 pm |
|
|
There is an example very close to what you want.
EX_PULSE.C |
|
|
otavio_fisica
Joined: 20 Jul 2006 Posts: 29
|
Thanks |
Posted: Tue Jul 25, 2006 2:02 pm |
|
|
Thanks for the tip. What I needed was exactly to know how to count the time. And with that example, I could learn it. Just using the set_timer0(0) and the get_rtcc.
Thanks again. |
|
|
|