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

measure button's pression time

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







measure button's pression time
PostPosted: Fri Aug 22, 2008 4:24 am     Reply with quote

Hi: I have a new problem.
I want to measure how much time (in seconds) one pin of 16f877a is high or low.. I know that I must use timers/interrupts, but I haven't idea how do it... Someone can help me? Thank's at all.
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: measure button's pression time
PostPosted: Fri Aug 22, 2008 6:34 am     Reply with quote

This can become quite a complicated problem if you have to deal with contact bounce too. A pushbutton does not generally give you a nice clean single transition from low to high, or high to low. Instead it bounces up and down very quickly several times during the transition.

One way to measure the duration of a button press is to make a software loop that checks the state of the input and increments a count if that input is active. Then you can calculate the duration of the button press from the value of the software counter by knowing the exact number of instruction cycles in your loop. Your loop should also have a time-out to detect when the button press is done, to account for contact bounce.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
milkman41



Joined: 16 Jun 2008
Posts: 30

View user's profile Send private message

PostPosted: Thu Aug 28, 2008 1:16 pm     Reply with quote

If you get the PIC development kit, example 14 in the exercise book does exactly what you want - it uses Timer1 and an interrupt. Check it out if you can, its pretty simple.
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