View previous topic :: View next topic |
Author |
Message |
davt
Joined: 07 Oct 2003 Posts: 66 Location: England
|
rotary bcd switch debounce |
Posted: Fri Apr 01, 2005 4:27 am |
|
|
Hi all
Sorry for off topic question.
I am using a rotary bcd switch connected to port pins rb4 - rb7 on a 16f628 and have enabled the interrupt on change option.
Do I have to debounce the switch - or by the nature of its construction is this not required.
Many thanks.
Dave |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Apr 01, 2005 6:48 am |
|
|
Not sure what your application is, but let say that a rotary BCD switch
usually is reading at power up. If you want to detect that it had been
rotated at run time, enable the RB_INT and in the rb_isr() set a flag
and quit to clear the RB_INT.
In main, looking the setted flag and reading the BCD switch
1 second later would be a normal task, unless your application needs
a fast response. My $0.02
Keep well,
Humberto |
|
|
valemike Guest
|
|
Posted: Fri Apr 01, 2005 7:43 am |
|
|
If your rotary BCD switch is one of those plastic switches whose contacts change everytime you turn the dial, and it has detents, then I think you'll need to debounce the thing for a few ms.
Furthermore, be warned that you're going to get intermediate values since the switches may not all close and open at the same time.
e.g. if you're at 0011 and you want to go to 0100, you'll probably go thru:
0011 -> 0001 -> 0000 -> 0100
Thus, depending on how fast, or slow, the user's hand is, even debouncing the switch contacts will fool you. You'll need to add 1/2 to full second delays. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Fri Apr 01, 2005 10:11 am |
|
|
I've used plenty of rotary encoders. They have all been gray code output 2 pin types. Honestly, I've never run into a problem with switch bounce on any of them.
FWIW, usually the encoder's data sheet will say something about contact bounce. The ones I've used have all had a typical bounce time of at most 5 milliseconds. |
|
|
Ttelmah Guest
|
|
Posted: Fri Apr 01, 2005 10:22 am |
|
|
Gray code is specifically designed so that the codes as you switch, should not cause problems. Imagine you have a BCD switch at position '7', and move it to '8', and the extra top bit makes before the low bits release, you will 'see' a position half a trn out of aligment for a moment. With Gray code, the advance from any location to the next, only changes one bit. Hence you may be seen as jumping backwards and forwards by one location as the switch changes, but not the massive error from the BCD system.
Personally, I'd have the interrupt on change, start a timer for a few mSec, and exit. Then when the timer runs out, read the switch position. If every change, retriggers the timer, you will read (say) 5mSec after the last edge.
Best Wishes |
|
|
davt
Joined: 07 Oct 2003 Posts: 66 Location: England
|
rotary bcd switch debounce |
Posted: Mon Apr 04, 2005 2:14 am |
|
|
Many thanks for your input and time!
Dave |
|
|
|