Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 18th January 2004, 06:48 PM   (permalink)
Default switch state based on timer

Hi again.

What is the proper way to make use of multiple states using switches, based on time?

What I mean is - say you press button1, it's associated IO pin sinks current via a resistor to ground, I can detect this and make a subroutine execute. But what if I want a different routine to execute if that pin is held to gnd for more than 2 seconds and yet a 3rd routine if it's held for 5 seconds?

Do you pass timing to the next loop? ie start a timer after first detection and check again at intervals? But then doesn't that change the logic for all button checking code? You now have to process based on leading edge of the switch release and not the press/sink?

I am confusing myself. Am I on the right track?
Patchouli is offline   Reply With Quote
Old 18th January 2004, 07:43 PM   (permalink)
Default Re: switch state based on timer

Quote:
Originally Posted by Patchouli
Hi again.

What is the proper way to make use of multiple states using switches, based on time?

What I mean is - say you press button1, it's associated IO pin sinks current via a resistor to ground, I can detect this and make a subroutine execute. But what if I want a different routine to execute if that pin is held to gnd for more than 2 seconds and yet a 3rd routine if it's held for 5 seconds?

Do you pass timing to the next loop? ie start a timer after first detection and check again at intervals? But then doesn't that change the logic for all button checking code? You now have to process based on leading edge of the switch release and not the press/sink?

I am confusing myself. Am I on the right track?
One way would be to make the keys auto-repeat, usually you would have it start repeating after being held down for a certain time (say after 1 second), them repeat at a faster rate (say every 250mS) while still held down. For your purposes you could count the number of repeats and branch accordingly.
Nigel Goodwin is online now   Reply With Quote
Old 18th January 2004, 08:51 PM   (permalink)
Default

another way is to use a "tick" counter, this way you use the timer1 register, set to auto-increment, and when the button is first pushed your store this value in a register, then in your timer0 int routine, you wait until the timer1 is say 20+value u saved.

Quick n dirty.

But yes u have the right idea
TheAnimus is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 10:28 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.