Menu

How to save analog results from ngspice and view them in gtkwave?

fiveight
2022-07-07
2023-08-04
  • fiveight

    fiveight - 2022-07-07

    Hi All:
    I know that ngspice can save event driven nodes to vcd file, and view the vcd file with gtkwave. But I am interesting in analog circuit now, and can not find a way to output analog results to vcd file.

    How to save analog results from ngspice and view them in gtkwave?
    Thanks!

     
  • Holger Vogt

    Holger Vogt - 2022-07-07

    Unfortunately this is not implemented directly in ngspice.

    You may try storing data with command 'wrdata' and then read and display it with gtkwave. If this is possible, please post your procedure here.

    For pure analog you might use the4 'gnuplot' command or the internal 'plot' procedures.

     
    • fiveight

      fiveight - 2022-07-08

      Thanks!
      I am using ngspice as shared library. So I decide to save the vactor values that from callback function in memory, and output a VCD file myself. Then let gtkwave use the VCD file.

       
      • marcel hendrix

        marcel hendrix - 2022-07-08

        On 2022-07-08 02:41, fiveight wrote:

        Thanks!
        I am using ngspice as shared library. So I decide to save the vactor
        values that from callback function in memory, and output a VCD file
        myself. Then let gtkwave use the VCD file.

        That is interesting. The last time I looked, I could not find
        adequate documentation to write VCD files. However, this
        documentation and source code was donated shortly afterwards
        and is now somewhere in an older NGSPICE branch. The
        implementation needs the zlib.dll and I remember issues
        with it not being available for Windows at that time.
        A nice side effect of VCD files is that they are much
        shorter than the regular .raw files and speed up
        NGSPICE quite a bit. A disadvantage is that most other
        tools can't read VCD.

        -marcel

         
        • Clyde

          Clyde - 2022-07-08

          Well, call me simple, but I tried to make a VCD file using eprvcd of a pulse waveform and the trouble is that my signal is not identified as event driven node, so it does not go into the file. Page 19 of the manual clearly shows that analog wavefroms may be displayed and implies they may coexist peacefully with digital ones.

          I don't have the luxury to do what @fiveight did.

           
          • Giles Atkinson

            Giles Atkinson - 2022-07-08

            Clyde,

            It seems that the only way to get analogue values into a VCD file is from an XSPICE "real" node. Hence the use of a bridge. I did now find a way to get a scope-style trace in gtkwave: Menubar->Edit->Data Format->Analog->Interpolated and it only works after the trace is displayed in the default format. So quite well-hidden, but with that the output looks OK.

            Marcel,

            I found an earlier topic on ngspice writing output for gtkwave while searching for how to display analogue traces. It mentioned a problem with zlib, but the format was gtkwave's own LXT, not VCD.

             
            • marcel hendrix

              marcel hendrix - 2022-07-08

              On 2022-07-08 13:35, Giles Atkinson wrote:

              Marcel,

              I found an earlier topic on ngspice writing output for gtkwave while
              searching for how to display analogue traces. It mentioned a problem
              with zlib, but the format was gtkwave's own LXT, not VCD.

              Sorry for the unintended confusion! It is indeed LXT that needs ZLIB.
              I don't think it is worthwhile to integrate LXT in NGSPICE, given the
              currently available VCD functionality.

              -marcel

               
            • Holger Vogt

              Holger Vogt - 2022-07-08
               

              Last edit: Holger Vogt 2022-07-08
  • Giles Atkinson

    Giles Atkinson - 2022-07-07

    Another possibility is to add voltage_to_real bridges to the relevant nodes and save the output. The bridge is not a standard component, but it took little time to make one. The resulting VCD file looks plausible, but gtkwave fails to plot it. I may be missing something.

    $date July 07, 2022 13:50:15 $end
    $version ngspice 37 $end
    $timescale 1 ns $end
    $var real 1 ! r $end
    $enddefinitions $end
    #0
    $dumpvars
    r0 !
    $end
    #201
    r0.001256637 !
    #401
    r0.002513271 !
    #800
    r0.005026527 !
    #1601
    r0.01005293 !
    #3201
    r0.02010484 !
    #6400
    r0.04020155 !
    #12801
    r0.0803381 !
    #25600
    r0.1601568 !
    #45601
    r0.2826093 !
    #65601
    r0.4006049 !
    #85601
    r0.5122827 !
    #105601
    r0.6158815 !
    #125600
    r0.7097675 !
    #145600
    

    The test circuit:

    Test voltage-to-real bridge
    
    va 1 0 sin(0 1 1k)
    abridge 1 r bridge
    .model bridge v_to_real gain=1
    
    .control
    tran 20u 2m
    plot v(1) r
    .endc
    .end
    
     
    • Clyde

      Clyde - 2022-07-07

      I am looking at a software called vcdMaker which purports to be able to make a vcd file of ascii data. My thinking was to write a text file wit wrdata as the input. I have started to try this, but have been unsuccessful so far.

       
    • Clyde

      Clyde - 2022-07-07

      I am looking at a software called vcdMaker which purports to be able to make a vcd file of ascii data. My thinking was to write a text file wit wrdata as the input. I have started to try this, but have been unsuccessful so far.

       
  • Giles Atkinson

    Giles Atkinson - 2022-07-07

    It does work after dragging the trace name into the central "Signals" box. The signal then appears as a digital wave form, but if zoomed in the numeric sample values are shown. So probably much less useful than ngspice's own plots or gnuplot output in most cases. I guess it could be useful if you have a lot of digital signals and a few analogue ones.

     
  • Giles Atkinson

    Giles Atkinson - 2023-08-04

    VCD file output for analogue nodes is expected in Ngspice41. (commit e9386155a63c17ce4d7b8f814f6f18d98927c40b)

     
  • dick freebird

    dick freebird - 2023-08-04

    Nice. Last time I had to deal with large amounts of digital stimulus and
    "expect", I had to make veriloga widgets and shell scripts to turn VCD
    dumps into PWL/NRZ veriloga sources.

    Will there be / is there, a VCD -input- complement to the VCD output?
    And what about a VCD "checker"? I made a veriloga that basically compared
    VCS@time to a clocked sample of an output, and threw an output voltage
    to inspect (for !=0).

    Everybody does functional-at-speed verification on >10Kgates in SPICE, right?

     
  • Giles Atkinson

    Giles Atkinson - 2023-08-04

    The VCD format seems to be the nearest available thing to a "lingua franca" for simulation data, so a VCD reader seems a good idea. And any such input reader would be very useful in regression testing, both for application circuits and ngspice itself. Having a hammer, this looks like a nail. I envisage a netlist syntax like:

    areader [ some digital nodes ] [ other analogue nodes ] test_input
    .model test_input vcdreader file="testdata.vcd"
    

    or even

    .model test_input vcdreader files=[ "testdata.vcd" "td2.vcd" ]
    + offsets=[ 0 10u ]
    

    I did look for some nice open-source library to handle the low-level stuff. So far, no luck. If anyone knows of one ...

     
  • Holger Vogt

    Holger Vogt - 2023-08-04

    Perhaps vcd.c in the gtkwave sources at https://sourceforge.net/projects/gtkwave/ , although its GPL license does not allow its direct usage in ngspice, which is not GPL.

     

    Last edit: Holger Vogt 2023-08-04
  • dick freebird

    dick freebird - 2023-08-04

    I imagine a voltage source similar to pwlfile but which lets you set the
    "1" and "0" voltage and transition time between, and then reads VCD
    format so you get level_one*bit_is_one and level_zero*!bit_is_one
    and a finite risetime. Point it at a VCD file and which column, badda-
    bing.

    And a "criticizer" for the output side, which can read an "expect" file
    format (VCD or ???), emitting an "error waveform" and per-failing-
    vector statements.

    But that's a circuit guy's idea without regard to practicalities.

     
    • Clyde

      Clyde - 2023-08-04

      How about this... I am looking on my drive for a simulation I did in ModelSim of a sine tone generator. When I wrote it, I produced an analog waveform in ModelSim.

      So, I just took a look in the folder which contains the .exe files associated with ModelSim and there is a conversion utility to covert the waveform file ( .wlf) to vcd format! Perhaps that is a way to break into how to represent an analog waveform in gtkwave.

      If I can find that HDL, I will try it...

       

Log in to post a comment.