title: Get memory dump in ModelSim (periodical)
body: <p>How can I get memory dump in ModelSim on a regular basis?</p>
  
  <p>I know how to export memory data. Is there a way to write in the .do file a command to export the memory data every 1000 ns or every x cycles?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Thanks for the answers.
  The way I'm doing it now:</p>
  
  <pre><code>mkdir -p mlog
  set counter 0
  set limit 30
  
  while { true } {
     run 100 us
    incr counter +1
    mem save -o ./mlog/spram1_${counter}.mem -f mti -data binary -addr hex /ram_tb/spram1/mem
    mem save -o ./mlog/spram2_${counter}.mem -f mti -data binary -addr hex /ram_tb/spram2/mem
    /path/to/third/mem
  }
  </code></pre>
  
  <p>This is in case you used run -all before and you don't know when the simulation stops.
  The VHDL testcase should of course have something like</p>
  
  <pre><code>ASSERT false
      REPORT "### End of Simulation!"
      SEVERITY failure;
  </code></pre>
  
  <p>to end the simulation (for a nicer way see the answers below, but this works)</p>
  
  <p>In case you know how long the simulation will run you can also use this way:</p>
  
  <pre><code>  mkdir -p mlog
    set counter 0
    set limit 10
  
    while { $counter &lt; $limit } {
      run 1 ns
      incr counter +1
      mem save -o ./mlog/filename1_${counter}.mem -f mti -data binary -addr hex /path/to/another/mem
      mem save -o ./mlog/filename2_${counter}.mem -f mti -data symbolic -addr hex -wordsperline 1 /path/to/mem
      ## mem save -o ./mlog/anotherfile ...
    }
  </code></pre>
  
  <p>that can replace "run 10 ns"</p>
  
  <p>alternatively you can use a signal that indicates the end of simulation</p>
  
  <pre><code>  signal end_of_sim   : std_logic := '0';
    ...
    end_of_sim &lt;= '1'
  </code></pre>
  
  <p>and in the do-file:</p>
  
  <pre><code>  when -label end_of_simulation {/end_of_sim == '1'} {
      echo "End of simulation"; 
      stop ;
      #quit -f
    }
  </code></pre>