0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MOSFET

Last updated at Posted at 2025-08-08

image.png


# 必要なライブラリをインストール(この行は Jupyter 環境用。スクリプト化時は不要)
# !pip install numpy

import numpy as np

# -------------------------------
# 各種定数とパラメータ(ここで一元管理)
# -------------------------------

# デバイス定数
mu_n = 220e-6          # 電子移動度 [m^2/Vs]
C_ox = 1e-2            # 酸化膜容量密度 [F/m^2]
V_T = 0.45             # しきい値電圧 [V]
V_A = 20               # アーリー電圧 [V]

# 動作条件
W = 10e-6              # トランジスタ幅 [m]
L = 0.5e-6             # トランジスタ長さ [m]
V_GS = 1.0             # ゲート-ソース電圧 [V]
V_DS = 1.0             # ドレイン-ソース電圧 [V]

# -------------------------------
# 電流 I_DS の計算(飽和領域)
# -------------------------------

# ID = (μ_n * C_ox / 2) * (W/L) * (V_GS - V_T)^2 * (1 + V_DS / V_A)
beta = mu_n * C_ox * (W / L)  # β = μ_n C_ox (W/L)
ID = 0.5 * beta * (V_GS - V_T)**2 * (1 + V_DS / V_A)

# -------------------------------
# トランスコンダクタンス g_m の計算
# -------------------------------

# g_m = ∂I_D/∂V_GS = μ_n C_ox (W/L)(V_GS - V_T)
gm = beta * (V_GS - V_T)

# または g_m = 2 I_D / (V_GS - V_T)
gm_alt = 2 * ID / (V_GS - V_T)

# -------------------------------
# 出力コンダクタンス g_d の計算
# -------------------------------

# g_d = I_D / (V_A + V_DS)
gd = ID / (V_A + V_DS)

# -------------------------------
# オーバードライブ電圧 V_ov の計算
# -------------------------------

# V_ov = sqrt(2 * I_D / (μ_n * C_ox * (W/L) * (1 + V_DS / V_A)))
V_ov = np.sqrt(2 * ID / (beta * (1 + V_DS / V_A)))

# ゲート電圧 V_GS の再計算(確認用)
V_GS_calc = V_ov + V_T

# -------------------------------
# 結果出力(英語ラベル)
# -------------------------------

print(f"I_D   = {ID:.3e} A")           # ドレイン電流
print(f"g_m   = {gm:.3e} S")           # トランスコンダクタンス(一次式)
print(f"g_m_alt = {gm_alt:.3e} S")     # トランスコンダクタンス(二次式)
print(f"g_d   = {gd:.3e} S")           # 出力コンダクタンス
print(f"V_ov  = {V_ov:.3f} V")         # オーバードライブ電圧
print(f"V_GS(calc) = {V_GS_calc:.3f} V")  # 再計算ゲート電圧

# -------------------------------
# 全処理終了
# -------------------------------
# Program Name: mosfet_vout_analysis.py
# Creation Date: 20250809
# Overview: Compute Vout and small-signal gain for MOSFET in saturation and triode regions
# Usage: Execute this script to simulate Vout behavior based on Vin and extract Av (gain)

!pip install numpy matplotlib

import numpy as np
import matplotlib.pyplot as plt

# --- 定数定義 (Constants) ---
V_DD = 5.0                 # [V] 電源電圧 Supply voltage
V_TH = 1.0                 # [V] しきい値電圧 Threshold voltage
mu_n = 400e-4              # [m^2/Vs] 電子移動度 Electron mobility
C_ox = 5e-3                # [F/m^2] ゲート酸化膜容量 Gate oxide capacitance
W = 10e-6                  # [m] トランジスタ幅 Transistor width
L = 1e-6                   # [m] トランジスタ長 Transistor length
R_D = 10e3                 # [Ohm] ドレイン抵抗 Drain resistance

# --- 派生パラメータ (Derived Parameters) ---
beta = mu_n * C_ox * (W / L)   # トランジスタ定数 Transconductance parameter

# --- 入力電圧範囲 (Input Range) ---
Vin = np.linspace(0, 5, 500)

# --- 出力電圧計算 (Output Voltage Calculation) ---
Vout = np.zeros_like(Vin)

# 飽和領域: Vin < Vout + V_TH
for i, v in enumerate(Vin):
    # 飽和領域 Saturation
    v_saturation = V_DD - (1/2) * R_D * beta * (v - V_TH)**2
    if v < v_saturation + V_TH:
        Vout[i] = v_saturation
    # トライオード領域 Triode
    else:
        Vout[i] = V_DD - R_D * (1/2) * beta * (2 * (v - V_TH) * vout[i-1] - vout[i-1]**2)

# --- 小信号利得計算 (Small Signal Gain) ---
gm = beta * (Vin - V_TH)           # トランスコンダクタンス g_m
Av = -gm * R_D                     # 利得 Gain

# --- プロット Plotting ---
plt.figure()
plt.plot(Vin, Vout)
plt.title("Output Voltage vs Input Voltage")
plt.xlabel("Input Voltage Vin [V]")
plt.ylabel("Output Voltage Vout [V]")
plt.grid()

plt.figure()
plt.plot(Vin, Av)
plt.title("Small-Signal Gain vs Input Voltage")
plt.xlabel("Input Voltage Vin [V]")
plt.ylabel("Gain Av [V/V]")
plt.grid()
plt.show()

image.png

image.png

# Program Name: mosfet_gain_analysis.py
# Creation Date: 20250809
# Overview: Compute MOSFET output voltage and gain in saturation and triode regions
# Usage: Run to evaluate output voltage and gain for varying Vin conditions

!pip install numpy

import numpy as np

# MOSFET Parameters(トランジスタのパラメータ)
V_DD = 5.0          # 電源電圧 [V]
V_TH = 1.0          # 閾値電圧 [V]
mu_n = 500e-4       # 電子移動度 [m^2/Vs]
C_ox = 2.5e-3       # 酸化膜容量 [F/m^2]
W = 10e-6           # チャネル幅 [m]
L = 1e-6            # チャネル長 [m]
R_D = 10e3          # ドレイン抵抗 [Ω]
lambda_val = 0.02   # チャネル長変調係数
I1 = 100e-6         # 定電流源電流 [A]
eta = 0.2           # gm比補正パラメータ

# 関数定義: 飽和領域での出力電圧 Vout(Vin < Vin1)
def Vout_saturation(Vin):
    return V_DD - R_D * 0.5 * mu_n * C_ox * (W / L) * (Vin - V_TH) ** 2

# 関数定義: Triode領域での出力電圧 Vout(Vin > Vin1)
def Vout_triode(Vin, Vout):
    return V_DD - R_D * 0.5 * mu_n * C_ox * (W / L) * (2 * (Vin - V_TH) * Vout - Vout ** 2)

# gm 計算(トランスコンダクタンス)
def gm(Vin):
    return mu_n * C_ox * (W / L) * (Vin - V_TH)

# 増幅率(出力抵抗 r_o を含む小信号利得)
def Av_small_signal(Vin, r_o):
    return -gm(Vin) * r_o

# 静的条件: 飽和領域電流 = I1 から Vin を計算
def Vin_from_I1(I1_val):
    return V_TH + np.sqrt((2 * I1_val) / (mu_n * C_ox * (W / L) * (1 + lambda_val * V_DD)))

# 電圧利得(複数段構成)
def multi_stage_Av(WL1, WL2, eta_val):
    return -np.sqrt(WL1 / WL2) * (1 / (1 + eta_val))

# スモールシグナルゲイン直線近似
def Av_slope(Vin):
    return -R_D * mu_n * C_ox * (W / L) * (Vin - V_TH)

# 動作確認用(Vin1計算)
Vin1 = Vin_from_I1(I1)
Vout_sat = Vout_saturation(Vin1)

# 出力
print(f"Vin1 (I1-based transition point) = {Vin1:.3f} V")
print(f"Vout at saturation (Vin = Vin1) = {Vout_sat:.3f} V")
print(f"Small-signal gain Av = {Av_slope(Vin1):.2f}")
print(f"Multi-stage gain Av = {multi_stage_Av(W/L, W/L * 0.5, eta):.2f}")

image.png

image.png

# Program Name: gain_vs_device_ratio.py
# Creation Date: 20250809
# Overview: Plot Av expressions vs W/L ratio in a common-source amplifier
# Usage: Run this script to visualize how gain varies with device sizing ratio

!pip install matplotlib numpy

import numpy as np
import matplotlib.pyplot as plt

#------------------------------
# パラメータ設定 / Parameter setup
#------------------------------
WL1 = 1  # 入力トランジスタのW/L比 (fixed) / W/L of input transistor
WL2_range = np.linspace(0.1, 20, 500)  # 負荷トランジスタのW/L比 / W/L of load transistor

#------------------------------
# 利得式の定義 / Define gain equations
#------------------------------
Av_sqrt = np.sqrt(WL1 / WL2_range)  # Av = sqrt((W/L)_1 / (W/L)_2)
Av_inv = 1 / WL2_range              # Av = 1 / (W/L)_2

#------------------------------
# グラフ描画 / Plotting
#------------------------------
plt.figure()
plt.plot(WL2_range, Av_sqrt, label='Av = sqrt(WL1 / WL2)')
plt.plot(WL2_range, Av_inv, '--', label='Av = 1 / WL2')

# 軸ラベルとタイトル / Axis labels and title
plt.xlabel('Load Transistor (W/L)2')
plt.ylabel('Voltage Gain Av')
plt.title('Gain vs. (W/L) Ratio')
plt.grid(True)
plt.legend()
plt.tight_layout()
plt.show()
# Program Name: av_vs_overdrive_ratio.py
# Creation Date: 20250809
# Overview: Plot Av vs. overdrive voltage ratio in common-source amplifier
# Usage: Run the script to see gain behavior under Eq (3.35) and (3.37)

!pip install matplotlib numpy

import numpy as np
import matplotlib.pyplot as plt

#------------------------------
# パラメータ設定 / Parameter setup
#------------------------------
VG1_VT1 = 0.2  # M1のオーバードライブ電圧 / Overdrive voltage of M1 (V_GS1 - V_TH1)
VG2_VT2_range = np.linspace(0.1, 1.5, 500)  # M2のオーバードライブ電圧範囲 / Range of V_GS2 - V_TH2

#------------------------------
# Avの2つのモデル / Two Av models
#------------------------------
# Eq (3.35): Av ≈ |V_GS2 - V_TH2| / (V_GS1 - V_TH1)
Av_direct = VG2_VT2_range / VG1_VT1

# Eq (3.37): Av = μn(W/L)_1 (V_GS1 - V_TH1) / μp(W/L)_2 (V_GS2 - V_TH2)
# 簡単化のためμn=μp, (W/L)_1 = (W/L)_2と仮定 / Assume mu_n = mu_p, W/L_1 = W/L_2
Av_inverse = VG1_VT1 / VG2_VT2_range

#------------------------------
# グラフ描画 / Plotting
#------------------------------
plt.figure()
plt.plot(VG2_VT2_range, Av_direct, label='Av ≈ (V_GS2 - V_T2) / (V_GS1 - V_T1)  [Eq 3.35]')
plt.plot(VG2_VT2_range, Av_inverse, '--', label='Av ∝ 1 / (V_GS2 - V_T2)       [Eq 3.37]')

# 軸ラベルとタイトル / Axis labels and title
plt.xlabel('Overdrive Voltage of M2 (V_GS2 - V_T2) [V]')
plt.ylabel('Voltage Gain Av')
plt.title('Gain vs. Overdrive Voltage (Eq 3.35 vs Eq 3.37)')
plt.grid(True)
plt.legend()
plt.tight_layout()
plt.show()

image.png

# Program Name: av_impedance_expression.py
# Creation Date: 20250809
# Overview: Compute Av from complex impedance expression with body effect and output resistance
# Usage: Run to calculate voltage gain Av for given gm, gmb, and ro values

!pip install numpy

import numpy as np

#------------------------------
# パラメータ定義 / Parameter definitions
#------------------------------
gm1 = 1e-3      # M1のgm [S]
gm2 = 1e-3      # M2のgm [S]
gmb1 = 0.2e-3   # M1のgmb [S]
gmb2 = 0.2e-3   # M2のgmb [S]
ro1 = 100e3     # M1のro [Ω]
ro2 = 100e3     # M2のro [Ω]

#------------------------------
# 並列合成関数 / Parallel combination function
#------------------------------
def parallel(*args):
    inv_total = sum(1/x for x in args)
    return 1 / inv_total

#------------------------------
# インピーダンスの各部分計算 / Compute impedances
#------------------------------
Z1 = 1 / (gm2 + gmb2)
Z2 = parallel(ro2, ro1)
Z3 = 1 / gmb1
Z4 = 1 / gm1

#------------------------------
# 分母と分子計算 / Compute numerator and denominator
#------------------------------
numerator = parallel(Z1, Z2, Z3)
denominator = parallel(Z1, Z2, Z3, Z4)

#------------------------------
# 電圧利得計算 / Compute Av
#------------------------------
Av = numerator / denominator

# 結果出力 / Print result
print(f"Voltage Gain Av = {Av:.2f}")

image.png

# Program Name: av_parallel_resistance_gain.py
# Creation Date: 20250809
# Overview: Compute voltage gain Av using parallel output resistances and transconductance
# Usage: Run to calculate Av based on gm1, gm2, ro1, ro2

!pip install numpy

import numpy as np

#------------------------------
# パラメータ定義 / Parameter definitions
#------------------------------
gm1 = 1e-3    # M1のgm [S]
gm2 = 1e-3    # M2のgm [S]
ro1 = 100e3   # M1のro [Ω]
ro2 = 100e3   # M2のro [Ω]

#------------------------------
# 並列合成関数 / Parallel combination function
#------------------------------
def parallel(a, b):
    return 1 / (1/a + 1/b)

#------------------------------
# 電圧利得計算 / Compute Av
# Av = -gm1 * (ro1 || (ro2 || (1/gm2)))
#------------------------------
ro_eq = parallel(ro2, 1/gm2)     # ro2 || 1/gm2
ro_total = parallel(ro1, ro_eq) # ro1 || (ro2 || 1/gm2)
Av = -gm1 * ro_total

# 結果出力 / Print result
print(f"Voltage Gain Av = {Av:.2f}")

image.png

# Program Name: av_divided_current_gain.py
# Creation Date: 20250809
# Overview: Compute voltage gain Av considering source degeneration and impedance division
# Usage: Run to calculate Av from gm1, gm2, gmb2, RP, RD

!pip install numpy

import numpy as np

#------------------------------
# パラメータ定義 / Parameter definitions
#------------------------------
gm1 = 1e-3     # M1のトランスコンダクタンス [S]
gm2 = 1e-3     # M2のトランスコンダクタンス [S]
gmb2 = 0.2e-3  # M2のボディ効果によるトランスコンダクタンス [S]
RP = 10e3      # ソース抵抗 RP [Ω]
RD = 10e3      # ドレイン抵抗 RD [Ω]

#------------------------------
# 電圧利得計算 / Compute voltage gain
# Av = -gm1 * (gm2 + gmb2) * RP * RD / (1 + (gm2 + gmb2) * RP)
#------------------------------
gm2_total = gm2 + gmb2
numerator = gm1 * gm2_total * RP * RD
denominator = 1 + gm2_total * RP
Av = -numerator / denominator

# 結果出力 / Print result
print(f"Voltage Gain Av = {Av:.2f}")

image.png

# Program Name: diff_pair_current_calc.py
# Creation Date: 20250809
# Overview: Computes differential output current (ID1 - ID2) in a differential pair based on Vin1 - Vin2
# Usage: python diff_pair_current_calc.py

# 必要なライブラリのインストール
!pip install numpy matplotlib

import numpy as np
import matplotlib.pyplot as plt

# 定数(デバイスパラメータなど)
mu_n = 300e-4         # 電子移動度 [m^2/Vs](例: 300 cm^2/Vs)
C_ox = 4e-3           # ゲート酸化膜容量 [F/m^2]
W = 10e-6             # トランジスタ幅 [m]
L = 1e-6              # トランジスタ長 [m]
W_over_L = W / L      # W/L 比

I_SS = 200e-6         # バイアス電流 [A]

# Vin1 - Vin2 の範囲(差動入力)[V]
vin_diff = np.linspace(-0.2, 0.2, 500)

# 出力電流 (ID1 - ID2) の計算
# 微分対回路の解析式より:
# ID1 - ID2 = (1/2) * μn * Cox * (W/L) * (Vin1 - Vin2) * [1 - (Vin1 - Vin2)^2 * (μn * Cox * (W/L) / (4 * ISS))]

factor = mu_n * C_ox * W_over_L
term1 = 0.5 * factor * vin_diff
term2 = 1 - (vin_diff**2) * factor / (4 * I_SS)
id_diff = term1 * term2  # ID1 - ID2 [A]

# 結果のプロット
plt.plot(vin_diff, id_diff)
plt.title("Differential Pair Output Current")
plt.xlabel("Vin1 - Vin2 [V]")
plt.ylabel("ID1 - ID2 [A]")
plt.grid(True)
plt.show()

image.png

# Program Name: diff_pair_gain_comparison.py
# Creation Date: 20250809
# Overview: Calculates voltage gain of differential pair when M1 and M2 are at same DC potential
# Usage: python diff_pair_gain_comparison.py

# 必要なライブラリのインストール
!pip install numpy

import numpy as np

# デバイスパラメータ
mu_n = 300e-4        # 電子移動度 [m^2/Vs]
C_ox = 4e-3          # ゲート酸化膜容量 [F/m^2]
W = 10e-6            # トランジスタ幅 [m]
L = 1e-6             # トランジスタ長 [m]
W_over_L = W / L     # W/L 比
I_SS = 200e-6        # バイアス電流(全体)[A]
R_D = 10e3           # ドレイン抵抗 [Ω]

# gm1, gm2 の計算(M1, M2 が同一バイアス電位にあるとき)
# 各トランジスタの電流: I_D1 = I_D2 = I_SS / 3, M2 側は電流2倍
I_D1 = I_SS / 3
I_D2 = 2 * I_D1

gm1 = np.sqrt(2 * mu_n * C_ox * W_over_L * I_D1)
gm2 = np.sqrt(2 * mu_n * C_ox * W_over_L * I_D2)  # = sqrt(2) * gm1 = 2 * gm1

# 利得の計算(式 4.20 および 4.21 に従う)
Av_abs = 2 * R_D / (1/gm1 + 1/(2*gm1))  # |Av| = 2RD / (1/gm1 + 1/(2gm1)) = 4/3 * gm1 * RD

# 結果出力
print("gm1 = {:.2e} S".format(gm1))
print("gm2 = {:.2e} S".format(gm2))
print("|Av| = {:.2f}".format(Av_abs))

image.png

# Program Name: differential_pair_gain.py
# Creation Date: 20250809
# Overview: Computes voltage gain of a differential amplifier with diode-connected and current-source loads
# Usage: python differential_pair_gain.py

# 必要なライブラリをインポート
import math

# ----------- 定数定義(一元管理) -----------
mu_n = 500e-4           # 電子移動度 [m^2/Vs]
mu_p = 250e-4           # 正孔移動度 [m^2/Vs]
W_L_n = 20              # NMOSのW/L比
W_L_p = 10              # PMOSのW/L比
ro_n = 50e3             # NMOS 出力抵抗 [Ohm]
ro_p = 100e3            # PMOS 出力抵抗 [Ohm]
gm_n = mu_n * W_L_n     # g_mN = μ_n * (W/L)_N
gm_p = mu_p * W_L_p     # g_mP = μ_p * (W/L)_P

# ----------- 増幅率の計算(ダイオード接続負荷) -----------

# Av = -gmN / gmP
Av_diode = -gm_n / gm_p

# Av = -sqrt(μn(W/L)_N / μp(W/L)_P)
Av_diode_sqrt = -math.sqrt((mu_n * W_L_n) / (mu_p * W_L_p))

# ----------- 増幅率の計算(電流源負荷) -----------

# ro_total = roN || roP
ro_total = 1 / (1 / ro_n + 1 / ro_p)

# Av = -gmN * (roN || roP)
Av_current_source = -gm_n * ro_total

# ----------- 結果表示 -----------
print("Voltage Gain with Diode-connected Load (Av) =", Av_diode)
print("Voltage Gain with Diode-connected Load (Av: sqrt form) =", Av_diode_sqrt)
print("Voltage Gain with Current Source Load (Av) =", Av_current_source)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?