![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Experienced Member
|
Hi I want to debounce my button without a flag bit.Here is the coding but its not working well.
SHOW contains displaying digit stuff in the segments. Code:
btfsc PORTA,0 ;check the button is pressed? goto SHOW ;NO its not pressed then display the digits call DEL50mS ;YES its pressed then add a small debounce delay btfss PORTA,0 ;check the button has it released? goto SHOW ;NO then again show the digits goto COUNTUP ;YES it has released then count up |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
You are using active low, aren't you?
I always use 100 ms for debouncing without any problem, with tact switch. What switch are you using? What happen when don't press anything and what happen when you press only once? |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Yes I’m using active low.
When I press nothing it shows the “0000” in the segments. But when I press its counting in a messy way. I’m using micro switches Is my code right? |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Maybe you can't release the switch fast enough? Try to increase the delay and see whether it helps.
I do this way usually: Code:
btfsc PORTA,0 ;check the button is pressed? goto SHOW ;NO its not pressed then display the digits call DEL50mS ;YES its pressed then add a small debounce delay btfss PORTA,0 ;check the button has it released? goto $-1 ;nothing happen unless it is released goto COUNTUP ;YES it has released then count up |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Is the displays getting off while the button is press & hold time?
It's displaying after the button released isn't it? |
|
|
|
|
|
(permalink) | ||
|
Experienced Member
|
Quote:
Quote:
|
||
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Yes I'm using multiplexing the label SHOW contains multiplexing.
|
|
|
|
|
|
(permalink) | |
|
Experienced Member
|
Quote:
Can you tell a 62uS Delay is it a good or a bad delay for button debouncing. |
|
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Here's one thing to keep in mind:
Say your button could bounce for 62uS. What if the person holds down the button for 100mS, then lets go? Typically off-bounce is not the same issue but I've never ruled it out- what if the delay expires, he lets off the button, and it goes off then on again then finally off for real, that would end up erroneously being detected as a second press.
__________________
I thought what I'd do was I'd pretend I was one of those deaf-mutes. |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Oh I see 62uS is too low value.Because it expires as soon if the user has press & hold on the button too long.I must try with a 100mS delay.
But for a 62uS delay I'm already checking the button has released so the small delay wont expire. Am I right? |
|
|
|
|
|
(permalink) | |
|
Experienced Member
|
Quote:
The procedure I've done: Wait for button press, then take the action you take for a press and start the on-debounce counter. During this period further transitions will not be counted. At the end of the debounce count if the button is still pressed, wait for it to be released. When the release is detected, start the off-debounce counter. At the end of the off-debounce period, if it's pressed take the actions you take for a press again. Otherwise wait for a new button press. Debounce time varies greatly with the quality of the switch.
__________________
I thought what I'd do was I'd pretend I was one of those deaf-mutes. |
|
|
|
|
|
|
(permalink) |
|
Experienced Member
|
I agree with Oznog. Its good to wait till button is released either before or after calling a function. The debounce time is switch dependent and environmental. I always filter and debounce, though filtering is not needed for tact switches. Generic mouse button type tacts produce good clean signals.
By the way, calling a button press function first and then processing the button release afterwards is a sign of incredible natural ability or years of good experience. So Oznog, which one are you? If you truely wish to understand what is going one, take an observation of the switch signal with an O-scope. Below are captures of a regular 4-pin pushbutton mouse style tact switch. Notice the very fast and relatively clean rise time. There is actualy more noise after the button is pressed than during the act of pressing and releasing (not captured) yet still very clean. ![]() Animated GIF file above. Must "Instruct" Internet Explorer 7 to "Allow" animation if you use IE 7 and do not see the animation.
__________________
I can still log in! Delete my account and all my post now. Last edited by donniedj; 3rd August 2007 at 02:53 AM. |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Wow what a video thanks donniedj I now understand.I applied Oznog codings it comes like this
Code:
btfsc PORTA,0 ;check the button is pressed? goto SHOW ;NO its not pressed then display the digits call DEL500mS ;YES its pressed then add a small debounce delay btfss PORTA,0 ;check the button has it released? goto SHOW ;NO then again show the digits goto COUNTUP ;YES it has released then count up can you tell me is my coding right & what modifications to be done? |
|
|
|
|
|
(permalink) | |
|
Experienced Member
|
Quote:
Incidentally, SOME applications take action on the button release, for good reason, and the user almost never notices. For example, on an iPod if you press the (I think this is what it is) play button once it plays the track you're on, but if you hold it for 1 sec then it turns on the backlight and does NOT take that as a "play" instruction. Hmmm... how does it know not to play when you press the button? Like I say, it starts a counter when it detects a button press (debounces) counts the pressed time and if the counter reaches 1 sec then it turns on the backlight and forgets the play instruction. If the button is released before 1 sec then it'll take it as a play instruction and forget the backlight instruction. Turns out nobody holds down a button that long without a specific reason and pressing under 1 sec is so short that you won't notice the track starts on the release rather the the press. This also gets used for some "soft reset" conditions. If your device gets in a funky state but the ISRs are still working, there's often like 2 buttons you hold down together for 3 sec to force a reset. Yet you may not want the device to take the actions those 2 buttons normally cause.
__________________
I thought what I'd do was I'd pretend I was one of those deaf-mutes. |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| odd project, 1 button adds a light 1 button takes a light away with sound. | KevinAlaska | Electronic Projects Design/Ideas/Reviews | 15 | 6th June 2007 04:38 AM |
| Please help me in writing code | abdosat2000 | Micro Controllers | 9 | 5th June 2007 01:40 PM |
| 1 Hour Timer PIC 16F628A (Set Button) | Suraj143 | Micro Controllers | 11 | 26th April 2007 03:54 AM |
| button midi keyboard | jjjjjj | General Electronics Chat | 2 | 20th March 2006 04:10 PM |
| Push Button On/Off power to PIC | eblc1388 | Micro Controllers | 8 | 17th February 2006 01:31 PM |