• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC Design
  3. Verilog-A read file separated by delays

Stats

  • Locked Locked
  • Replies 12
  • Subscribers 127
  • Views 21771
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Verilog-A read file separated by delays

kennethbrun
kennethbrun over 13 years ago

I want to create a Verilog-A module (intended for Spectre simulations) that will read a stimuli file on some predefined format and apply the stimulis to the outputs.

The input stimuli file format could be like this:

OUT1=1

OUT2=0

# = 25

OUT1=0

OUT2=0

 

In the above file, the intention is to initially set OUT1/2 to some well-defined value and then change them 25 time units (ps in this case) later. I create the file myself (in another tool) and the format is not fixed in any sense, but the basic concept is, that it should include both timing and signal/value information.

 

 I've been trying to create this Verilog-A module, but I got stuck while trying to create the time delay. Below is my Verilog-A code so far. After some initial setup, the idea is that I run a check at each time unit step (~1ps). If a delay counter is higher than 0, then I count it down, if not: then I read the file (and potentially changes the delay counter when "#=250" is read).

When simulated 500ps in Spectre,  the last to output assignments are never effectuated. According to my debugging, it seems that the file pointer has reached EOF when exiting the inner loop. But I do not understand this, and I cannot see any alternative implementation to avoid this problem - any suggestions for a way through this?

 -----------

 module vloga_component(vdd1v2,out1, out2);
   output out1;
   electrical out1;
   output out2;
   electrical out2;
   input  vdd1v2;
   electrical vdd1v2;
   
   parameter string fileString = "/tmp/default" ;

   integer   fd;
   integer   testint1,testint2;
   integer   out1var,out2var;
   
   string signalName;
   integer   signalVal;
   integer   delayCounter;
   
   analog
     begin
    // THIS BLOCK IS FOR FILE READING:
    @(initial_step)
      begin
         delayCounter = 0;
         fd = $fopen(fileString, "r");
      end // @ (initial_step)
    @(timer(0,1e-12))
      begin
         if(delayCounter>0)
           begin
          // PART OF LOOP WHERE THE DELAY IS IMPLEMENTED
          delayCounter = delayCounter-1;
          $display("Remaining delay: %d ps", delayCounter);
           end
         else
           begin
          // PART OF LOOP WHERE THE FILE IS READ
          while (delayCounter==0 && (!$feof(fd)))
            begin
                    testint1 = $fscanf(fd, "%s=%d", signalName, signalVal);
               case(signalName)
             "#" :
             begin
                $display("WE GOT A MATCH: %s = %d ; TEST2=%d",signalName,signalVal,testint1);
                $display("Delay: %d ps", signalVal);
                delayCounter=signalVal;
             end
             "OUT1" :
               begin
                  $display("WE GOT A MATCH: %s = %d ; TEST2=%d",signalName,signalVal,testint1);
                  out1var = signalVal;
               end
             "OUT2" :
               begin
                  $display("WE GOT A MATCH: %s = %d ; TEST2=%d",signalName,signalVal,testint1);
                  out2var = signalVal;
               end
             default $strobe("Error. Too weird: %s", signalName);
               endcase // case(signalName)
               
            end
          
           end // else: !if(delayCounter>0)
      end
    V(out1) <+ transition(out1var,0,1e-12);
    V(out2) <+ transition(out2var,0,1e-12);

     end

   
endmodule
-----------

 Best regards,

Kenneth

  • Cancel
  • kennethbrun
    kennethbrun over 13 years ago

     Anyone with experience in reading stimuli files through Verilog-A at all?

    More general the question can be stated as:

    How can I make a delay (in a transient simulation) dependent on the content of a read file?

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 13 years ago

    I'd like to investigate, but the day job has been getting in the way... maybe somebody else has the time.

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • RobinCommander
    RobinCommander over 11 years ago

    kennethbrun said:

    More general the question can be stated as:

    How can I make a delay (in a transient simulation) dependent on the content of a read file?

     

    I take it this isn't possible?

    I started on something similar, but it sounds like it isn't going to work.

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • kennethn
    kennethn over 11 years ago

    RobinCommander said:

    I take it this isn't possible?

    I started on something similar, but it sounds like it isn't going to work.

     

    Hi Robin,

     

    I succeeded with the task the last time. I'm currently busy, but will post you ideas within a couple of days. Don't remember the details, but I can look them up...

    /Kenneth

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • RobinCommander
    RobinCommander over 11 years ago

     OK thanks.

    I was also trying to make the file name a parameter but couldn't get it to run in Spectre when I included the path.

    In VerilogA:    parameter string read_file="/path/SPI_commands.txt";

    In spectre.out:      Error found by spectre during circuit read-in.
        ERROR (SFE-874): "input.scs" 12: Unexpected operator "/".

    Line 12 of input.scs:      I0 (net3 net4 net1 net5) SPI_stim read_file=/path/SPI_commands.txt

    If I could persuade the netlister to put quotes around the string maybe this would work, but I haven't found a way to do this.

    Robin

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • kennethn
    kennethn over 11 years ago

      Did you try escaping either quotes or slashes?

     E.g.

    parameter string read_file="\/path\/file.txt"

    or

    parameter string read_file="\"/path/file.txt\""

     

    I do it by:

    parameter string simId = "default";

    and then open the file with:

        fd = $fopen({{"$PROJECTSDIR/",simId}, ".txt"}, "r");

     /Kenneth

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • RobinCommander
    RobinCommander over 11 years ago

     Escaping the quotes or slashes didn't help, I also tried "\042/path\/file.txt\042" (042 is octal ").

    But this feature was just plus, maybe something like your method will work.

    Robin

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 11 years ago

    Robin,

    There's a bug in correctly setting the view-specific CDF for string parameters in VerilogA views, it seems.

    To solve this, if you do:

    almGetParameterList("mylib" "mycell" ?view "veriloga")

    to find out what parameters you have - in your case you have one called read_file (maybe others too). Set the parameterList to not include read_file, but include all the other parameters (I called them param1 param2) - if there are no others, you can just pass nil instead of '(param1 param2):

    almSetParameterList("mylib" "mycell" '(param1 param2) ?view "veriloga") 

    Then tell it that read_file is a string parameter:

    almSetStringParameterList("mylib" "mycell" '(read_file) ?view "veriloga")

    Having done this, it should netlist it with quotes around the fileName.

    I am filing a CCR on your behalf to correct the VerilogA parser/CDF creation to do this automatically.

    As for implementing the delay in the original question, I would do it not by setting a timer every 1ps - because that will hurt simulation performance - but instead keep track of the time of the next "event" and set a non-periodic timer to start then and read the next data from the file).

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 11 years ago

    Robin,

    Turns out that you don't need to do the almSetParameterList removing the read_file parameter; all you have to do is call almSetStringParameterList().

    I filed CCR  1230515 to get the VerilogA parsing fixed.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • kennethn
    kennethn over 11 years ago

    Robin,

     

    Here is the important part of my solution to the problem.

    --

       analog
         begin
            @(initial_step)
              begin
                 timeOfNextStep = 0;
                 simTimeStep=0;
              end
            @(cross($abstime-timeOfNextStep*1e-9,1) or initial_step)
              begin
                 fileTimeStep=0;
                 fd = $fopen({{"/path/inputcounter/",simId}, ".txt"}, "r");
                 while($fscanf(fd, "%s = %s", signalName, signalVal)>0)
                   begin
                      if(fileTimeStep==simTimeStep)
                        begin
                           case(signalName)
                             "#":
                             begin
                                timeOfNextStep=timeOfNextStep+signalVal.atoi();
                                $display("INFO: (%m) (time:%g) Delay read from file %s ns",$abstime,signalVal);
                             end
                             "CdrLocked":
                               begin
                                  case(signalVal)
                                    "0": CdrLockedVar = 0;
                                    "1": CdrLockedVar = 1.2;
                                    "X": CdrLockedVar = 0.6;
                                    "Z": CdrLockedVar = 0.6;
                                    "z": CdrLockedVar = 0.6;
                                    "x": CdrLockedVar = 0.6;
                                    default: $strobe("ERROR: (%m) (time:%g) Unsupported signal value for signal CdrLocked: %s",$abstime,signalVal);
                                  endcase
                                  $display("INFO: (%m) (time:%g) Stimuli read: CdrLocked = %s",$abstime,signalVal);
                               end
                               end
                             default $strobe("ERROR: (%m) (time:%g) Unknown signal name: %s",$abstime, signalName);
                           endcase // case(signalName)
                        end // if (fileTimeStep==simTimeStep)
                      if(signalName=="#")
                        begin
                           // keep track of the number of "timesteps" in file
                           fileTimeStep=fileTimeStep+1;
                        end
                   end
                 simTimeStep=simTimeStep+1;
                 $fclose(fd);
              end
            V(CdrLocked) <+ transition(CdrLockedVar,0,1e-12);
    end
    --

     

    The example is not self-contained, but let me know if you need further details.

    /Kenneth

    PS: the performance of this forum is horrible today. Just had three timeouts :(

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
>

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information