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 CCS Technical Support

debounce switch

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



Joined: 24 Jul 2005
Posts: 20

View user's profile Send private message

debounce switch
PostPosted: Fri Aug 19, 2005 10:46 pm     Reply with quote

this is my routine to check what key is pressed
Code:

char key_id;
......
while(1)
{
if(RA0==0)   
  {
   delay_ms(20);
   if (RA==0)  key_id=1;
  }
if (RB0==0)
  {
  delay_ms(20);
  if (RB==0) key_id=2;
  }

}


a mount of time for delay_ms(interval)? 20ms is suitable?
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Sat Aug 20, 2005 7:38 am     Reply with quote

Some switches are more bouncy than others. For example, if you have dry contact inputs (e.g. relays), some relays specs say that the contact settling time is 16ms; some say 25ms.

Some designs may exhibit a lot of switching noise that radiates throughout the whole circuit. So best to look at an oscilloscope to see how long you really need to debounce.

For the case of simple tactile pushbuttons, you'll just need a 10k pullup resistor and .1uF capacitor to ground, and heck, even 5ms debouncing may be enough.
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Mon Aug 22, 2005 6:58 pm     Reply with quote

Take a look also at the ICs for switch debouncing such as MAX6816. They come handy, when your switch is connected to an interrupt or a counter.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Aug 23, 2005 8:38 am     Reply with quote

Here's a little routine, that I use, that seems to work quite well. You can play with the value of 'j' to get the delay that you need, depending on how bouncy your switch is.

Code:

void pushed_one(void)
{
unsigned int16 j = 0;
int1 save, current;

  if(!input(PIN_B7))// is the button pushed?
  {
    save = 0;
    for(j = 0; j < 400; j++)// adjust the value of j for your delay needs
    {
      if((current = input(PIN_B7)) != save)// if the button is not in the same state it was
      {                                 // last time then it has bounced, start counting again.
        j = 0;
      }
      save = current;
    }

    if(!input(PIN_B7))// if we’re still pressed after the delay time
    {
      pressed1 = 1;// set the flag that the button is pressed - global var
    }
    else
    {
      pressed1 = 0;// if we’re not pressed then make sure the flag is reset
    }
  }// end of if(!save)
  else
  {
    pressed1 = 0;// if the button is not pressed, reset the flag
  }
}// end of pushed_one()



Ronald
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

PostPosted: Tue Aug 23, 2005 9:11 am     Reply with quote

kender wrote:
Take a look also at the ICs for switch debouncing such as MAX6816. They come handy, when your switch is connected to an interrupt or a counter.


Can you recommend an IC that comes in a package more amenable to prototyping? I don't mind SMD's, but those really fine pitches intimidate me a tad.

Thanks,
Scott
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Tue Aug 23, 2005 10:25 am     Reply with quote

sseidman wrote:
Can you recommend an IC that comes in a package more amenable to prototyping? I don't mind SMD's, but those really fine pitches intimidate me a tad.


Well, MAX6816 (single) and MAX6817 (dual) come in SOT-23, which are more a less solderable by hand. I couldn't find the multi-channel debounce ICs in SOIC or bigger package. Take a look at this lab guide, which shows how to make debouncers out of logic gates. The circuit in the figure 9 is particularly simple.

http://www.people.fas.harvard.edu/~thayes/phys123/lb14_305.pdf
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Sun Aug 28, 2005 2:56 am     Reply with quote

sseidman wrote:
Can you recommend an IC that comes in a package more amenable to prototyping? I don't mind SMD's, but those really fine pitches intimidate me a tad.


A friend of mine cane across this one today http://www.onsemi.com/pub/Collateral/MC14490-D.PDF. It comes in DIP.
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

PostPosted: Mon Aug 29, 2005 6:28 am     Reply with quote

kender wrote:
sseidman wrote:
Can you recommend an IC that comes in a package more amenable to prototyping? I don't mind SMD's, but those really fine pitches intimidate me a tad.


A friend of mine cane across this one today http://www.onsemi.com/pub/Collateral/MC14490-D.PDF. It comes in DIP.


Thanks-

As it turns out, timely info. We're using a matched p-channel, n-channel mosfet that will provide any digital out from TTL to high voltage, high current without any circuit mods except for what you tie to Vcc, with another FET on the input to transition the logic level to Vcc (or the p-chan and n-chan are on at the same time, and the chip desolders iitself!!). Switch bounce is doing some real nasties.

Scott
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Wed Sep 07, 2005 7:31 am     Reply with quote

I have a couple of MAX681X chips, but I ended up not trying or putting it on my board. Reason is that it looks for "30ms" of a clean signal before it considers it a truly changed signal.

I'm using a couple PWMs on my board, and the duty cycle transitions on the high voltage side of my isolated motor drive cause nasty decayed sine waves (aka switching noise) radiating into my supposedly isolated 5V lines. As a result I have put tons of .1uf capacitors everywhere.

Wouldn't such switching noise lock up the MAX681X chips from "deciding"?
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

PostPosted: Wed Sep 07, 2005 7:59 am     Reply with quote

MikeValencia wrote:
I have a couple of MAX681X chips, but I ended up not trying or putting it on my board. Reason is that it looks for "30ms" of a clean signal before it considers it a truly changed signal.

I'm using a couple PWMs on my board, and the duty cycle transitions on the high voltage side of my isolated motor drive cause nasty decayed sine waves (aka switching noise) radiating into my supposedly isolated 5V lines. As a result I have put tons of .1uf capacitors everywhere.

Wouldn't such switching noise lock up the MAX681X chips from "deciding"?


I think "logically" clean would be a better description--no logical low to logical high transitions-- but I've not used that chip so I'm not sure.

More importantly, how have you isolated the high voltage side?? If it were me, I'd have a master power driving a regulator for the low side, and an isolated DC/DC for the high side. All the connections between would be optically isolated, and the respective grounds must never touch
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Wed Sep 07, 2005 9:23 am     Reply with quote

My "motor voltage" is actually 100VAC rectified to 141vdc from the primary of a custom autotransformer. This transformer also has a a 12vac secondary for digital stuff and a 14vac secondary for the motor driver.

The motor voltage and the 14vac rectified thru a bridge and 15v voltage regulator are both floating and share a common 'return'.

As for my PIC's inputs, when i measure them with a scope, i admit the ground probe's lead length does owe to the ringing i see. For all I know, maybe i have noise coupling within the transformer windings. I do have a line filter at the entry of line power, but this might not help since the autotransformer is downstream.

All in all, its a somewhat noisy system. One day, i'll try breadboarding a MAX6818 into my circuit and add a follow-up to this thread.
Guest








PostPosted: Wed Sep 07, 2005 7:44 pm     Reply with quote

MikeValencia wrote:
I have a couple of MAX681X chips, but I ended up not trying or putting it on my board. Reason is that it looks for "30ms" of a clean signal before it considers it a truly changed signal.


The MC14490, which I have mentioned above has an adjustable by a capacitor delay.
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