{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "246c9164-55d2-4a68-bd30-c789d73369ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import math\n",
    "from matplotlib import pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b26d5a3f-177c-452d-a23e-41a5cce6d695",
   "metadata": {},
   "source": [
    "# LDO margining calculations\n",
    "\n",
    "This follows https://www.ti.com/lit/an/sbaa341b/sbaa341b.pdf\n",
    "\n",
    "![](ldo-margining-circuit.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ae4e7b18-37a5-4c13-b8c6-a668192f1d0c",
   "metadata": {},
   "outputs": [],
   "source": [
    "Vref = 0.55\n",
    "Vout = lambda Vdac: Vref + ((Vref/R2) + (Vref - Vdac)/R3)*R1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "74c5f3fe-c8d8-4f7f-bb69-e590386f81b5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 26748 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "R1 = 10e3\n",
    "R2 = 2.2e3\n",
    "R3 = 10e3\n",
    "\n",
    "Vdac = np.linspace(0, 3.3, 500)\n",
    "fig, ax = plt.subplots()\n",
    "ax.plot(Vdac, Vout(Vdac))\n",
    "ax.grid()\n",
    "ax.set_xlabel('$V_{DAC}$')\n",
    "ax.set_ylabel('$V_{out}$')\n",
    "min(Vout(Vdac)), max(Vout(Vdac))\n",
    "plt.savefig('ldo_margin_dac_curve.png')"
   ]
  }
 ],
 "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.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
