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

Count Time between events and store it in a variable

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



Joined: 20 Jul 2006
Posts: 29

View user's profile Send private message Send e-mail MSN Messenger

Count Time between events and store it in a variable
PostPosted: Thu Jul 20, 2006 8:04 am     Reply with quote

Very Happy 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. Very Happy
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. Smile
NOTE: What if this time is of the order of units of milliseconds?? Question

I really apreciate any contribution. Smile
Ttelmah
Guest







PostPosted: Thu Jul 20, 2006 8:23 am     Reply with quote

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

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

PostPosted: Thu Jul 20, 2006 1:19 pm     Reply with quote

There is an example very close to what you want.
EX_PULSE.C
otavio_fisica



Joined: 20 Jul 2006
Posts: 29

View user's profile Send private message Send e-mail MSN Messenger

Thanks
PostPosted: Tue Jul 25, 2006 2:02 pm     Reply with quote

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