C226 of 30
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

C2 · Lesson 26 · Sandbox

Choosing time constants for real jobs

A mechanical switch doesn't close cleanly. Its contacts bounce for a millisecond or so, and a microcontroller watching it would count a single press as a dozen. An RC filter smooths the bounces away, but only if its time constant is long enough to ignore them and short enough that a real press still gets through promptly. Picking that τ, and picking parts for a timer or for protecting a transistor from a coil's kick, are the design problems in this sandbox. Each one is graded by simulating what you built.

Play

  • A bouncing switch is modeled as a fast square wave for the first few milliseconds. The RC filter's output should stay low during the bounce, then rise once the switch settles.
  • Slide R and C. Find values where the bounce barely moves the output. How long does the output then take to rise?

Predict

A debounce filter must ignore bounce lasting 2 ms but pass a real press within 30 ms. Which time constant fits?

Name it

Designing with τ

A timer. A capacitor charging from 0 toward Vs crosses a threshold Vt at

t=RCln⁡VsVs−Vt

Pick C first (from the values you can buy, and large enough that stray capacitance doesn't matter), then solve for R. Keep R in the kilohms to megohms: too small wastes current, too large makes leakage currents matter.

A debounce filter has two requirements pulling in opposite directions:

  • ignore the bounce: during bounce lasting tb, the output must stay below the logic threshold, which roughly needs τ≫tb;
  • respond promptly: after a real press, the output must cross the threshold within the allowed time.

Microcontrollers usually add a Schmitt trigger input (two thresholds, C6) so the slowly rising output switches cleanly once.

Protecting a switch from a coil. A flyback diode clamps the kick near the supply but makes the coil release slowly. A resistor Rs in series speeds the release and raises the spike to about Vs+0.7+I0Rs. Choose the largest Rs whose spike the transistor can survive.

Worked example

A timer charges 1 µF toward 5 V and must cross 2.5 V after 10 ms. What resistor?

Show the solution
  1. Time to cross 2.5 V. t=RCln⁡55−2.5=RCln⁡2
  2. Solve for R. R=0.0110−6×0.693Ω=14.4kΩ
  3. Nearest standard part. 15 kΩ from E24 gives 10.4 ms.

Answer 14.4 kΩ; the E24 value of 15 kΩ gives 10.4 ms.

Worked example

A debouncer of 100 kΩ and 0.1 µF from 5 V: how long after a clean press does it reach 2.5 V, and how high can 2 ms of bounce push it?

Show the solution
  1. Time constant. τ=100kΩ×0.1μF=10ms
  2. After a clean press. It crosses 2.5 V after t=10×ln⁡2ms=6.9ms
  3. The worst bounce. Even if the contact stayed closed through all 2 ms of bounce, the output would reach only v=5(1−e−0.2)V=0.9V well below the threshold.

Answer it reaches 2.5 V 6.9 ms after a clean press, and 2 ms of bounce can push it to only 0.9 V.

Check

Choose R1 and C1 so the capacitor reaches 3 V exactly 10 ms after the 5 V step.

Type values the way you would write them on a schematic: 4.7k, 100n, 10m. Then try them: the circuit runs with your values and is measured.

Check

Choose R1 and C1 so that 2 ms of contact bounce (modeled as a 1 kHz square wave) never lifts the output above 1 V.

Type values the way you would write them on a schematic: 4.7k, 100n, 10m. Then try them: the circuit runs with your values and is measured.

Check

The same filter must also let a steady press through: choose R1 and C1 so the output passes 4 V within 30 ms of a clean 5 V step.

Type values the way you would write them on a schematic: 4.7k, 100n, 10m. Then try them: the circuit runs with your values and is measured.

Check

A transistor switches a 100 mH, 100 Ω relay coil from 12 V. Choose the resistor RD in series with the flyback diode so the drain never goes above 30 V.

Type values the way you would write them on a schematic: 4.7k, 100n, 10m. Then try them: the circuit runs with your values and is measured.

Explain why

Why does a debounce filter's time constant have both a lower and an upper limit?

Practice

Keep practicing

4 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.