{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 2 - Power Switching Devices & Their Characteristics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 2.1 page 67"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "VA = 1.10 V\n"
     ]
    }
   ],
   "source": [
    "V1=1    # V across SCR\n",
    "IG=0    # A\n",
    "Ih=2    # mA holding current\n",
    "R=50    # ohm\n",
    "\n",
    "# Applying kirchoff law\n",
    "#VA-(IAK*R)-V1=0\n",
    "VA=(Ih*10**-3*R)+V1    # V (let IAK=Ih)\n",
    "print 'VA = %.2f V'%(VA)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 2.2 page 67"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Minimum duration of gating pulse = 10 us\n"
     ]
    }
   ],
   "source": [
    "diBYdt=1000    # A/s (rate of rise of current)\n",
    "il=10    # mA (latching current = diBYdt * tp)\n",
    "tp=il*10**-3/diBYdt    # s\n",
    "print 'Minimum duration of gating pulse = %.f us'%(tp*10**6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 2.3 page 68"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gate power dissipation = 4 W\n",
      "\n",
      " Resistance to be connected = 14 ohm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "m=16    #  V/A (gradient)\n",
    "t_on=4    #  us\n",
    "IG=500    #  mA\n",
    "VS=15    #  V\n",
    "\n",
    "VG=m*IG/1000    #  V\n",
    "#Load line equation\n",
    "#VG=VS-IG*RS\n",
    "RS=(VS-VG)/(IG/1000)     #  ohm\n",
    "Pg=VS*(IG/1000)**2 # # W\n",
    "print 'Gate power dissipation = %.f W'%(Pg)\n",
    "print '\\n Resistance to be connected = %.f ohm'%(RS)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 2.4 page 68"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Value of resistance to be added in series = 44.11 ohm\n"
     ]
    }
   ],
   "source": [
    "from numpy import roots\n",
    "# VG=0.5+8*IG -- eqn(1)\n",
    "f=400# # Hz\n",
    "delta=0.1 # # (Duty Cycle)\n",
    "P=0.5    # W\n",
    "VS=12    #  V\n",
    "\n",
    "Tp=1/f*10**6    #  us\n",
    "# P= VG*IG -- eqn(2)\n",
    "# solving eqn  1 and 2\n",
    "#8*IG*IG**2+0.5*IG-P=0\n",
    "p=[8, 0.5, -P] # polynomial for IG\n",
    "IG=roots(p)     #  A \n",
    "IG=IG[1]     #  A (discarding -ve value)\n",
    "VG=0.5+8*IG    #  V\n",
    "# VS=VG+IG*RS\n",
    "RS=(VS-VG)/IG\n",
    "print 'Value of resistance to be added in series = %.2f ohm'%(RS)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 2.5 page 69"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Value of resistance to be connected in series = 6.97 ohm\n",
      "\n",
      " Triggering frequency = 5.00 kHz\n",
      "\n",
      " Duty Cycle = 0.1 \n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt\n",
    "# VG=10*IG -- eqn(1)\n",
    "PGM=5    #  W\n",
    "PGav=.5    #  W\n",
    "VS=12    #  V\n",
    "Tp=20    #  us\n",
    "\n",
    "# PGM = VG*IG where VG=10*IG\n",
    "\n",
    "IG=sqrt(PGM/10)    #  A\n",
    "VG=10*IG    #  V\n",
    "# During the application of pulse VS = VG+(IG*RS)\n",
    "RS=(VS-VG)/IG     #  ohm\n",
    "f=PGav/(PGM*Tp*10**-6)/1000    #  kHz\n",
    "delta=f*1000*Tp*10**-6    #  Duty Cycle\n",
    "print 'Value of resistance to be connected in series = %.2f ohm'%(RS)\n",
    "print '\\n Triggering frequency = %.2f kHz'%(f)\n",
    "print '\\n Duty Cycle = %.1f '%(delta)\n",
    "# Note : ans in the textbook is not accurate."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 2.6 page 70"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Value of R = 31.25 kohm\n",
      "\n",
      " Value of C = 1.20e-07 F\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "VS=3    #  kV\n",
    "IS=750    #  A\n",
    "\n",
    "VD=800    #  V\n",
    "ID=175    #  A\n",
    "dr=30/100    #  de-rating factor\n",
    "IB=8    # mA\n",
    "delQ=30    #  u Coulomb\n",
    "# dr = 1-IS/np*ID\n",
    "np = round(IS/(1-dr)/(ID)) # # no. of parallel string\n",
    "ns = round(VS*1000/(1-dr)/(VD)) # # no. of series string\n",
    "R=(ns*VD-VS*1000)/(ns-1)/(IB/1000)/1000    # kohm\n",
    "C=(ns-1)*delQ*10**-6/(ns*VD-VS*1000)\n",
    "print 'Value of R = %.2f kohm'%(R)\n",
    "print '\\n Value of C = %.2e F'%(C)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 2.7 page 71"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " no. of series connection = 7\n",
      "\n",
      " no. of parallel connection = 5\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import ceil\n",
    "VS=4    #  kV\n",
    "IS=800    #  A\n",
    "\n",
    "VD=800    #  V\n",
    "ID=200    #  A\n",
    "dr=20/100    #  de-rating factor\n",
    "# for series connection\n",
    "ns = ceil(VS*1000/(1-dr)/(VD)) # # no. of series string\n",
    "# for parallel connection\n",
    "np = round(IS/(1-dr)/(ID)) # # no. of parallel string\n",
    "print '\\n no. of series connection = %d'%(ns)\n",
    "print '\\n no. of parallel connection = %d'%(np)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 2.8 page 72"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " Series resistance = 0.007 ohm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "IS1=100    #  A\n",
    "IS2=150    #  A\n",
    "vd1=2.1    #  V\n",
    "vd2=1.75    #  V\n",
    "I=250    #  A\n",
    "\n",
    "rf1=vd1/IS1    #  ohm\n",
    "rf2=vd2/IS2    #  ohm\n",
    "# Equating voltage drops\n",
    "# vd1+IS1*re = vd2+IS2*re\n",
    "re=(vd1-vd2)/(IS2-IS1)\n",
    "print ' Series resistance = %.3f ohm'%(re)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 2.9 page 72"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average power loss = 34.8 W\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "Vf1=1    #  V\n",
    "If1=0    # A\n",
    "Vf2=1.9    #  V\n",
    "If2=60    # A\n",
    "IT=20*pi    #  A\n",
    "# PAV = 1/T*integrate(VT*IT,0,T)*dt = ITAV+0.015*IRMS**2\n",
    "ITAV=IT/pi    # A\n",
    "ITRMS=IT/2    #  A\n",
    "dt=ITAV+0.015*ITRMS**2    #  W\n",
    "print 'Average power loss = %.1f W'%(dt)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 2.10 page 73"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Minimum gate pulse width = 8.7 us\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "R=10    #  ohm\n",
    "L=0.1    #  H\n",
    "delta_i=20/1000    #  A\n",
    "Vs=230    #  V4\n",
    "f=50    #  Hz\n",
    "theta=45    # degree\n",
    "\n",
    "delta_t = L*delta_i/Vs# # s\n",
    "delta_t = delta_t*10**6    #  us\n",
    "print 'Minimum gate pulse width = %.1f us'%(delta_t)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 2.11 page 73"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "gate source resistance = 2.0 kohm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt\n",
    "m=3*10**3    #  gradient (VG/IG)\n",
    "VS=10    #  V\n",
    "PG=0.012    #  W\n",
    "# IG = VG/m & PG=VG*IG\n",
    "VG=sqrt(PG*m)\n",
    "IG=VG/m # # A\n",
    "RS=(VS-VG)/IG/1000    #  kohm\n",
    "print 'gate source resistance = %.1f kohm'%(RS)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 2.12 page 74"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Value of resistance = 6.82 kohm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "VS=300    #  V\n",
    "delta_i = 50/1000    #  A\n",
    "R=60    #  ohm\n",
    "L=2    #  H\n",
    "TP=40*10**-6    #  s\n",
    "\n",
    "I1=VS/L*TP    #  A (at the end of pulse)\n",
    "# as I1 << delta_i\n",
    "I2=delta_i    #  A (anode current with RL load)\n",
    "\n",
    "Rdash = VS/(I2-I1)/1000    #  kohm\n",
    "print 'Value of resistance = %.2f kohm'%(Rdash)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 2.13 page 74"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "For half sine wave current : \n",
      "\n",
      "(i) Average ON State current  = 31.83 A\n",
      "\n",
      "(ii) Average ON State current  = 22.51 A\n",
      "\n",
      "(iii) Average ON State current  = 12.54 A\n",
      "\n",
      "\n",
      " For rectangular wave current : \n",
      "\n",
      "(i) Average ON State current  = 35.36 A\n",
      "\n",
      "(ii) Average ON State current  = 25.00 A\n",
      "\n",
      "(i) Average ON State current  = 14.43 A\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi,sqrt\n",
    "Im=50    #  A\n",
    "\n",
    "print 'For half sine wave current : \\n'\n",
    "# theta=180    #  degree\n",
    "theta=180    #  degree\n",
    "Iav=Im/pi    #  A\n",
    "Irms=Im/2    #  A\n",
    "FF=Irms/Iav    #  form factor\n",
    "ITav=Im/FF # # A\n",
    "print '(i) Average ON State current  = %.2f A\\n'%(ITav)    \n",
    "\n",
    "# theta=90    #  degree\n",
    "theta=90    #  degree\n",
    "Iav=Im/2/pi    #  A\n",
    "Irms=Im/2/sqrt(2)    #  A\n",
    "FF=Irms/Iav    #  form factor\n",
    "ITav=Im/FF # # A\n",
    "print '(ii) Average ON State current  = %.2f A\\n'%(ITav)    \n",
    "\n",
    "# theta=180    #  degree\n",
    "theta=180    #  degree\n",
    "Iav=Im*0.0213    #  A\n",
    "Irms=Im*0.0849    #  A\n",
    "FF=Irms/Iav    #  form factor\n",
    "ITav=Im/FF # # A\n",
    "print '(iii) Average ON State current  = %.2f A\\n'%(ITav)    \n",
    "\n",
    "print '\\n For rectangular wave current : \\n'\n",
    "# theta=180    #  degree\n",
    "theta=180    #  degree\n",
    "Iav=Im/2    #  A\n",
    "Irms=Im/sqrt(2)    #  A\n",
    "FF=Irms/Iav    #  form factor\n",
    "ITav=Im/FF # # A\n",
    "print '(i) Average ON State current  = %.2f A\\n'%(ITav)    \n",
    "\n",
    "# theta=90    #  degree\n",
    "theta=90    #  degree\n",
    "Iav=Im/4    #  A\n",
    "Irms=Im/2    #  A\n",
    "FF=Irms/Iav    #  form factor\n",
    "ITav=Im/FF # # A\n",
    "print '(ii) Average ON State current  = %.2f A\\n'%(ITav)    \n",
    "\n",
    "# theta=180    #  degree\n",
    "theta=180    #  degree\n",
    "Iav=Im/12    #  A\n",
    "Irms=Im/2/sqrt(3)    #  A\n",
    "FF=Irms/Iav    #  form factor\n",
    "ITav=Im/FF # # A\n",
    "print '(i) Average ON State current  = %.2f A\\n'%(ITav)    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 2.14 page 76"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Value of L = 16.67 uH\n",
      "\n",
      " Value of R = 3.3 ohm\n",
      "\n",
      " Value of Ip = 175.0 A is greater than permissible peak current = 125.0 A\n",
      " change the value of Rs\n",
      "\n",
      " Value of C = 0.78 uF\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "VS=500    #  V\n",
    "IP=250    #  A\n",
    "diBYdt=60    #  A/us\n",
    "dvaBYdt=200    #  V/us\n",
    "RL=20    #  ohm\n",
    "r=0.65    #  ohm\n",
    "eps=0.65     #  damping ratios\n",
    "\n",
    "F=2    #  saftety factor\n",
    "IP=IP/2    #  A\n",
    "diBYdt=60/2    #  A/us\n",
    "dvaBYdt=200/2    #  V/us\n",
    "L=VS/diBYdt    #  uH\n",
    "R=L*10**6/VS*dvaBYdt/10**6    #  ohm\n",
    "print 'Value of L = %.2f uH'%(L)\n",
    "print '\\n Value of R = %.1f ohm'%(R)\n",
    "\n",
    "Ip=VS/RL+VS/R    #  A\n",
    "if Ip > IP :\n",
    "    print '\\n Value of Ip = %.1f A is greater than permissible peak current = %.1f A\\n change the value of Rs'%(Ip,IP)\n",
    "    Rs=6    # ohm\n",
    "\n",
    "Ip=VS/RL+VS/Rs    #  A\n",
    "Cs=(2*eps/Rs)**2*L    #  uF\n",
    "print '\\n Value of C = %.2f uF'%(Cs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 2.15 page 77"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I2t rating = 45000 A**2/s\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import ceil,sqrt\n",
    "Isb=3000    #  A\n",
    "f=50    #  Hz\n",
    "I=sqrt((Isb**2*1/2/f)*f)     #  A\n",
    "I2t=I**2/2/f    #  A**2/s\n",
    "print 'I2t rating = %d A**2/s'%(ceil(I2t))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}