当前位置:   article > 正文

IC验证学习笔记(手撕代码)-3.1用verilog实现3.5分频电路_ic验证项目实例

ic验证项目实例

在这里插入图片描述

  1. module f35 (clk,rst,clk2);
  2. input clk,rst;
  3. output clk2;
  4. reg posedge_clk;
  5. reg negedge_clk;
  6. reg [2:0]posedge_count;
  7. reg [2:0]negedge_count;
  8. always@(posedge clk or negedge rst)begin
  9. if(!rst || posedge_count==3'd6)
  10. posedge_count<=0;
  11. else posedge_count<=posedge_count+1;
  12. end
  13. always@(negedge clk or negedge rst)begin
  14. if(!rst||negedge_count==3'd6)
  15. negedge_count<=0;
  16. else negedge_count<=negedge_count+1'd1;
  17. end
  18. always@(posedge clk or negedge rst)begin
  19. if(!rst)
  20. posedge_clk<=0;
  21. else if (posedge_count==0||posedge_count==3'd1)
  22. posedge_clk<=!posedge_clk;
  23. else
  24. posedge_clk<=posedge_clk;
  25. end
  26. always@(negedge clk or negedge rst)begin
  27. if(!rst)
  28. negedge_clk<=0;
  29. else if (negedge_count==3'd3||negedge_count==3'd4)
  30. negedge_clk<=!negedge_clk;
  31. else
  32. negedge_clk<=negedge_clk;
  33. end
  34. assign clk2=posedge_clk||negedge_clk;
  35. endmodule

posedge_clk:在0、1翻转 negedge_clk:在3、4翻转 然后或操作

 testbench:

  1. `timescale 1ns/1ps
  2. module f35_tb();
  3. reg clk;
  4. reg rst;
  5. wire clk2;
  6. f35 u1(.clk(clk),.rst(rst),.clk2(clk2));
  7. always
  8. #5 clk=~clk;
  9. initial begin
  10. clk=0;
  11. rst=1;
  12. #15 rst=0;
  13. #30 rst=1;
  14. #300;
  15. $stop;
  16. end
  17. endmodule

波形: 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/519146?site
推荐阅读
相关标签
  

闽ICP备14008679号