def test_close_values_at_limit(self): resistors = get_resistors("E12", ORDERS_RESISTOR) r0_9 = EngineerNumber(0.9, ONE) M101 = EngineerNumber(10.1, MEGA) self.assertEqual(EngineerNumber(1), close_values(r0_9, "up", resistors)) self.assertEqual(EngineerNumber("10M"), close_values(M101, "down", resistors))
def test_close_values_out_of_range(self): resistors = get_resistors("E12", ORDERS_RESISTOR) r0_9 = EngineerNumber(0.9, ONE) M101 = EngineerNumber(10.1, MEGA) self.assertIsNone(close_values(r0_9, "down", resistors)) self.assertIsNone(close_values(M101, "up", resistors))
def test_make_resistors(self): resistors = get_resistors("E12", ORDERS_RESISTOR) resistors_ = tuple(str(x) for x in resistors) expected = ( "1.000", "1.200", "1.500", "1.800", "2.200", "2.700", "3.300", "3.900", "4.700", "5.600", "6.800", "8.200", "10.000", "12.000", "15.000", "18.000", "22.000", "27.000", "33.000", "39.000", "47.000", "56.000", "68.000", "82.000", "100.000", "120.000", "150.000", "180.000", "220.000", "270.000", "330.000", "390.000", "470.000", "560.000", "680.000", "820.000", "1.000k", "1.200k", "1.500k", "1.800k", "2.200k", "2.700k", "3.300k", "3.900k", "4.700k", "5.600k", "6.800k", "8.200k", "10.000k", "12.000k", "15.000k", "18.000k", "22.000k", "27.000k", "33.000k", "39.000k", "47.000k", "56.000k", "68.000k", "82.000k", "100.000k", "120.000k", "150.000k", "180.000k", "220.000k", "270.000k", "330.000k", "390.000k", "470.000k", "560.000k", "680.000k", "820.000k", "1.000M", "1.200M", "1.500M", "1.800M", "2.200M", "2.700M", "3.300M", "3.900M", "4.700M", "5.600M", "6.800M", "8.200M", "10.000M") for x in resistors: self.assertIsInstance(x, EngineerNumber) self.assertEqual(expected, resistors_)
def brute_force_to_look_for_rc(c2=None, e_series_resistors="E12", e_series_capacitors="E6", orders_resistor=ORDERS_RESISTOR, orders_capacitor=ORDERS_CAPACITOR): resistors = get_resistors(e_series_resistors, orders_resistor) if not c2: capacitors = get_capacitors(e_series_capacitors, orders_capacitor) else: capacitors = (c2, ) r_combinations_with_replacement = list( combinations_with_replacement(resistors, 3)) parameters = [None] * (len(r_combinations_with_replacement) * len(resistors) * len(capacitors)) i = 0 for c2, r4 in product(capacitors, resistors): for r5, r3, r1 in r_combinations_with_replacement: le = c2 * (r1 * r3 * r5) / r4 kwds = {} for name in NAMES: kwds[name] = locals()[name] si = SimlatedInductor(**kwds) # print("i =", i) parameters[i] = si i += 1 return parameters
def brute_force_LMC555(resistor_e_sesires, capacitor_e_sesires): resistors = get_resistors(resistor_e_sesires, ORDERS_RESISTOR) capacitors = get_capacitors(capacitor_e_sesires, ORDERS_CAPACITOR) combi_rbra = tuple(product(resistors, resistors)) len_combinations = len(combi_rbra) * len(capacitors) # print("len(resistors) ** 2 =", len(resistors) ** 2) # print("len(combi_rbra) =", len(combi_rbra)) # print("len(capacitors) =", len(capacitors)) # print("len_combinations =", len_combinations) # print("len(resistors) ** 2 * len(capacitors) / len_combinations =", len(resistors) ** 2 * len(capacitors) / len_combinations) tf = [None] * len_combinations i = 0 for rbra, c in product(combi_rbra, capacitors): rb, ra = rbra tL, tH, t, f = lmc555(ra, rb, c) dutyL = tL / t dutyH = 1 - dutyL kwds = {} for name in NAMES: kwds[name] = locals()[name] l555 = LMC555(**kwds) tf[i] = l555 i += 1 tf = tf[:i] return tf
def brute_force_LMC555(resistor_e_sesires, capacitor_e_sesires): resistors = get_resistors(resistor_e_sesires, ORDERS_RESISTOR) capacitors = get_capacitors(capacitor_e_sesires, ORDERS_CAPACITOR) len_combinations = len(resistors) * len(capacitors) # print("len(resistors) =", len(resistors)) # print("len(capacitors) =", len(capacitors)) # print("len_combinations =", len_combinations) tf = [None] * len_combinations i = 0 for rc, c in product(resistors, capacitors): t, f = lmc555_fifty_duty(rc, c) duty = EngineerNumber("0.5") kwds = {} for name in NAMES: kwds[name] = locals()[name] l555 = LMC555(**kwds) tf[i] = l555 i += 1 tf = tf[:i] return tf
def brute_force_to_look_for(c3=None, e_series_resistors="E12", e_series_capacitors="E6", orders_resistor=ORDERS_RESISTOR, orders_capacitor=ORDERS_CAPACITOR): resistors = get_resistors(e_series_resistors, orders_resistor) if not c3: capacitors = get_capacitors(e_series_capacitors, orders_capacitor) else: capacitors = c3 r_combinations_with_replacement = list( combinations_with_replacement(resistors, 2)) parameters = [None] * (len(r_combinations_with_replacement)**2 * len(capacitors)) i = 0 for r1r5, r2r4 in product(r_combinations_with_replacement, r_combinations_with_replacement): r1, r5 = r1r5 r2, r4 = r2r4 for c3 in capacitors: ce = c3 * (r1 * r5) / (r2 * r4) kwds = {} for name in NAMES: kwds[name] = locals()[name] cm = CapacitanceMultiplier(**kwds) # print("i =", i) parameters[i] = cm i += 1 return parameters
def test_close_values_same_exponent(self): k47 = EngineerNumber(47, 3) k50 = EngineerNumber(50, 3) k56 = EngineerNumber(56, 3) resistors = get_resistors("E12", ORDERS_RESISTOR) self.assertEqual(k56, close_values(k50, "up", resistors)) self.assertEqual(k47, close_values(k50, "down", resistors))
def test_close_values_transfer_next_exponent(self): resistors = get_resistors("E12", ORDERS_RESISTOR) r83 = EngineerNumber(8.3, 1) r100 = EngineerNumber(1.0, 2) self.assertEqual(r100, close_values(r83, "up", resistors)) k094 = EngineerNumber(0.94, 3) r820 = EngineerNumber(8.2, 2) self.assertEqual(r820, close_values(k094, "down", resistors))
def brute_force_to_look_for_gain_and_Pce(Vcc, ic, hfe, e_series, orders=ORDERS_RESISTOR): resistors = get_resistors(e_series, orders) combi_RcRe = tuple(combinations_with_replacement(resistors, 2)) parameters = [None] * len(combi_RcRe) # print("len(resistors)={}".format(len(resistors))) # print("len(resistors) ** 2 ={}".format(len(resistors) ** 2)) # print("len(combi_RcRe)={}".format(len(combi_RcRe))) # print("len(resistors) ** 2 / len(combi_RcRe) ={}".format(len(resistors) ** 2 / len(combi_RcRe))) i = 0 for Rc, Re in combi_RcRe: eca = _emitter_common_amplifier(Vcc, ic, hfe, Rc, Re, resistors) if eca: parameters[i] = eca i += 1 return parameters[:i]
def brute_force_umeppi(resistor_e_sesires, capacitor_e_sesires): orders_resistor = range(KILO, MEGA + 1) orders_capacitor = range(PICO, MICRO + 3) resistors = get_resistors(resistor_e_sesires, orders_resistor) capacitors = get_capacitors(capacitor_e_sesires, orders_capacitor) len_combinations = (len(resistors)**2) * len(capacitors) # print("len(resistors) =", len(resistors)) # print("len(capacitors) =", len(capacitors)) # print("len_combinations =", len_combinations) uc = [None] * len_combinations i = 0 for c in capacitors: c_0693 = 0.693 * c for rb in resistors: tb = c_0693 * rb if not tb > TB: continue for ra in resistors: if not ra / rb > RARB: continue ta = c_0693 * ra + tb if not ta <= TA: continue T = ta + tb kwds = {} for name in NAMES: kwds[name] = locals()[name] ucs = UmeppiConstants(**kwds) uc[i] = ucs i += 1 uc = uc[:i] return uc
def look_for_optimized_gain(gain, ic, Vcc, hfe=200, e_series="E12", orders=ORDERS_RESISTOR): resistors = get_resistors(e_series, orders) gain_ = gain parameters = [] # print("resistors =", resistors) for Rc in resistors: d = {} ie = ic + ic / hfe Vc = Rc * ic # 6 Re = Rc / gain_ Re_ = close_values(Re, "up", resistors) if not Re_: continue Re = Re_ Ve = Re * ie # 注意 # must be Vc + Ve <= Vcc if Vc + Ve > Vcc: # raise ValueError("invalid Vc and Ve combination compare Vcc.") # print("added(Vc={}, Ve={})={} is greater ghan Vcc={}.".format(Vc, Ve, Vc + Ve, Vcc)) continue gain = Vc / Ve Vce = Vcc - (Vc + Ve) # 7 Pce = Vce * ic # 8 # Pce は小さきこと。 # 2SC1815 の場合, # Pce < 400mW(=PD) Vb = Ve + 0.6 # 9 Vcb = Vcc - Vb # hfe = 200 # 10 ib = ic / hfe # ? ibias = 10 * ib # 11 Rb2 = Vb / ibias # 12 Rb1 = Vcb / ibias # 13 Rb2_ = close_values(Rb2, "down", resistors) Rb1_ = close_values(Rb1, "down", resistors) Rb2, Rb1 = Rb2_, Rb1_ if (not Rb2) or (not Rb1): # print("--") # print("Rb2={}, Rb2_={}".format(Rb2, Rb2_)) # print("Rb1={}, Rb1_={}".format(Rb1, Rb1_)) continue Radd = Rb1 + Rb2 # print("Radd =", Radd) ibias = Vcc / Radd kwds = {} for name in NAMES: kwds[name] = locals()[name] eca = EmitterCommonAmp(**kwds) parameters.append(eca) parameters.sort(key=lambda parameter: math.fabs(gain_ - parameter.gain)) # print("parameters =") # print(parameters) return parameters
def test_close_values_eq_down(self): resistors = get_resistors("E24", ORDERS_RESISTOR) k15 = EngineerNumber(15, 3) self.assertEqual(EngineerNumber(15, 3), close_values(k15, "down", resistors))