Advertisement
STANAANDREY

ac sapt9

Nov 22nd, 2023
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. module prod(
  2. input clk, rst_b
  3. output reg val,
  4. output reg[7:0] data
  5. );
  6. integer cntv, cntiv;
  7. always @(posedge clk, negedge rst_b)
  8. if (rst_b == 0) begin
  9. val <= 0;
  10. cntv <= 1;
  11. end else if (cntv == 1) begin
  12. val <= 1;
  13. cntv <= cntv - 1;
  14. end
  15. if (cntv == 1) begin
  16. val <= 0;
  17. cntiv <= $urandom_range(1,4);
  18. end else
  19. data <= $urandom_range(0,5);
  20. end else if (cntiv > 0) begin
  21. val <= 0;
  22. cntiv <= cntiv - 1;
  23. if (cntiv == 1) begin
  24. val <= 1;
  25. data <= $urandom_range(0,5);
  26. cntv <= $urandom_range(3,5);
  27. end
  28. end
  29.  
  30. endmodule
  31.  
  32. module cons(
  33. input clk, rst_b, val,
  34. input[7:0] data,
  35. output reg[7:0] sum
  36. );
  37. always @(posedge clk, negedge rst_b)
  38. if (rst_b == 0)
  39. sum <= 0;
  40. else if (val == 1)
  41. sum <= sum + data;
  42. endmodule
  43.  
  44. module prod_tb;
  45. reg clk, rst_b;
  46. wire val;
  47. wire [7:0] data, sum;
  48.  
  49. prod inst1(.clk(clk), .rst_b(rst_b), .val(val), .data(data));
  50. cons inst2(.clk(clk), .rst_b(rst_b), .val(val), .data(data), .sum(sum));
  51. localparam CLK_PERIOD=100, RUNNINGCYCLES=100, RST_DURATION=25;
  52. initial begin
  53. $display("time\tclk\trst_b\tval\tdata");
  54. $monitor(%5t\t%b\t%b\t%b\t%1d", $time, clk, rst_b, val, data);
  55. clk=0;
  56. repeat (2*RUNNING_CYCLES) #(CLK_PERIOD/2) clk=~clk;
  57. end
  58. initial begin
  59. rst_b = 0;
  60. $RST_DURANTION rst_b=~rst_b;
  61. end
  62. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement