예제 #1
0
    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))
예제 #2
0
    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))
예제 #3
0
    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))
예제 #4
0
    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))
예제 #5
0
def _emitter_common_amplifier(Vcc, ic, hfe, Rc, Re, resistors):
    ib = ic / hfe # ?
    ie = ic + ib
    Vc = Rc * ic   # 6
    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))
        return None

    Vce = Vcc - (Vc + Ve) # 7
    gain = Vc / Ve
    Pce = Vce * ic        # 8
    # Pce は小さきこと。
    # 2SC1815 の場合,
    # Pce < 400mW(=PD)

    Vb = Ve + 0.6 # 9
    Vcb = Vcc - Vb

    # hfe = 200 # 10
    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_))
        return None
    Radd = Rb1 + Rb2
    ibias = Vcc / Radd

    kwds = {}
    for name in NAMES:
        kwds[name] = locals()[name]
    eca = EmitterCommonAmp(**kwds)
    return eca
예제 #6
0
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
예제 #7
0
 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))