CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

rotary bcd switch debounce

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
davt



Joined: 07 Oct 2003
Posts: 66
Location: England

View user's profile Send private message

rotary bcd switch debounce
PostPosted: Fri Apr 01, 2005 4:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 01, 2005 6:48 am     Reply with quote

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







PostPosted: Fri Apr 01, 2005 7:43 am     Reply with quote

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: 1903

View user's profile Send private message

PostPosted: Fri Apr 01, 2005 10:11 am     Reply with quote

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







PostPosted: Fri Apr 01, 2005 10:22 am     Reply with quote

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

View user's profile Send private message

rotary bcd switch debounce
PostPosted: Mon Apr 04, 2005 2:14 am     Reply with quote

Many thanks for your input and time!
Very Happy
Dave
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group