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
Re: measure button's pression time
Posted: Fri Aug 22, 2008 6:34 am
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
Posted: Thu Aug 28, 2008 1:16 pm
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.
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