Oh no! Some styles failed to load. 😵 Please try reloading this page
Menu â–¾ â–´

VHDL sim'd .vcd data - as analog sim source

sdaau
2011-11-25
2017-07-21
  • sdaau

    sdaau - 2011-11-25

    Hi all,

    I needed to simulate some PWM signals, generated by a VHDL testbench (and stored in a .vcd (value change dump) file) in the analog domain using ngspice; and here is an example Linux Bash script: ghdl2ngspice-example.sh. To test it, just do something like:

    #download
    wget http://sdaaubckp.svn.sf.net/viewvc/sdaaubckp/single-scripts/ghdl2ngspice-example.sh
    # give permissions
    chmod +x ghdl2ngspice-example.sh
    # run
    ./ghdl2ngspice-example.sh
    # to capture terminal output log:
    # ./ghdl2ngspice-example.sh 2>&1 | tee ghdl2ngspice-example-log.txt
    

    The script will automatically generate source files, and basically use:

    (from the script notes)

    • GHDL to simulate a VHDL model (PWM generator) and output vcd data;

    • gtkwave with tcl script to extract the PWM vcd channel into new vcd file;

    • vcd2ngspice-d_source.py to convert the extracted vcd data file into ngspice's d_source (digital source) data format

    • gschem to generate appropriate circuit schematic and netlist for ngspice

    • ngspice to simulate the circuit with the converted PWM data as a voltage source

    For comparison, here is the command log output ghdl2ngspice-example-log.txt; this is how the circuit ends up looking like in gschem:

    … and here is what the simulation in ngspice looks like:

    The vcd2ngspice-d_source.py is my attempt to write a VCD parser using python and pyparsing, based on the approach in http://stackoverflow.com/questions/4140884/pyparsing-forward-and-recursion - which will convert the VCD format to the text data format used by ngspice's `d_source` ("digital source") model. It can be used like this:

    python vcd2ngspice-d_source.py -i INFILENAME.vcd > d_source.text
    # to supress terminal stderr messages:
    # python2.7 vcd2ngspice-d_source.py -i INFILENAME.vcd 2>/dev/null > d_source.text
    

    The `vcd2ngspice-d_source.py` script seems to work in both python 2.7 and 3.2 (however, see notes in script regarding installation of latest `pyparsing`). Note that only bit/wire .vcd values will end up being correctly read by the `d_source` - bus/register values will be output verbatim to the `d_source` data file, and as such `d_source` will not be able to parse them. However, note that the same script contains an example of using a `tcl` script for `gtkwave`, in order to separate a single signal from a collection in a .vcd - and then export the extracted signal only (in a new .vcd). The script should be capable of dealing with VCD from `ghdl`, `gtkwave` and `isim` - however, note that the current 'dumpon'/'dumpoff' handling is rather "cheap" (still, it does what I want it to do for now :) ).

    Well, hope this may be of use to the community,
    Cheers!

     
  • sdaau

    sdaau - 2011-11-29

    PSS: It turns out the `d_source` is an older XSPICE code model, and may have some memory leaks; it's better to use the analog `filesource`, but that has a slightly different data file format than `d_source`  (see ngspice-users: rawfile & malloc: Internal Error: can't allocate)

     
  • sdaau

    sdaau - 2011-11-30

    PSSS: The script vcd2ngspice-d_source.py is now modified to also support output in `filesource` format (columns of real number values)

     

Log in to post a comment.