Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. //----------------------------------------
  2. //module bit stream generator
  3. //-----------------------------------------
  4.  
  5. module generator(
  6. clk,
  7. stream //generated stream
  8. );
  9. output stream;
  10. input clk;
  11. reg c;
  12. wire stream;
  13. assign stream=c;
  14.  
  15. initial
  16. begin
  17. c=1'd0;
  18. end
  19.  
  20. always@(posedge clk)
  21. begin
  22. //c=!c;
  23. c = {$random} %2;
  24. //$display("a= %b",c);
  25. end
  26. endmodule
  27.  
  28.  
  29.  
  30. //----------------------------------------
  31. //module D flip flip
  32. //-----------------------------------------
  33.  
  34. module d(q_w,q0_w,d,c);
  35. output q_w,q0_w;
  36. input c,d;
  37.  
  38. //wire c;
  39. reg q,q0;
  40. wire q_w,q0_w;
  41. assign q_w=q;
  42. assign q0_w=q0;
  43.  
  44. initial
  45. begin
  46. q=1'b0; q0=1'b1;
  47. end
  48. always @ (posedge c)
  49. begin
  50. q=d;
  51. q0= ~d;
  52. end
  53. endmodule
  54.  
  55.  
  56. //----------------------------------------
  57. //module sequencedetector
  58. //-----------------------------------------
  59.  
  60. module sequencedetector(
  61. clk,
  62. x, //input bit stream
  63. out //output from sequence detector
  64. );
  65.  
  66. input x,clk;
  67. output out;
  68.  
  69. wire x,y0,y_0,y1,y_1,g12,g32,g2d1,out;
  70.  
  71. d dff1(.q_w(y1),.q0_w(y_1),.d(g2d1),.c(clk)); //flip flop D1
  72. d dff0(.q_w(y0),.q0_w(y_0),.d(x),.c(clk)); //Flip Flop D2
  73.  
  74. and gate1(g12,x,y0);
  75. or gate2(g2d1,g12,g32);
  76. and gate3(g32,y1,y0);
  77. and gate4(out,x,y_0,y1);
  78.  
  79. endmodule
  80.  
  81.  
  82. //----------------------------------------
  83. //module sequencedetector testbench
  84. //-----------------------------------------
  85.  
  86. module sequencedetector_tb;
  87.  
  88. reg clk;
  89. wire out,x;
  90.  
  91. sequencedetector UUT(
  92. .clk(clk),
  93. .x(x),
  94. .out(out));
  95.  
  96. generator UUTgen(
  97. .clk(clk),
  98. .stream(x));
  99.  
  100.  
  101.  
  102. initial begin
  103. clk=1'b0;
  104. //stream=1'b0;
  105. //=1'b0;
  106. end
  107.  
  108. initial
  109. begin
  110. $dumpfile ("counter.vcd");
  111. $dumpvars(0);
  112. end
  113.  
  114. always
  115. begin
  116. #20 clk=!clk;
  117. end
  118.  
  119. initial
  120. begin
  121. #20000 $finish;
  122. end
  123. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement