{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2b60df67-af61-4ee2-b6a0-ee13f6561239",
   "metadata": {},
   "source": [
    "# Differential-pair NMOS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "343366af-1995-4a87-b4da-6717b0735d76",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Compiling library: SLiCAP.lib.\n",
      "Compiling library: SLiCAPmodels.lib.\n"
     ]
    }
   ],
   "source": [
    "import SLiCAP as sl\n",
    "sl.initProject(\"Differential pair NMOS\", notebook=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "28b2bac4-fe4a-422d-98f3-8a3c38ba6a26",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Creating netlist of kicad/diffpair_n/diffpair_n.kicad_sch using KiCAD\n",
      "Creating drawing-size SVG and PDF images of kicad/diffpair_n/diffpair_n.kicad_sch\n",
      "Plotted to '/home/anton/DATA/www/SEDwebsite/_build/SEDwebsite/EE4109-2024-2025/designExample/HearingLoop/SLiCAPnoiseDesignNotebooks/WithTermination/img/diffpair_n.svg'.\n",
      "Done\n",
      "Checking netlist: cir/diffpair_n.cir\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<figure><img src=\"img/diffpair_n.svg\" alt=\"\" style=\"width:500px\">\n",
       "</figure>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cir=sl.makeCircuit(\"kicad/diffpair_n/diffpair_n.kicad_sch\")\n",
    "sl.img2html(\"diffpair_n.svg\",500)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "7d2dfcdd-6abd-4b39-a901-2f31493811c4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<h3>design specification</h3>\n",
       "<table><a id=\"table_design\"></a><caption>Table design specification </caption><tr><th class=\"left\">symbol</th><th class=\"left\">description</th><th class=\"left\">value</th><th class=\"left\">units</th></tr>\n",
       "<td class=\"left\">$C_{i}$</td><td class=\"left\">Required value of integrator capacitor</td><td class=\"left\">$1.798 \\cdot 10^{-9}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$IC_{N}$</td><td class=\"left\">Inversion coefficient input stage NMOS</td><td class=\"left\">$0.001167$</td><td></td></tr>\n",
       "<td class=\"left\">$ID_{N}$</td><td class=\"left\">Operating current input stage NMOS</td><td class=\"left\">$2.828 \\cdot 10^{-6}$</td><td class=\"left\">$\\mathrm{A}$</td></tr>\n",
       "<td class=\"left\">$I_{fb}$</td><td class=\"left\">Maximum peak-peak current through feedback network</td><td class=\"left\">$4.542 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{A}$</td></tr>\n",
       "<td class=\"left\">$M_{N}$</td><td class=\"left\">Number of fingers input stage NMOS</td><td class=\"left\">$47$</td><td></td></tr>\n",
       "<td class=\"left\">$R_{i}$</td><td class=\"left\">Selected value of integrator resistor</td><td class=\"left\">$8900$</td><td class=\"left\">$\\mathrm{\\Omega}$</td></tr>\n",
       "<td class=\"left\">$Ri_{max}$</td><td class=\"left\">Max. value of integrator resistor</td><td class=\"left\">$8945.0$</td><td class=\"left\">$\\mathrm{\\Omega}$</td></tr>\n",
       "<td class=\"left\">$Ri_{min}$</td><td class=\"left\">Min. value of integrator resistor</td><td class=\"left\">$3380$</td><td class=\"left\">$\\mathrm{\\Omega}$</td></tr>\n",
       "<td class=\"left\">$SRCnoise$</td><td class=\"left\">DIN A weighted RMS output noise, source + termination</td><td class=\"left\">$1.571 \\cdot 10^{-6}$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "<td class=\"left\">$S_{Ri}$</td><td class=\"left\">Squared DIN A weighted RMS output noise due to source and feedback network</td><td class=\"left\">$2.491 \\cdot 10^{-11}$</td><td class=\"left\">$\\mathrm{\\frac{V^{2}}{Hz}}$</td></tr>\n",
       "<td class=\"left\">$W_{F N}$</td><td class=\"left\">Finger width input stage NMOS</td><td class=\"left\">$5.0 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{m}$</td></tr>\n",
       "<td class=\"left\">$W_{N}$</td><td class=\"left\">Selected width input stage NMOS</td><td class=\"left\">$0.00235$</td><td class=\"left\">$\\mathrm{m}$</td></tr>\n",
       "<td class=\"left\">$c_{issN}$</td><td class=\"left\">Selected input capacitance NMOS</td><td class=\"left\">$6.912 \\cdot 10^{-12}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$c_{iss N o}$</td><td class=\"left\">Obtained input capacitance input stage NMOS</td><td class=\"left\">$6.888 \\cdot 10^{-12}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$c_{iss costs minN}$</td><td class=\"left\">Required c_iss NMOS for minimum costs</td><td class=\"left\">$6.912 \\cdot 10^{-12}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$c_{iss g m minN}$</td><td class=\"left\">Required c_issN at g_m_minN</td><td class=\"left\">$9.87 \\cdot 10^{-10}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$g_{mN}$</td><td class=\"left\">Selected transconductance input stage NMOS</td><td class=\"left\">$7.854 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{\\mathtt{\\text{S}}}$</td></tr>\n",
       "<td class=\"left\">$g_{m N o}$</td><td class=\"left\">Obtained transconductance input stage NMOS</td><td class=\"left\">$7.854 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{\\mathtt{\\text{S}}}$</td></tr>\n",
       "<td class=\"left\">$g_{m costs minN}$</td><td class=\"left\">g_m NMOS for minimum costs</td><td class=\"left\">$7.854 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{\\mathtt{\\text{S}}}$</td></tr>\n",
       "<td class=\"left\">$g_{m minN}$</td><td class=\"left\">Minimum transconductance input stage NMOS</td><td class=\"left\">$3.926 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{\\mathtt{\\text{S}}}$</td></tr>\n",
       "<td class=\"left\">$n_{Ri obtained}$</td><td class=\"left\">Relative contribution of source and feedback network to squared DIN A weighted output noise</td><td class=\"left\">$0.199$</td><td></td></tr>\n",
       "</table>\n",
       "<h3>performance specification</h3>\n",
       "<table><a id=\"table_performance\"></a><caption>Table performance specification </caption><tr><th class=\"left\">symbol</th><th class=\"left\">description</th><th class=\"left\">value</th><th class=\"left\">units</th></tr>\n",
       "<td class=\"left\">$L_{s}$</td><td class=\"left\">Source inductance</td><td class=\"left\">$0.12$</td><td class=\"left\">$\\mathrm{H}$</td></tr>\n",
       "<td class=\"left\">$P_{max}$</td><td class=\"left\">Maximum power dissipation at maximum supply voltage</td><td class=\"left\">$0.001$</td><td class=\"left\">$\\mathrm{W}$</td></tr>\n",
       "<td class=\"left\">$R_{s}$</td><td class=\"left\">Source resistance</td><td class=\"left\">$875$</td><td class=\"left\">$\\mathrm{\\Omega}$</td></tr>\n",
       "<td class=\"left\">$R_{t}$</td><td class=\"left\">Termination resistance</td><td class=\"left\">$1.0 \\cdot 10^{4}$</td><td class=\"left\">$\\mathrm{\\Omega}$</td></tr>\n",
       "<td class=\"left\">$V_{DD}$</td><td class=\"left\">Maximum supply voltage</td><td class=\"left\">$1.3$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "<td class=\"left\">$V_{onoise}$</td><td class=\"left\">DIN A weighted output voltage noise</td><td class=\"left\">$1.062 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "<td class=\"left\">$Vi_{ADC}$</td><td class=\"left\">Peak-peak input voltage ADC</td><td class=\"left\">$0.9$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "<td class=\"left\">$Vi_{pp}$</td><td class=\"left\">Maximum peak-peak input voltage</td><td class=\"left\">$0.2932$</td><td></td></tr>\n",
       "<td class=\"left\">$f_{fp}$</td><td class=\"left\">Maximum full-power frequency</td><td class=\"left\">$5000$</td><td class=\"left\">$\\mathrm{Hz}$</td></tr>\n",
       "<td class=\"left\">$f_{max}$</td><td class=\"left\">-3dB low-pass cut-off frequency</td><td class=\"left\">$6000$</td><td class=\"left\">$\\mathrm{Hz}$</td></tr>\n",
       "<td class=\"left\">$f_{min}$</td><td class=\"left\">-3dB high-pass cut-off frequency</td><td class=\"left\">$600$</td><td class=\"left\">$\\mathrm{Hz}$</td></tr>\n",
       "<td class=\"left\">$\\tau_{i}$</td><td class=\"left\">Integration time constant</td><td class=\"left\">$1.6 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{s}$</td></tr>\n",
       "</table>\n",
       "<h3>achievements specification</h3>\n",
       "<table><a id=\"table_achievements\"></a><caption>Table achievements specification </caption><tr><th class=\"left\">symbol</th><th class=\"left\">description</th><th class=\"left\">value</th><th class=\"left\">units</th></tr>\n",
       "<td class=\"left\">$V_{onoise WLI N}$</td><td class=\"left\">DIN A weighted RMS output noise with NMOS, W, L, and ID</td><td class=\"left\">$7.833 \\cdot 10^{-6}$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "<td class=\"left\">$V_{onoise gmCissN}$</td><td class=\"left\">DIN A weighted RMS output noise with NMOS and selected g_m and c_iss</td><td class=\"left\">$9.021 \\cdot 10^{-6}$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "</table>\n",
       "<h3>budgets specification</h3>\n",
       "<table><a id=\"table_budgets\"></a><caption>Table budgets specification </caption><tr><th class=\"left\">symbol</th><th class=\"left\">description</th><th class=\"left\">value</th><th class=\"left\">units</th></tr>\n",
       "<td class=\"left\">$n_{MN}$</td><td class=\"left\">Relative contribution controller NMOS input stagenoise to the squared DIN-A weighted RMS output noise</td><td class=\"left\">$0.5$</td><td></td></tr>\n",
       "<td class=\"left\">$n_{Ri}$</td><td class=\"left\">Relative contribution of R_i noise to the squared DIN-A weighted RMS output noise</td><td class=\"left\">$0.2$</td><td></td></tr>\n",
       "<td class=\"left\">$n_{SRC}$</td><td class=\"left\">Relative contribution of source noise to the squared DIN-A weighted RMS output noise</td><td class=\"left\">$0.02189$</td><td></td></tr>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "specs = sl.csv2specs('A1specs.csv')\n",
    "sl.specs2html(specs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "7dd870fc-75bd-4920-922f-f6a4906704d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "sl.specs2circuit(specs, cir)\n",
    "cir.defPar(\"ID_N\", 0.6*cir.getParValue(\"I_fb\"))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
