Basic Electronics, Chapter 7: Challenge 2 solution (comparators and hysteresis) Formulas: Vin(switch) = Vref x (1 + R1/Rf) - Vout x (R1/Rf) rising threshold VH = Vref x (1 + R1/Rf) - Vl x R1/Rf (output LOW before switching, Vl = 0) falling threshold VL = Vref x (1 + R1/Rf) - Vh x R1/Rf (output HIGH before switching, Vh = Vcc) hysteresis = VH - VL = (Vh - Vl) x R1/Rf NTC: R = R0 x exp( B x (1/T - 1/T0) ) T = 1 / ( 1/T0 + ln(R/R0)/B ) Vs = 3.3 x Rb / (Rt + Rb) (a) 5 V rail-to-rail comparator, Vref = 2.5 V, R1 = 10 k, Rf = 220 k: R1/Rf = 0.04545 VH = 2.5 x 1.04545 - 0 = 2.614 V VL = 2.614 - 5 x 0.04545 = 2.614 - 0.227 = 2.386 V hysteresis = 5 x 0.04545 = 0.227 V (b) Fan: ON at 40 C, OFF at 35 C; NTC 10 k (B = 3950) on top, 10 k below, 3.3 V. Vs rises with temperature, so a non-inverting comparator (Vs through R1 to the + input, Vref on the - input) turns the fan on when it gets warm. 1. Resistances: R(40 C) = 10 k x exp(3950 x (1/313.15 - 1/298.15)) = 10 k x exp(-0.6347) = 5.301 k R(35 C) = 10 k x exp(3950 x (1/308.15 - 1/298.15)) = 10 k x exp(-0.4300) = 6.506 k 2. Divider voltages: Vs(40 C) = 3.3 x 10 / (5.301 + 10) = 2.157 V Vs(35 C) = 3.3 x 10 / (6.506 + 10) = 1.999 V VH = 2.157 V (rising, fan ON), VL = 1.999 V (falling, fan OFF) hysteresis = 0.157 V 3. R1 / Rf = hysteresis / Vcc = 0.157 / 3.3 = 0.0477 -> Rf = 10 k / 0.0477 = 210 k -> E12 value 220 k (R1/Rf = 0.04545) 4. Vref from VH = Vref x (1 + R1/Rf): Vref = 2.157 / 1.04545 = 2.063 V Divider from 3.3 V: ratio 2.063 / 3.3 = 0.625. 12 k (top) and 20 k (bottom, two 10 k in series): Vref = 3.3 x 20 / 32 = 2.0625 V 5. Actual thresholds: VH = 2.0625 x 1.04545 = 2.156 V VL = 2.156 - 3.3 x 0.04545 = 2.156 - 0.150 = 2.006 V Temperatures: VH: Rt = 10 k x (3.3/2.156 - 1) = 5.305 k -> 39.98 C (fan ON at 40.0 C) VL: Rt = 10 k x (3.3/2.006 - 1) = 6.448 k -> 35.2 C (fan OFF at 35.2 C) The thermistor divider has a source resistance (NTC in parallel with 10 k, about 3.5 k at 40 C) that adds to R1 and so shifts the hysteresis; put a follower between the divider and R1, as the build does, or make R1 and Rf much larger. The 12 k / 20 k reference draws 3.3 / 32 k = 0.1 mA; it is "stiff" because it only feeds a high-impedance input. (c) Stage A with Rf = 47 k: R1/Rf = 10 / 47 = 0.2128 VH = 1.65 x 1.2128 = 2.001 V VL = 2.001 - 3.3 x 0.2128 = 2.001 - 0.702 = 1.299 V hysteresis = 0.702 V LDR resistance at the switch points (LDR on top, 10 k below): rising Vs = 2.001 V: R = 10 k x (3.3 / 2.001 - 1) = 6.49 k (LED ON below 6.5 k) falling Vs = 1.299 V: R = 10 k x (3.3 / 1.299 - 1) = 15.4 k (LED OFF above 15.4 k) (with Rf = 100 k it was 8.18 k and 12.2 k, a hysteresis of 0.33 V) A 50 mV peak-to-peak flicker is well inside both dead bands (0.33 V and 0.70 V), so neither choice can switch falsely because of it. The 47 k design has the wider dead band: the light must change by a ratio of 15.4 / 6.49 = 2.4 : 1 between ON and OFF (against 1.5 : 1 for 100 k), so it is more robust against noise and slow drifts, but less sensitive to small light changes. Checklist - Hysteresis = Vcc x R1/Rf; choose it a few times larger than the noise. - Vref = VH / (1 + R1/Rf) when Vl = 0. - Positive feedback goes to the + input; check which input the signal and which the reference use. - A high-impedance divider needs a buffer, or its source resistance must be added to R1.