{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Custom Solution\n",
    "\n",
    "Starting from a board and firmware (miniROV Light controller) that already checks many of the boxes, we can get a DAC with 16-bit resolution and only need some minor signal conditioning to drive the &plusmn;10V or even better directly drive the servos themselves. We also get the ability to ingest data and mirror it on registers from a sensor like the tilt sensor.\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Bipolar +/-10V Analog Output from a Unipolar Voltage Output DAC\n",
    "\n",
    "Image below taken from a [TI app note](http://www.ti.com/lit/ug/slau525/slau525.pdf)\n",
    "\n",
    "![Bipolar Analog](./files/TI_BIPOLAR_REF.PNG)\n",
    "\n",
    "The transfer equation is:\n",
    "\n",
    "\\begin{equation}\n",
    "V_{OUT} = \\left(1 + \\frac{R_{FB}}{R_{G2}} + \\frac{R_{FB}}{R_{G1}}\\right)V_{DAC} - \\frac{R_{FB}}{R_{G2}}V_{REF}\n",
    "\\end{equation}\n",
    "\n",
    "Let $V_{REF} = 5$ and solve for the case when $V_{OUT} = -10$ and $V_{DAC} = 0$\n",
    "\n",
    "We get the relationship:\n",
    "\n",
    "\\begin{equation}\n",
    "2R_{G2} = R_{FB}\n",
    "\\end{equation}\n",
    "\n",
    "Now let $V_{REF} = 5$ and solve for the case when $V_{OUT} = 10$ and $V_{DAC} = 5$\n",
    "\n",
    "We get:\n",
    "\n",
    "\\begin{equation}\n",
    "R_{G1} = R_{FB}\n",
    "\\end{equation}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "R_G1 = 16500, R_G2 = 8250, R_FB = 16500\n"
     ]
    }
   ],
   "source": [
    "#Seed R_G2\n",
    "R_G2 = 8.25e3\n",
    "R_FB = 2*R_G2\n",
    "R_G1 = R_FB\n",
    "print(f'R_G1 = {R_G1:g}, R_G2 = {R_G2:g}, R_FB = {R_FB:g}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "So now our circuit looks like this: \n",
    "\n",
    "![lt spice simulation](./files/ltspice_dac_to_bipolar.png)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "Using a LT6020 with a AD8397 unity gain buffer, we get the following bode plot for this stage:\n",
    "\n",
    "![bode plot of the out of the dac to bipolar output](./files/bode_dac_to_bipolar.PNG)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Servo Drive using the Howland Current Pump\n",
    "\n",
    "As laid out in this app notes from TI, [AN-1515](http://www.ti.com/analog/docs/litabsmultiplefilelist.tsp?literatureNumber=snoa474a&docCategoryId=1&familyId=1562), and since the range of currents, despite the large inductances make this a conveinient and highly accurate solution if tuned properly. \n",
    "\n",
    "For our solution, we will test feasibility again in SPICE, and see that a wide variety of 1-ampere, wide voltage op-amps can perform this task well. Our selection for test is again the [AD8397](https://www.analog.com/en/products/ad8397.html#product-tools). We can model the circuit below:\n",
    "\n",
    "![](./files/ltspice_bipolar_to_current.png)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "Which for the same AC analysis above provides the following response in current:\n",
    "\n",
    "![](./files/bode_bipolar_to_current.png)\n",
    "\n",
    "Here we can see that the circuit has the ability to modify voltage gain to keep the current output response flat, through 10kHz. Without belaboring the point, you can see we have the ability in this model to also test against the other coil options, a change to $R1$ will change the maximum output current, so future designs will have these range output control options. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " Coil Current: 0.04-amperes => R1 = 250.0-ohms\n",
      " Coil Current: 0.02-amperes => R1 = 500.0-ohms\n",
      " Coil Current: 0.01-amperes => R1 = 1,000.0-ohms\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "r_1 = lambda v,i:v/i\n",
    "v_in = 10\n",
    "\n",
    "coil_currents = np.array([0.040, 0.020, 0.010])\n",
    "coil_resistances = np.array([80, 200, 1000])\n",
    "\n",
    "for current in coil_currents:\n",
    "    print(f' Coil Current: {current:g}-amperes => R1 = {r_1(v_in, current):,}-ohms')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Component Selection\n",
    "\n",
    "#### Amplifiers\n",
    "\n",
    "We already know the amplifiers of interest, they are:\n",
    "  * 0-5 to &plusmn;10 stage: [LT6020](https://www.analog.com/en/products/lt6020.html)\n",
    "  * 36V 100mA Amplifier for current output: [AD8397](https://www.analog.com/en/products/ad8397.html)\n",
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "#### DC/DC\n",
    "\n",
    "To drive the amplifiers, we need DCDC that can source the following currents:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Expected Maximum Watts for 2 channels is 1.2\n"
     ]
    }
   ],
   "source": [
    "v_max = 15 #volts\n",
    "i_max = v_max*coil_currents\n",
    "print(f'Expected Maximum Watts for 2 channels is {2*np.max(i_max)}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "So, since most dual supplies are power rated for total watts in swing, we need $>2.4W$ supply\n",
    "\n",
    "A good contender is the [Recom REC-SRW Series](https://www.digikey.com/product-detail/en/recom-power/REC3-2415DRWZ-H2-A-M-SMD/945-2829-ND/2316847) of 3W converters, with 9-36V input and &plusmn;100mA outputs at 15V."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "#### Quad Matched Resistors\n",
    "\n",
    "The current pump requires tightly matched quad resistor network in order not to have erroneous outputs, we are best advised to leverage a quad network. The [ACAS Series](https://www.digikey.com/product-detail/en/vishay-beyschlag/ACASA1003S1003P100/749-1031-2-ND/4725778) from Vishay has 0.05% matching and overall 0.1% tolerance. \n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "celltoolbar": "Slideshow",
  "kernelspec": {
   "display_name": "Python 3",
   "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.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
