Basic Electronics, Chapter 4: Challenge 3 solution (debounce and the relay coil) (a) Debounce on a 3.3 V input, Rp = 10 k, bounce gaps up to 6 ms During a gap the capacitor charges from about 0 V through Rp. It must stay below 0.3 x Vcc, i.e. the fraction f = 0.3 of the supply: t_gap = -tau x ln(1 - 0.3) = 0.3567 x tau Need t_gap >= 6 ms: tau >= 6 ms / 0.3567 = 16.8 ms C >= tau / Rp = 16.8 ms / 10,000 = 1.68 uF E6 choices: 1.5 uF gives tau = 15 ms and t_gap = 5.35 ms (NOT enough); 2.2 uF gives tau = 22 ms and t_gap = 0.3567 x 22 = 7.85 ms (OK). Choose 2.2 uF. Release delay (to 0.7 x Vcc): t = -tau x ln(1 - 0.7) = 1.204 x 22 ms = 26.5 ms With Rs = 100 ohm: peak discharge current = 3.3 V / 100 ohm = 33 mA (when the button closes onto a full capacitor) discharge time constant = 100 x 2.2e-6 = 0.22 ms time to fall to 0.3 x Vcc = 1.204 x 0.22 ms = 0.265 ms (the press is detected almost at once) Pressed, steady: pin = 3.3 x 100 / (10,000 + 100) = 0.033 V (a clear logic 0). (b) 12 V relay coil, R = 240 ohm, L = 240 mH Final current: I = V / R = 12 / 240 = 50 mA Time constant: tau = L / R = 0.24 / 240 = 1 ms Current rise: i(t) = 50 mA x (1 - e^(-t / 1 ms)) Time to 90 %: t = tau x ln(10) = 2.30 ms Stored energy: E = 1/2 L I^2 = 0.5 x 0.24 x 0.05^2 = 0.5 x 0.24 x 0.0025 = 3.0e-4 J = 300 uJ Spike if the transistor cuts the current to zero in 2 us: v = L x di/dt = 0.24 x (0.050 / 2e-6) = 0.24 x 25,000 = 6,000 V This is the theoretical figure: in practice the transistor's junction breaks down or a spark forms long before that. Either way the transistor is endangered. With a flyback diode (ignoring its 0.7 V drop), the current circulates through the diode and the coil's own resistance, decaying as 50 mA x e^(-t / tau), tau = L / R = 1 ms: 10 % of 50 mA = 5 mA when e^(-t / tau) = 0.1 -> t = tau x ln 10 = 2.30 ms (Including the diode's 0.7 V drop, the current falls a little faster: i(t) = (I0 + Vd/R) x e^(-t/tau) - Vd/R, with Vd/R = 2.9 mA, reaches 5 mA at t = 1.90 ms.) The switched node then rises only to about 12 V + 0.7 V = 12.7 V, which is harmless. Checklist - Debounce gap rule: t_gap = 0.357 x Rp x C (for the 0.3 x Vcc low threshold). - Series resistor protects the contacts and the capacitor; it costs nothing at the press. - Every coil switched by a transistor or pin needs a flyback diode, cathode to the supply side.