# 12_bjt_amp_ac: pinout with spice/portmap

## Scope

In this simulation we are going to look at a single-transistor amplifier in frequency domain to verify how it amplifies a sine waves. Compared to the trans variant the only difference is how we specify the transistor pinout and what spice commands we use for the AC simulatuin

## The schematics

Largely the same as trans variant.

Click the image to get the sch-rnd sheet; NOTE: the actual value of V1 has been changed from SINE() to a dc/ac combo.

## Preparing for simulation

### Q1

This example demonstrates using spice/portmap to set the pinout: the stock spice/pinnum attributes has been manually removed from Q1 terminals and a portmap attribute, array type, added to the Q1 symbol. The portmap is:

###

###

###

##

##

###

###

    {C->spice/pinnum=1}
    {B->spice/pinnum=2}
    {E->spice/pinnum=3}

    Since the attribute is called spice/portmap, it does not interfere with
    the normal portmap attribute (installed by devmap in our example) and it
    affects the spice workflow only.

     V1

    V1 is generating the input sine wave on the in network.
    The simulator will reconfigure it while sweeping the frequency for the
    ac analysis.

     V2

    V2 is an 5V DC power supply for Vcc:

    dc 5

     Raw spice commands

    It contains the following script:

    ac dec 10 1 1000k
    settype decibel out
    plot vdb(out) xlimit 1 1000k ylabel 'small signal gain'
    settype phase out
    plot cph(out) xlimit 1 1000k ylabel 'phase (in rad)'

    This runs an ac analysis between 1 Hz and 1 MHz with 10 points in every decade,
    then plot gain and phase.

     Export and run ngspice

    Running ngspice the usual way on the export yields the following graph:

     Using other implementations
     gnucap

    This may not work with gnucap; error message: open circuit: internal node 2

    Gnucap uses a different command syntax. Modify the spice command symbol's
    spice/command attribute to:

    print ac vdb(out) zp(out)
    ac dec 10 1 1000k > plot.txt

    After the export, write a single word spice in the first line of the
    file (e.g. using a text editor), else gnucap won't know the file is in spice
    syntax. Then run gnucap 12_btj_amp_ac.cir and it will dump a text
    table to plot.txt that can be plotted using e.g. gnuplot. Both traces are
    included in the same file.

    The gnucap-modified schematics is also available.

     xyce

    TODO