# 22_custom_sym: creating a custom symbol

## Scope

Create a custom diode symbol with an embedded (inline) model card.

## The schematics

Click the image to get the sch-rnd sheet

## Preparing for simulation

Draw the symbol the usual way, using lines, rectangles and {p t} for placing terminals; select the objects, convert selection to symbol; set the usual attributes (e.g. name on the symbol and on the terminals).

For spice simulation, set the following attributes:

- symbol attribute spice/prefix to D: for the simulation this is a diode; this attribute lets the sheet name the symbol U1 still show spice a D component by prefixing the name with D_.
- symbol attribute spice/model_card to .MODEL my_diode D (IS=2f RS=3.4 N=2.2): this is how the model is specified inline, within the symbol, not relying on external libs
- terminal attribute spice/pinnum; the positive (anode) terminal should be 1, the negative (cathode) should be 2.

The inline model card option is useful for one-off symbols or for an easy and quick way of tuning model parameters in test-bench schematics.

### Raw spice commands

Similar to those used in 10_bjt_amp_tr.

## Export and run ngspice

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

## Using other implementations

### gnucap

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

    print tran v(out) v(in)
    tran 1u 4m > plot.txt

After the export, write the single word spice in the first line of the file (e.g. using a text editor), otherwise gnucap won't know that the file is in spice syntax. Then run gnucap 22_custom_sym.cir and it will dump a text table to plot.txt that can be plotted using a suitable utility, e.g. gnuplot.

The gnucap-modified schematic is also available.

### xyce

TODO