*************************************************
Three Terminal MOS VG Control and VCB Control
*************************************************

Notes
==============

#.  3-T MOS charge control **updated 2/21**    
    :download:`Download<../../mosfet2012/3tmos/3_term_mos_surface_charge_2012.jnt>`. 

#.  Vcb control point of view **updated 2/21**    
    :download:`Download<../../mosfet2012/3tmos/vcb_control.jnt>`. 
    
    
#.  Download latest version of the programs.

    The downloader works now as intended. Not downloading
    current version of programs has caused a great deal of problem.
    It happened today with ruocan too, when she thinks
    she had the latest version, it turns out that she had the older
    version, which took a lot of time for us to figure out.

    Give this program a try, and let me know how it works.
     
    Right now there are 5 downloading threads, if there is issue I can set that to 1.
    
    This should save a bunch of clicks, and hopefully helps us
    always downloading latest versions.
    
 
    #. :download:`Download and save in working folder<../../livemesh/python/qt/qtdownloader.py>`. 
       :download:`Download and save in working folder<../../livemesh/python/qt/downloader.py>`.  
       
       This one works now, I had the files saved
       in the c:\ root folder rather than the current folder during testing. 
       
       It now saves files under your working folder if you use the new version.

    #. :download:`Download and save as equisemi.py<../../livemesh/python/semidev/equisemi.py>`.
    
    #. :download:`Download and save as vcb_control_view_demo.py<../../livemesh/python/semidev/vcb_control_view_demo.py>`.
    
Homework 3 (Due Th class):
=============================

#.  see slide 21

#.  For first problem, just use the latest codes we used today. 

    try all 4 combinations of overlay and subplots, use a different tox, Na, or try different tox, Na.
    
    save all PDFs (rename them in file system or in python program)
    
    write down the ``points`` learned today on the graphs. Many adobe readers allow you to type
    on a PDF. If you have trouble finding one, let me know.
    
 
    
    
Homework 2 (Report due next class):
======================================

#.  Practice the new interactive MOS codes. Take screenshots. 
    Compare with equations, see if it makes sense to you. 

#.  Write a small program to graph out 
    VTB and VTC as a function of doping from 1e16 to 1e18 for tox=1nm, 2nm, and 10nm.
    Explain your graphs.

#.  Investigate the VCB control point of view by looking at 
    how surface potential and charges vary with VCB when VGB
    is held constant. You can use the sample program provided below.

    Explain why surface potential increases with increasing 
    VCB, why ps eventually saturates, and how the saturated ps
    value relates to psa(Vgb), the depletion surface potential.
    
    A sample program you can use / modify is given below:
    
    .. code-block:: python

        #-------------------------------------------------------------------------------
        # Name:        Vcb Control of Inversion Charge in 3-T MOS
        # Purpose:     For teaching how Vcb controls inversion charge and the concept
        #              of channel pinch-off.
        # Author:      GuofuNiu
        #
        # Created:     08/02/2012, updated 2/16/2012
        # Copyright:   (c) GuofuNiu 2012
        # Licence:     <your licence>
        #-------------------------------------------------------------------------------

        from myplot import *
        from equisemi import Nmos, Metal, Psemi
        import numpy as np
        from matplotlib.pyplot import show, interactive
        from matplotlib.backends.backend_pdf import PdfPages

        '''
        For teaching how Vcb controls inversion charge and the concept
        Also serve as a demo for calculating surface potential vs Vcb for various Vg 
        You can modify this code for your own purpose

        Examine the 'vcb_control_view.pdf' file for output graphics.


        '''
        fig_format = 'png'

        pp = PdfPages('vcb_control_view.pdf')
        nmos = Nmos()
        vgs = np.linspace(0, 2.0, 5)

        ps_from_vg = nmos.ps_from_vg_bisect
        qinv_from_ps = nmos.qinv_from_ps

        vcbs = np.linspace(0, 2, 50)
        cols = colors[:]
        ax = None
        ax_qinv = None
        fig = None
        fig_qinv = None

        ps = vcbs.copy()
        qinv = vcbs.copy()

        ##interactive(True)
        for vg in vgs:
            nmos.vgb = vg
            color = cols.pop(0)
            for idx, vcb in enumerate(vcbs):
                nmos.vcb = vcb
                ps[idx] = ps_from_vg(vg)
                qinv[idx] = qinv_from_ps(ps[idx])

            line, ax, fig = myplot(ax=ax, x=vcbs, y=ps,
                                  xlabel='$V_{cb} (V)$',
                                  ylabel='$\phi_{s} (V)$',
                                  label='Vgb=%4.1f' % (vg),
                                  color=color, fig=fig)

            pp.savefig(fig)

            line2, ax_qinv, fig_qinv = myplot(ax=ax_qinv, x=vcbs, y=qinv,
                                  xlabel='$V_{cb} (V)$',
                                  ylabel='$Q_{inv} (C/cm^2)$',
                                  label='vgb=%4.1f' % (vg),
                                  color=color,
                                  fig=fig_qinv)

            cols.append(color)
            pp.savefig(fig_qinv)

        fig.savefig(nmos.name + '_ps_vcb.png', format=fig_format)
        fig_qinv.savefig(nmos.name + '_qinv_vcb.png', format=fig_format)
        show()

        pp.close()


    
Homework 1 (Report Due 2/16 Class Time)
=======================================

    
#.  Download latest version of the programs.

    #. :download:`Download and save as equisemi.py<../../livemesh/python/semidev/equisemi.py>`.
    
    #. :download:`Download and save as myplot.py<../../livemesh/python/semidev/myplot.py>`.

#.  Read the 3-T MOS notes above, summarize the 
    impact of VCB on the Qs-ps, Qs-ps, Qs-Vg curves.
    
    
#.  Study the mos_vcb_demo() function. Make a copy in another
    program file, and change doping or oxide thickness, see if you can 
    understand the resulting plots (see the PDF output) using the equations learned from the notes.

    :download:`PDF output<../../livemesh/python/semidev/gate_control_at_vcbs_from_ps.pdf>`.

    .. code-block:: python

        def mos_vcb_demo():
            '''
            Illustrates the effect of Vcb using
            pss based MOS data (no bisect that is)

            Note that the Vg range will
            vary a lot as Vcb varies as
            the internal surface potential array nmos.pss
            varies with Vcb.



            '''

            metal = Metal('Npoly')
            oxide = Oxide(2)
            vcbs = np.array([0, 1, 2])
            psemi = Psemi(5e15)

            nmos_list = []

            for vcb in vcbs:
                nmos = Nmos(metal, oxide, psemi, vcb)
                nmos_list.append(nmos)

            plotter = NmosPlotter(nmos_list)
            plotter.save_figs_as_pdf('gate_control_at_vcbs_from_ps.pdf')
    
    
#.  Study the nmos_vg_plotter_demo() function and its PDF
    output. Explain results with equations
    in your own words. 
    
    :download:`PDF output<../../livemesh/python/semidev/doping_impact_from_vg.pdf>`

    .. code-block:: python

    
        def nmos_vg_plotter_demo():
            '''
            Vg dependence of MOS physics from
            using Bisect method.

            This demo uses doping dependence for illustration.

            :download:`see sample output of Vg dependence with doping impact
            <../../doping_impact_from_vg.pdf>`
            '''

            # create a metal, an oxide and a ptype semi
            metal = Metal('Npoly')
            oxide = Oxide(2)
            dopings = np.logspace(16, 18, 3)
            nmos_list = []
            vgs = np.linspace(-2,2,100)

            for doping in dopings:
                psemi = Psemi(doping)
                nmos = Nmos(metal, oxide, psemi)
                nmos_list.append(nmos)

            plotter = NmosVgPlotter(nmos_list, vgs)

            plotter.save_as_pdf('doping_impact_from_vg.pdf')
            plotter.write_sphinx(prefix='doping_vg')

    
    
#.  Study the nmos_vcb_plotter_demo() function and its PDF output.
    Explain
    results with equations in your own words.
    
    :download:`PDF output<../../livemesh/python/semidev/vcb_dependence_from_vg.pdf>`
    
    .. code-block:: python
    
        def nmos_vcb_plotter_demo():
            '''
            Vcb dependence of MOS physics from
            using Bisect method.

            This demo uses doping dependence for illustration.

            :download:`see sample output of Vcb dependence with doping impact
            <../../vcb_dependence_from_vg.pdf>`

            '''
            # create a metal, an oxide and a ptype semi
            metal = Metal('Npoly')
            oxide = Oxide(2)
            dopings = np.logspace(16, 18, 1)
            nmos_list = []
            vgb = 1
            vcbs = np.linspace(0,2,100)

            for doping in dopings:
                psemi = Psemi(doping)
                nmos = Nmos(metal, oxide, psemi, vgb=vgb)
                nmos_list.append(nmos)

            plotter = NmosVcbPlotter(nmos_list, vcbs)
            plotter.save_as_pdf('vcb_dependence_from_vg.pdf')
            plotter.write_sphinx(prefix='doping_vcb')
    


Download Modules 
------------------------

#. :download:`Download and save<../../livemesh/python/semidev/interactive_mos.py>`.


#.  the ``equisemi`` module
    :download:`Download<../../livemesh/python/semidev/equisemi.py>`.
    
#.  the ``myplot`` module
    :download:`Download<../../livemesh/python/semidev/myplot.py>`.
    
#.  the ``conditions`` module (you do not really need it, but I use it for debugging,
    this way, I can debug your code if necessary).
    :download:`Download<../../livemesh/python/semidev/conditions.py>`.

#.  the ``nmos_demo`` module which you will use as basis for in-class exercise 
    and homework problems 
    :download:`Download<../../livemesh/python/semidev/nmos_demo.py>`.