Purpose of the cap in this RC Debouncer circuit...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Spork Schivago
    Badcaps Legend
    • Mar 2012
    • 4734
    • United States of America

    #1

    Purpose of the cap in this RC Debouncer circuit...

    Hello,

    I'm trying to learn how to debounce my push-button switches. I'm looking at the hardware way of doing it right now. I've attached an image but I'm curious as to how the cap is actually working in this schematic.

    When the switch is closed, wouldn't VCC just travel through R1 and R2 to the NOT gate?

    I know that electrolytic caps block DC voltage but allow AC voltage to pass through and I understand why. So, in this diagram here, the cap would charge up and if the circuit was broken, the cap would provide DC and pass it through the NOT gate, right? But the circuit with the cap never gets broken, right? How does the cap actually help to do away with the bouncing effects of a switch?
    Attached Files
    -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full
  • Spork Schivago
    Badcaps Legend
    • Mar 2012
    • 4734
    • United States of America

    #2
    Re: Purpose of the cap in this RC Debouncer circuit...

    I think I might understand now. I was forgetting about the anode / cathode on the cap. When the switch isn't closed, the circuit is broke, the cap can never charge, right? VCC can't go through the caps anode terminal and then down through the cathode terminal to get to ground, right? The cap would only charge up when the switch is closed, is that right?
    -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

    Comment

    • eccerr0r
      Solder Sloth
      • Nov 2012
      • 8694
      • USA

      #3
      Re: Purpose of the cap in this RC Debouncer circuit...

      Uh...
      Analyze this way: Treat the inverter's input as mostly an open circuit, so basically ignore the inverter for now (not exactly the right model, but close enough). The voltage across the cap is what is fed in the inverter.

      The key to this is that the voltage across a cap cannot change instantaneously, unless it is a BAD CAP.

      Now case 1: switch is open (not pressed). Basically you end up with two resistors in series and capacitor. The capacitor will eventually charge up to VCC, no questions about that. When the cap voltage rises above the flip point of the inverter, the output goes low.

      Case 2: the switch is pressed. In this case R1 is shorted to ground and does nothing except eat power. R2 is now parallel with the capacitor, so it also starts discharging the capacitor. Capacitor voltage will go down and eventually hit GND. When the voltage drops below the trip point of the inverter, the inverter will flip high.

      The reason for the cap? The cap is there to make sure the amount of time that the switch is bouncing is shorter than the amount of time to charge/discharge the cap so that it's hidden in the scheme of things.
      Last edited by eccerr0r; 12-21-2015, 01:54 PM.

      Comment

      • Spork Schivago
        Badcaps Legend
        • Mar 2012
        • 4734
        • United States of America

        #4
        Re: Purpose of the cap in this RC Debouncer circuit...

        Okay, thank you eccerr0r. So the point of R1 is just so VCC isn't connected directly to ground when the flip is switched? It's just a load that drops the voltage before hitting ground? R2 and the value of the cap is what determines how long the inverter stays high? Longer bounce, different values, right?
        -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

        Comment

        • Spork Schivago
          Badcaps Legend
          • Mar 2012
          • 4734
          • United States of America

          #5
          Re: Purpose of the cap in this RC Debouncer circuit...

          I'm looking at a formula, here: http://www.ganssle.com/debouncing-pt2.htm

          that shows the formula on how to calculate how long it takes to discharge a cap. They rearrange the formula so we can calculate what resistor value I need to do away with the bounce. The formula, rearranged is:
          Code:
          [FONT="Courier New"]
          R =  -t
             -----
          C(ln(Vth/Vinitial))
          [/FONT]
          t is the time of the bounce, in seconds. To be generous, we put 20 milliseconds, or 0.02 seconds.

          C is the value of the capacitor, in farads. They use 0.1 uF, or 0.0000001 farads. Vth, they say, is the input hysteresis I think. I'm having trouble finding out how to find this number. In their example, they say the 7414 hex inverter has a Vth, worst case, of 1.7V. Vinitial is the voltage we supply to the circuit, in this case, 5V. Solving the equation, we get:

          Code:
          [FONT="Courier New"]
          R =  -0.02
             -----
          0.0000001(ln(1.7/5))
          
          
          
          
          R =  -0.02
             -----
          0.0000001*ln(0.34)
          
          
          
          
          R =  -0.02
             -----
          0.0000001*-1.07880966137193
          
          
          
          R =  -0.02
             -----
          -0.000000107880966137193
          
          
          
          
          R = 185389.515093569483385678265672
          or roughly 185K.
          [/FONT]
          Any idea what they mean when they say Vth and where do I find that information in the datasheet? I believe they're using the 74AHCT14 inverter.
          -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

          Comment

          • stj
            Great Sage 齊天大聖
            • Dec 2009
            • 30977
            • Albion

            #6
            Re: Purpose of the cap in this RC Debouncer circuit...

            dont mix up ttl and cmos chips - the input specifics are different.

            Comment

            • Spork Schivago
              Badcaps Legend
              • Mar 2012
              • 4734
              • United States of America

              #7
              Re: Purpose of the cap in this RC Debouncer circuit...

              Thanks Stj. I was thinking of going with the CMOS ones.
              -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

              Comment

              • Spork Schivago
                Badcaps Legend
                • Mar 2012
                • 4734
                • United States of America

                #8
                Re: Purpose of the cap in this RC Debouncer circuit...

                I think maybe Vth might be the Logical Threshold, where the input and output voltages are equal. Just gotta find where this information is located in the datasheet. I found an old article saying you could calculate it by hooking the output of the inverter up to the input of the inverter and measure it.
                -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                Comment

                • Spork Schivago
                  Badcaps Legend
                  • Mar 2012
                  • 4734
                  • United States of America

                  #9
                  Re: Purpose of the cap in this RC Debouncer circuit...

                  I see the 74AHCT14 is a CMOS inverter that provides pin compatibility with TTL logic. That's kind of nice. We can finally move away from TTL logic and stick with mainly CMOS type ICs now. I know it's really easy to damage CMOS with ESD but I think the less power they consume could really benefit the world. Make it more green, you know?
                  -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                  Comment

                  • stj
                    Great Sage 齊天大聖
                    • Dec 2009
                    • 30977
                    • Albion

                    #10
                    Re: Purpose of the cap in this RC Debouncer circuit...

                    it's the "T" in HCT that makes it compatable - ish.
                    there are rare instances where they dont work as ttl replacements though.
                    dont ask - it's down to trial and error.

                    Comment

                    • keeney123
                      Lauren
                      • Sep 2014
                      • 2536
                      • United States

                      #11
                      Re: Purpose of the cap in this RC Debouncer circuit...

                      So here is a good explanation of RC t with natural log.

                      Comment

                      • Spork Schivago
                        Badcaps Legend
                        • Mar 2012
                        • 4734
                        • United States of America

                        #12
                        Re: Purpose of the cap in this RC Debouncer circuit...

                        Originally posted by stj
                        it's the "T" in HCT that makes it compatable - ish.
                        there are rare instances where they dont work as ttl replacements though.
                        dont ask - it's down to trial and error.
                        Gotcha! I'll try to remember this in the future. I saw where it said they're usually marked with TTL in the name or a T that says it's TTL compatible. Boy, I wish you knew C Stj. Having real trouble with my debouncing routine for these push buttons. Dang push buttons and their bouncing!

                        I'm going to sit down and read this early Christmas gift my wonderful wife got me. C Programming - A Modern Approach, 2nd Edition by K.N. King. It's a great book on C. I understand what bouncing is and I understand a few ways to detect it and the workarounds. It's just implementing the functions that I'm having trouble with. Instead of writing my own function, I've decided to use William Dillon's debouncing function. Just gotta figure out how it works and everything.
                        -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                        Comment

                        • Spork Schivago
                          Badcaps Legend
                          • Mar 2012
                          • 4734
                          • United States of America

                          #13
                          Re: Purpose of the cap in this RC Debouncer circuit...

                          Originally posted by keeney123
                          So here is a good explanation of RC t with natural log.
                          Thank you Keeney123. I've tried in the past to understand capacitors but have failed. I think I'll understand this time around but I'm going to need to ask some questions for clarification, if that's alright.

                          I've started reading the PDF you linked to and I had a question already. This is what the PDF says:
                          Code:
                          ...the battery will drive charges around the circuit as an electric current.
                          When the charges reach the plates they can't go any further because of the
                          insulating gap so they collect on the plates, one plate becoming positively
                          charged and the other negatively charged. This slow buildup of electric
                          charge actually begins to resist the addition of more charge as a voltage
                          begins to build across the plates, thus opposing the action of the battery....
                          So the battery moves the charge through the circuit. When the charge reaches the two plates in the capacitor, they can't go anywhere because of the insulator between the plates. I understand that so far.

                          I don't understand why they collect on the plates and why one becomes positively charged and the other negatively charged though. Why is it a slow buildup? Is the reason it resists the addition of more charge because it's saturated with electrons? How is this creating the voltage across the plates?

                          I have more questions but I figured that's enough right now! Maybe if the first one gets answered, the other ones would just start making sense to me.
                          -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                          Comment

                          • keeney123
                            Lauren
                            • Sep 2014
                            • 2536
                            • United States

                            #14
                            Re: Purpose of the cap in this RC Debouncer circuit...

                            The short version is the charges of the plate hold each other together because the characteristics of the make up of the plates and the dielectric.
                            Long version:This is how I look at it; With Direct Current you will have valance electrons from one atom bumping into valance electrons of another atom in a copper wire. The potential that creates this a batteries Voltage. A battery terminal has say on one side a +5VDC on the other side a -5VDC to make a 10 DC Volt battery, which when you measure across the battery and observe the polarity a +10 Volts. What creates this voltage are the components inside the battery. This is a chemical reaction within the battery. Now, if you go back to what I said about Direct Current and the valance electrons bumping into each other this happens from the positive terminal to the negative terminal in one direction. Because a capacitor has a dielectric which is an insulating material and plates that are conductive it presents a condition that when you connect a battery to it you will have an instantaneously full amount of current flow from one valance electron to another in the copper wire( with copper wire resistance) then to the plates(set at a specific distance to each other) of the capacitor through the insulator(made of certain types of materials and of specific resistance) continuing on the the other plate and back to the other terminal through the chemical reaction of the battery( which is the internal resistance of the battery). So the condition of the capacitor is the plate builds up a charge(coulombs) because the gap between the plates with the dielectric resist the flow of electrons in such a way that the opposing plates in a capacitor hold the charge from one plate to another. So the current in a capacitor is controlled by the resistance of the circuit including the internal resistance of the battery it is logarithmic in nature and starts out at maximum and reduces to near "0" but never attains "0". At the same time the Voltage starts out at "0" and attains near the voltage of the battery but never reaches that point. As the current runs through the plates charges accumulate on the plates positive and negative holding each other together. The short version is the charges of the plate hold each other together because the characteristics of the make up of the plate. I guess this is the best I can explain this.
                            Last edited by keeney123; 12-21-2015, 11:50 PM.

                            Comment

                            • Spork Schivago
                              Badcaps Legend
                              • Mar 2012
                              • 4734
                              • United States of America

                              #15
                              Re: Purpose of the cap in this RC Debouncer circuit...

                              Wow, that was a great help! I remember valance electrons some how from high school chemistry! What you said made a lot of sense and it answers so many questions. Thank you Keeney123!!! I'll reread your post again tomorrow and I'll finish reading that article you linked me to. I kept on reading and got to some math and felt that it was a good time to stop for the night. I was reading how ohms x farads = time. They had some weird greek symbols I think in some of the formulas. I think one is called a Tau (au = ou as in pout). I took up to pre-calc in college. My major didn't require calc or diffy q's or anything so some of these symbols used in these formulas are foreign to me. Thanks for helping me understand!
                              -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                              Comment

                              • Longbow
                                Badcaps Veteran
                                • Jun 2011
                                • 623
                                • USA

                                #16
                                Re: Purpose of the cap in this RC Debouncer circuit...

                                Originally posted by Spork Schivago
                                We can finally move away from TTL logic and stick with mainly CMOS type ICs now.
                                Quick note on this topic: everything has its place. You must look at the application to see which approach is likely to work best. Unfortunately these circuits don't exist in a vacuum. Maybe TTL is a better choice when used in an automotive environment, for example (due to its lower impedance = less likely to be affected by EMI).

                                You might look up the massive literature available on switch debouncing and see that there are a variety of ways to do it. I don't care for the particular example shown but it will work in non-critical circuits. A quick look at a typical data sheet for CMOS will tell you the maximum rise time for an input. Slower rise times will cause the chip to oscillate, negating the purpose of the debouncer circuit. Adding a little positive feedback or the use of a Schmidt trigger will stabilize a debouncer.

                                You are over-teching the time constant aspect. RxC gives you some information about how many input events your circuit can handle per unit time, but exact calculation is rarely important. Knowing what type of IC is significant for 2 reasons: because the input impedance of the IC directly affects the time constant in a simple circuit as above, and also that the defined logic threshold voltage is different for TTL than for CMOS. (the voltage which the chip considers to be a 0 or a 1). So for a TTL chip, that point is about 1.8volts, while for a 5 volt CMOS chip it will be around 2.5 volts.

                                Why not throw this circuit together on a board and observe the results with various parts values?
                                Last edited by Longbow; 12-22-2015, 09:14 AM.
                                Is it plugged in?

                                Comment

                                • stj
                                  Great Sage 齊天大聖
                                  • Dec 2009
                                  • 30977
                                  • Albion

                                  #17
                                  Re: Purpose of the cap in this RC Debouncer circuit...

                                  it's worh pointing out that there may be an internal pullup/down resistor on the input on some chips.

                                  pic's have switchable internal pullups for example.

                                  Comment

                                  • Spork Schivago
                                    Badcaps Legend
                                    • Mar 2012
                                    • 4734
                                    • United States of America

                                    #18
                                    Re: Purpose of the cap in this RC Debouncer circuit...

                                    Originally posted by Longbow
                                    Quick note on this topic: everything has its place. You must look at the application to see which approach is likely to work best. Unfortunately these circuits don't exist in a vacuum. Maybe TTL is a better choice when used in an automotive environment, for example (due to its lower impedance = less likely to be affected by EMI).

                                    You might look up the massive literature available on switch debouncing and see that there are a variety of ways to do it. I don't care for the particular example shown but it will work in non-critical circuits. A quick look at a typical data sheet for CMOS will tell you the maximum rise time for an input. Slower rise times will cause the chip to oscillate, negating the purpose of the debouncer circuit. Adding a little positive feedback or the use of a Schmidt trigger will stabilize a debouncer.

                                    You are over-teching the time constant aspect. RxC gives you some information about how many input events your circuit can handle per unit time, but exact calculation is rarely important. Knowing what type of IC is significant for 2 reasons: because the input impedance of the IC directly affects the time constant in a simple circuit as above, and also that the defined logic threshold voltage is different for TTL than for CMOS. (the voltage which the chip considers to be a 0 or a 1). So for a TTL chip, that point is about 1.8volts, while for a 5 volt CMOS chip it will be around 2.5 volts.

                                    Why not throw this circuit together on a board and observe the results with various parts values?
                                    Thank you! So TTL is still needed. I didn't know that TTL ICs were less prone to EMI. Thank you for sharing that. So I hardly ever need to calculate how long it takes for a cap to charge to 67% of it's full charge or to discharge to 37% of it's initial voltage? R*C should be enough? Thank you. I know ohms times farads = seconds. Saw that in the article Keeney123 posted.

                                    I want to build the circuit because I'm struggling very much implementing a software debouncing routine. I've seen a bunch of source codes but they all seem to involve using interrupts and I didn't want to use an interrupt right now. I've found some that don't use interrupt. I thought right now, it'd be best using someone elses code instead of mine, just to get the debouncer stuff taken care of. William Dillion had some debouncing code that I tried using. I can get the LEDs to turn on just fine, but when I try to turn them off, I end up with the bouncing problem again. I think maybe I need a delay or something in there before turning off the LEDs. I can share the code if you're interested.

                                    As for building the circuit, I don't have the 74AHCT14 inverter. I do have some older chips from the late 90's / very early 2000's that I bought at Radio Shack, back when they carried a bunch of ICs. I'm wondering if I could use some of them. I believe my CD74HCT74E might have an inverter built into it but it's been so long since I've played with digital logic that I'm gonna have to study it a good deal. These are the ICs I currently have:

                                    CD74HCT74E ( High Speed CMOS Logic Dual Positive-Edge-Triggered D Flip-Flops with Set and Reset )

                                    74HCT74N ( Dual D-type flip-flop with set and
                                    reset; positive-edge trigger )

                                    CD4027BCN ( Dual J-K Master/Slave Flip-Flop with Set and Reset )
                                    SIL 4516BE ( Binary up / down counter )

                                    CD74HCT138E (High Speed CMOS Logic 3-to-8 Line Decoder/Demultiplexer Inverting and Non-Inverting )

                                    MC14017BCP ( Decade Counter)
                                    BA10324A ( Ground Sense Operational Amplifiers )
                                    BA546 ( 6V/330mW single-channel power amplifier )

                                    There's a few ICs in this kit I got when Radio Shack was going out of business, a Make: Electronics Pro kit, one and two. I'll check to see if an inverter is in there...
                                    -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                                    Comment

                                    • Spork Schivago
                                      Badcaps Legend
                                      • Mar 2012
                                      • 4734
                                      • United States of America

                                      #19
                                      Re: Purpose of the cap in this RC Debouncer circuit...

                                      Ooo! I found an inverter. It's an open-collector inverter (SN74LS06N). Maybe I could use this.
                                      -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                                      Comment

                                      • Spork Schivago
                                        Badcaps Legend
                                        • Mar 2012
                                        • 4734
                                        • United States of America

                                        #20
                                        Re: Purpose of the cap in this RC Debouncer circuit...

                                        Originally posted by stj
                                        it's worh pointing out that there may be an internal pullup/down resistor on the input on some chips.

                                        pic's have switchable internal pullups for example.
                                        Yes, I have disabled the pullups because I'm setting the inputs to high and then when the button is pushed, it pulls them to low. Originally, I was doing it the opposite way and had the internal pullups enable. I would have the inputs set to low and when the buttons where pressed, they'd go high. However, people on the MicroChip forums suggested against this and said normally, it's best to have the switches go low and normal inputs high.
                                        -- Law of Expanding Memory: Applications Will Also Expand Until RAM Is Full

                                        Comment

                                        Related Topics

                                        Collapse

                                        Working...