CMOS Switching and bouncing problems

Started by CodeMonk, September 05, 2011, 10:12:45 PM

Previous topic - Next topic

CodeMonk

Ok, so I wanted to get into CMOS switching (a current project requires it, unless I can find a 6PDT switch).
So my first bit of education in this, as usual, was a visit to Geofex (RG, your info has saved and educated me many times).

http://www.geofex.com/article_folders/cd4053/cd4053.htm
So after spending my spare time reading and re-reading count less times the CD4053 article, I went at it.
I started with the CD4013 section as I have a local electronics surplus store that I know had a bunch.
Built it up, but had some switch bounce (didn't even know it was called that at the time).
As I had discussed some aspects of my project with someone on another forum, he also suggested I put a 0.1uF cap across the switch leads
to cure bounce problems (He said this before I had built anything up, but apparently was aware of that issue).
So after I built up my first CD4013 section. I was getting switch bounce. So I put the 0.1uF cap in.
Bounce went away and it seemed to be working fine. I went ahead and started to add the other parts to make use of the CD4053.
But, before I put the CD4053's into their sockets and all, I tested the CD4013 part again.

It was no longer working. I would press the momentary switch, the LED lit. When I released the switch, the LED went off.
I went back to RG's original specs and it behaved as it should except for the switch bounce.

Since then, I have built this circuit up on my breadboard (The original was on a Datek "Spider" PCB), and on one of those little PCB's that Smallbear sells for 90 cents.
Same results. I get switch bounce, and with the 0.1uF cap I get the LED on with switch depressed and LED off as soon as I release the switch.

I did a fair bit of searching looking for de-bounce info.
It seems that the 100K resistor and the 0.01uF cap in RG's design is there for the de-bounce (feel free to beat me with a wet towel if I am wrong in this assumption).

So, I am currently unsure of what to do now.
Except I am going to mess around with the values of the 100K and 0.01uF parts to see what I can come up with.

NOTE: I am using these switches for my project so I am also using them for testing : http://www.mammothelectronics.com/4SFSSPST-M-p/800-1003.htm

Thanks for any info.

Edit:
Does the CD4053 section need to be hooked up for the CD4013 part to function properly (Maybe the CD4013 needs a load to work properly?)

R.G.

Switch bounce is a demon, always waiting in the shadows for you to be inattentive for a second.

Well, OK, it's always there and can be tough to root out.  :icon_lol:

All of the simple debounce circuits are special cases, with windows of component values that make them work. Outside the windows, you get bounce. It's worst when you get bounce sometimes, but not every time.

First, read http://www.ganssle.com/debouncing.htm
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

CodeMonk

#2
Thanks RG, will do.
And a note, each time I rebuilt, I used all new components just in case i broke something :)

Edit:
Several months ago I bought Don Lancaster's "CMOS Cookbook" to learn about CMOS stuff in general. Sadly, the section on CMOS switching is rather small.

R.G.

Quote from: CodeMonk on September 05, 2011, 10:25:47 PM
Thanks RG, will do.
And a note, each time I rebuilt, I used all new components just in case i broke something :)

Edit:
Several months ago I bought Don Lancaster's "CMOS Cookbook" to learn about CMOS stuff in general. Sadly, the section on CMOS switching is rather small.
CMOS switching is straightforward, in that the rules are clear. But it is quite unforgiving of any of the rules not being followed. Trivial little things can get you - like the impedance of an input is so high that a signal separated from the input by two inches of air can be picked up by the input .

Sometimes.

I really liked Ganssle's write up. Almost to the "sleep with it under my pillow" state.
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

CodeMonk

#4
I found Ganssle's info rather interesting.
Been experimenting with some things already.
But still need to read it a few more times to get it to sink in better. And reading his other info. Technical info tends to sink in better once I understand the writers style a bit more.

Another question...
I didn't see anything in the datasheet to indicate that the CD4053 is a latching type switch. So I am assuming its not.
If that is the case then the CD4013 is always sending >6 volts into the control signal. Correct?
(Please forgive this amateurish question, this is a new direction for me. And maybe I am overly eager (but willing and interested to learn, I see many possibilities here) ).
So is there a reason you can't use a SPDT latching switch to toggle the CD4053? Unless I am mistaken, thats what the CD4013 does anyway.
That's sort of the way its currently behaving.
Reliability? Possible chip damage?

earthtonesaudio



Note the text; when "A" is low, "X" is routed to "X0".  When "A" is high, "X" is routed to "X1".  If neither a high or low signal is present on "A" the output is indeterminate.  It may stay where it last was, or it may change, or it may oscillate rapidly back and forth.  You want to avoid this condition, so make sure the signal on "A" is always some definite logic level.  By definition the 4053 is non-latching, but neither does it snap back to a default position like a spring-loaded pushbutton switch would do. 

You can use a latching switch to control the 4053, that's fine.  The whole debounce/flip flop logic portion of these electronic switching schemes is designed to mimic the function of a latching switch while using only a (smaller/cheaper) momentary switch.  So electrically it's equivalent.

CodeMonk

Thanks.
I did some testing with a standard latching toggle switch. Works dandy using the <1/3, >2/3 formula.

Just the CD4013 is giving me headaches.
If worse comes to worse, I can go that route, but I'm a bit stubborn and would much prefer to use the CD4013 since that was my initial goal.
I'll get there, but will probably pull some of my hair out in the process :).

R.G.

Quote from: CodeMonk on September 06, 2011, 01:17:56 AM
I didn't see anything in the datasheet to indicate that the CD4053 is a latching type switch. So I am assuming its not.
Correct. It is purely three SPDT switches, each independently driven by one of the A/B/C control pins. Switch follows the pin condition.

QuoteIf that is the case then the CD4013 is always sending >6 volts into the control signal. Correct?
The CD4013 is sending its output voltage according to its datasheet. This is almost, but not quite the full power supply voltage when the output is high, and nearly, but not perfectly, ground when the output is low.There are specifications one exactly how close to power and ground logic signals get, but for CMOS it reduces to high voltage ~ power and low voltage ~ ground.

QuoteSo is there a reason you can't use a SPDT latching switch to toggle the CD4053? Unless I am mistaken, thats what the CD4013 does anyway.
That's sort of the way its currently behaving. Reliability? Possible chip damage?
Nope. Works fine. I like to pull the control pins up with about 100K and run a 10K to the off-board switch for reasons of protecting the CMOS inputs against voltage transients. There is a set of reasons for momentary switches, but for this application, latching switches work too.

R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

boogietone

#8
Quote from: R.G. on September 06, 2011, 12:55:33 PM
Nope. Works fine. I like to pull the control pins up with about 100K and run a 10K to the off-board switch for reasons of protecting the CMOS inputs against voltage transients. There is a set of reasons for momentary switches, but for this application, latching switches work too.

I want to make sure that I understand this. Do you mean that if you use a latching SPST (on-off) switch to control a CMOS switch, you:

1) place a 100K resistor from the control pin to the supply (9+DC for most positive voltage pedals) and
2) put a 10K resistor from the control pin to the one side of the SPST switch
3) the other side of the SPST switch is connected to ground?

If I were to use a latching STDT (on-on) switch with the common pin of the switch going to the CMOS control pin and one of the other SPDT switch pins going to supply and the last SPDT switch pin going to ground, would I only need the 10K into the CMOS control pin?

How much of a problem is it if the resistors are not used?

If this is covered in the debounce document, please just direct me there.
An oxymoron - clean transistor boost.

R.G.

Quote from: boogietone on September 06, 2011, 04:09:22 PM
1) place a 100K resistor from the control pin to the supply (9+DC for most positive voltage pedals) and
2) put a 10K resistor from the control pin to the one side of the SPST switch
3) the other side of the SPST switch is connected to ground?
That's my favorite, yes. There are other ways.

QuoteIf I were to use a latching STDT (on-on) switch with the common pin of the switch going to the CMOS control pin and one of the other SPDT switch pins going to supply and the last SPDT switch pin going to ground, would I only need the 10K into the CMOS control pin?
Not for the logic itself. This setup WILL bounce with the switch, but so do most of them.

QuoteHow much of a problem is it if the resistors are not used?
The 10K series resistor is not needed for the circuit to work in the normal case. It is there as a bit of finess based on long experience with CMOS logic. CMOS inputs go to actual MOS transistors which have gates made out of highly refined glass that's 20 (or less) volts thick. The chip becomes worthless if these gates exceed that number, even for a few nanoseconds. All modern CMOS has input protection circuits involving diodes to clamp incoming signals to the power supplies. However, too much current can burn out the diodes, then the CMOS chip. It takes a few more nanoseconds, but what's a nanosecond among friends?

CMOS logic lives longer if there is some resistance between it and the wires that go off board.  It will make no difference at all the first few times you try it. But one day, a transient will kill that gate if it's used enough. A 10K may put off that day until it no longer matters to you by limiting the input current which gets clamped to the power supplies down to something the diodes can stand for longer.
Quote
If this is covered in the debounce document, please just direct me there.
It's not. I have three gray hairs on my head as a reminder of how I learned about the sensitivity of CMOS inputs. Those are not the only gray ones there, but I do know which ones are for CMOS.   :icon_lol:
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

CodeMonk

#10
I think I may have added a few more gray hairs with this.
But to paraphrase Thomas Edison "I now know 999 ways not to do CMOS switching" :)

And something I always would tell my bosses after a bad day at work : "If I learned at least one thing, then it was a good day".
And its been a very good day. Well, night. I'm a bit of a night owl.

Edit:
For RG:
Thanks for the link to Ganssle's site.
Found a ton of interesting info there.
I used to be a Software Engineer by title and there was a lot of stuff there related to that. I was able to really identify with that.

PRR

> I bought Don Lancaster's "CMOS Cookbook" to learn about CMOS stuff in general. Sadly, the section on CMOS switching is rather small.

Fig 5-15 is equivalent to R.G.'s scheme; similar is found in many pedals. If not working for you, maybe your switch is extra-glitchy?

Fig 5-15 is a more-chips plan. At the first glitch it makes a 1 second pulse and ignores the switch for this period. 1 second may be short for a slow finger (it may glitch/pulse again on release) yet long for rapid-fire.

Fig 4-2 is simpler and more reliable IF you can use SPDT switch.

4SFSSPDT-LP price $2.80 and a small cap might do what you want withOUT electronic flip-flop-ery.
  • SUPPORTER

CodeMonk

#12
Quote from: PRR on September 06, 2011, 09:23:30 PM
> I bought Don Lancaster's "CMOS Cookbook" to learn about CMOS stuff in general. Sadly, the section on CMOS switching is rather small.

Fig 5-15 is equivalent to R.G.'s scheme; similar is found in many pedals. If not working for you, maybe your switch is extra-glitchy?

Fig 5-15 is a more-chips plan. At the first glitch it makes a 1 second pulse and ignores the switch for this period. 1 second may be short for a slow finger (it may glitch/pulse again on release) yet long for rapid-fire.

Fig 4-2 is simpler and more reliable IF you can use SPDT switch.

4SFSSPDT-LP price $2.80 and a small cap might do what you want withOUT electronic flip-flop-ery.


That one in  5-15 that uses both halves of the 4013 looks intriguing to me.
That might be tonight's project.
I guess I missed that bit. My copy of the book if missing the TOC for the first 9 chapters. Someone with a copy scanned them for me, but didn't do that great of a job.

I did get it working using a latching switch, and will go that way if I throw in the towel on the flip flop idea.
But....
1. Saw RG's article and said "I'm gonna do this".
2. I'm stubborn, to the point of being a bit masochistic.
3. I want something else I can put in my "tool chest".

egasimus

Hey, I just made a layout for R.G.'s 4053 switch yesterday. I went the inverter way, with a 4069. I haven't tested it yet, but I plan on etching a board today. What pitfalls should I expect ahead?

CodeMonk

Quote from: egasimus on September 07, 2011, 02:58:36 AM
Hey, I just made a layout for R.G.'s 4053 switch yesterday. I went the inverter way, with a 4069. I haven't tested it yet, but I plan on etching a board today. What pitfalls should I expect ahead?

Get good switches.

I got these :http://www.mammothelectronics.com/4SFSSPST-M-p/800-1003.htm
Been having all kinds of problems with my stuff.
I WOULD NOT RECOMMEND THESE SWITCHES. Not for this application anyway.
Apparently it has a severe case of the bouncies.
So I had an old Danelectro FAB pedal. Took a look at the switching system. Uses a CD4053 and a CD4013. Same as what I was using.
So I took the switch off the Dano pedal.
The test switching system works fine with that one.

Now I need to find a decent Momentary SPST switch.

Anyone have a recommendation for a quality Momentary SPST switch?

R.G.

Quote from: CodeMonk on September 07, 2011, 05:36:07 AM
Now I need to find a decent Momentary SPST switch.
Anyone have a recommendation for a quality Momentary SPST switch?
This is exactly the train of thought that led me to use tactile switches. Small tactile switches have very little bounce, and what they do have is over quickly.

Small Bear sells a spring-loaded actuator button, suitable for pressing a momentary switch through a soft plastic block...  :icon_biggrin:

The other thing that does work is probably not all that useful to you. I found i could debounce nearly anything by using Scott Datallo's vertical adder approach for debouncing. You get one chip (a uC, though) that debounces N switches in parallel with no timing loops or funny RC time constants. It's probably overkill for simple applications.
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

CodeMonk

Quote from: R.G. on September 07, 2011, 11:32:52 AM
Quote from: CodeMonk on September 07, 2011, 05:36:07 AM
Now I need to find a decent Momentary SPST switch.
Anyone have a recommendation for a quality Momentary SPST switch?
This is exactly the train of thought that led me to use tactile switches. Small tactile switches have very little bounce, and what they do have is over quickly.

Small Bear sells a spring-loaded actuator button, suitable for pressing a momentary switch through a soft plastic block...  :icon_biggrin:

The other thing that does work is probably not all that useful to you. I found i could debounce nearly anything by using Scott Datallo's vertical adder approach for debouncing. You get one chip (a uC, though) that debounces N switches in parallel with no timing loops or funny RC time constants. It's probably overkill for simple applications.


Thanks.
This has definitely been a learning experience.
But I am excited to see it finally coming together.
Just placed an order with Small Bear (Only 5 actuators and switches for now).
But I will have a look Scott Datallo's stuff later (need to wake up a bit more first).

PRR

> I bought Don Lancaster's "CMOS Cookbook" to learn about CMOS stuff in general.

Oh! Lancaster wrote CMOS knowing that "everybody" already read his RTL Cookbook and TTL Cookbook. CMOS assumes some basic logic concepts, and focuses on the new tricks possible with CMOS. It would be good to get one or both of the previous books and digest them.
  • SUPPORTER

CodeMonk

The Op Amp Cookbook is one that's on my list.
I guess I should add those as well.

Processaurus

An alternative available to stompbox builders (as opposed to manufacturers working within narrower parts budgets and using the cheapest of switch technologies-tact switches, rubber switches, membrane switches, etc) is using SPDT momentary stompswitches like small bear stocks, and using a set/reset latch.  The advantages are twofold: instant reaction time and no chance of bounce. 

The idea is that you use one throw to pull the reset pin high, and when you push the switch it disconnects from the reset pin and then connects the set pin high as long as the switch is held down, and then when you let go, it returns to holding the reset pin high.  It doesn't matter how many times it bounces because the bounces only reinforce the state:
Reset - Setsetsetsetsesesssss-Resetresetresereseresresrerereerrrr

Here is an example using a 4013 for the latch, you can also use "cross coupled" NAND gates, or even cross coupled inverters as the latch.