Timeline for Software Debouncing to detect if switch has been pressed for T seconds
Current License: CC BY-SA 3.0
26 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Feb 22, 2018 at 12:44 | comment | added | rrz0 | @ThomasPadron-McCarthy, thanks for pointing that out. Yes, that is a mistake from my end. | |
Feb 21, 2018 at 21:34 | comment | added | Thomas Padron-McCarthy | "Since the clock speed for my micro-controller is at 60 MHz, then it will take 5 seconds to reach 300,000." Am I missing something, or have you (1) confused mega an kilo, and (2) assumed that an iteration of the loop is done in one clock cycle? | |
Feb 21, 2018 at 17:16 | vote | accept | rrz0 | ||
Feb 21, 2018 at 6:47 | comment | added | Nick Gammon | How are you going to detect "5 seconds or longer" if you have no idea how much time has elapsed? It's all very well saying you will count instructions, but if you add something to the counting loop, it will be out. | |
Feb 21, 2018 at 6:26 | comment | added | rrz0 | @NickGammon, no there is not... | |
Feb 21, 2018 at 4:26 | comment | added | Nick Gammon |
You say you don't want to use timers, but is there a function on the platform you are using that returns the elapsed time? (Similar to millis() on the Arduino).
|
|
Feb 21, 2018 at 3:53 | history | tweeted | twitter.com/StackElectronix/status/966158888243486725 | ||
Feb 20, 2018 at 20:08 | history | edited | rrz0 | CC BY-SA 3.0 |
added 299 characters in body
|
Feb 20, 2018 at 19:30 | answer | added | Jeroen3 | timeline score: 4 | |
Feb 20, 2018 at 18:03 | comment | added | DiBosco | Added a little more to it for further clarity (hopefully!) | |
Feb 20, 2018 at 17:58 | comment | added | DiBosco | Done. As there were two other good answers and I accidentally hit submit before it was ready, mine seemed unnecessary, but I hope it helps. | |
Feb 20, 2018 at 17:55 | comment | added | rrz0 | @DiBosco, I am currently pursuing a solution in the direction of the current answers (which seem the best option), however I have seen a snippet of the answer you posted and was wondering whether you could modify/undelete it ? | |
Feb 20, 2018 at 17:51 | comment | added | Trevor_G | @Rrz0 ya that kind of works assuming the calls to that are at regular and long enough but not too long intervals. | |
Feb 20, 2018 at 17:39 | comment | added | rrz0 |
I have an if(buttonPress()) statement, which only is true on return 1
|
|
Feb 20, 2018 at 17:36 | comment | added | Trevor_G | Sorry I misread the code.. not sure how you are calling that though... | |
Feb 20, 2018 at 16:56 | history | edited | Dave Tweed | CC BY-SA 3.0 |
fix formatting
|
Feb 20, 2018 at 16:47 | history | edited | rrz0 | CC BY-SA 3.0 |
deleted 23 characters in body
|
Feb 20, 2018 at 16:47 | answer | added | DiBosco | timeline score: 3 | |
Feb 20, 2018 at 16:45 | answer | added | Trevor_G | timeline score: 6 | |
Feb 20, 2018 at 16:44 | answer | added | Dave Tweed | timeline score: 15 | |
Feb 20, 2018 at 16:43 | history | edited | rrz0 | CC BY-SA 3.0 |
added 122 characters in body
|
Feb 20, 2018 at 16:42 | comment | added | rrz0 | @DiBosco, thanks for your insightful comment, yes I am calling this from the main infinite loop. I agree with all your statements mentioned, and I am trying to figure out a better way to do all the things mentioned. Would the method I am trying to use (without timers) be any good if I simply want to detect a button press longer than, say, 2 seconds, instead of an exact value? | |
Feb 20, 2018 at 16:39 | comment | added | DiBosco | PS When you're replying to someone, make sure you use their name so they know you have replied. :) | |
Feb 20, 2018 at 16:38 | comment | added | DiBosco | It looks to me like once downCount hits five you're just stuck in that while loop. I assume you're calling this from the main infinite loop? You need a better way of coming into the function from the main loop, incrementing the counter and coming out if you've not hit your target count. However, unless you do this from a timer (you could set a flag in an interrupt even if it's a shared interrupt) and come in here from the main loop when that flag is set, it's going to wildly inaccurate. | |
Feb 20, 2018 at 16:35 | history | edited | Dave Tweed | CC BY-SA 3.0 |
add material from comment
|
Feb 20, 2018 at 16:22 | history | asked | rrz0 | CC BY-SA 3.0 |