misc.expect.txt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <span class="hljs-meta">`<span class="hljs-meta-keyword">timescale</span> 1ns / 1ps</span>
  2. <span class="hljs-comment">/**
  3. * counter: a generic clearable up-counter
  4. */</span>
  5. <span class="hljs-keyword">module</span> counter
  6. #(<span class="hljs-keyword">parameter</span> WIDTH=<span class="hljs-number">64</span>)
  7. (
  8. <span class="hljs-keyword">input</span> clk,
  9. <span class="hljs-keyword">input</span> ce,
  10. <span class="hljs-keyword">input</span> arst_n,
  11. <span class="hljs-keyword">output</span> <span class="hljs-keyword">reg</span> [WIDTH-<span class="hljs-number">1</span>:<span class="hljs-number">0</span>] q
  12. );
  13. <span class="hljs-comment">// some child</span>
  14. clock_buffer <span class="hljs-variable">#(WIDTH)</span> buffer_inst (
  15. <span class="hljs-variable">.clk</span>(clk),
  16. <span class="hljs-variable">.ce</span>(ce),
  17. <span class="hljs-variable">.reset</span>(arst_n)
  18. );
  19. <span class="hljs-comment">// Simple gated up-counter with async clear</span>
  20. <span class="hljs-keyword">always</span> @(<span class="hljs-keyword">posedge</span> clk <span class="hljs-keyword">or</span> <span class="hljs-keyword">negedge</span> arst_n) <span class="hljs-keyword">begin</span>
  21. <span class="hljs-keyword">if</span> (arst_n == <span class="hljs-number">1'b0</span>) <span class="hljs-keyword">begin</span>
  22. q &lt;= {WIDTH {<span class="hljs-number">1'b0</span>}};
  23. <span class="hljs-keyword">end</span>
  24. <span class="hljs-keyword">else</span> <span class="hljs-keyword">begin</span>
  25. q &lt;= q;
  26. <span class="hljs-keyword">if</span> (ce == <span class="hljs-number">1'b1</span>) <span class="hljs-keyword">begin</span>
  27. q &lt;= q + <span class="hljs-number">1</span>;
  28. <span class="hljs-keyword">end</span>
  29. <span class="hljs-keyword">end</span>
  30. <span class="hljs-keyword">end</span>
  31. <span class="hljs-keyword">endmodule</span>