Projektdaten für das ESY1B Praktikum im Sommersemester 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

random_tl.sv 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Project: ESY-Praktikum-Testbench
  2. // File: random_tl.sv
  3. // Title: Random Testbench Toplevel
  4. // Description: Creates a Testbench that tests the Toplevel-Design with random based verifikation
  5. //
  6. //
  7. // --------------------------------------------------------------------
  8. //
  9. //------------------------------------------------------------
  10. // Notes:
  11. //
  12. //
  13. //------------------------------------------------------------
  14. // Development History:
  15. //
  16. // __DATE__ _BY_ _REV_ _DESCRIPTION___________________________
  17. // 14/06/22 JU/TL 1.0 Initial testbench design
  18. //
  19. //------------------------------------------------------------
  20. // Dependencies:
  21. // Toplevel-Design
  22. //
  23. //
  24. //------------------------------------------------------------
  25. //------------------------------------------------------------
  26. //
  27. //
  28. // Testbench
  29. //
  30. //------------------------------------------------------------
  31. class Taster_rnd;
  32. rand bit [1:0] data;
  33. constraint Rst_rnd
  34. {
  35. data dist {0:=70,1 :=30};
  36. }
  37. endclass
  38. class Data_ADC_rnd;
  39. rand bit [7:0] data;
  40. endclass
  41. `timescale 1ns/1ps
  42. module tb;
  43. // inputs and outputs
  44. reg taster;
  45. reg [7:0]data_ADC;
  46. reg clk12M;
  47. wire RED;
  48. wire GRN;
  49. wire alarm;
  50. wire alarm_r;
  51. wire SI;
  52. wire SO;
  53. wire SCK;
  54. wire nCS;
  55. reg endOfConvRnd;
  56. //random
  57. Taster_rnd taster_rnd = new();
  58. Data_ADC_rnd data_ADC_rnd = new();
  59. // connect module
  60. SPI_FRAM_Module fram_storage(
  61. .SI(SI),
  62. .SO(SO),
  63. .SCK(SCK),
  64. .nCS(nCS),.opcode(),.addr());
  65. Top top(.clk(clk12M),.rst(taster),.endOfConv(endOfConvRnd),.LEDg(GRN),.LEDr(RED),.AlarmAmpel(alarm),.Alarm_R(alarm_r));
  66. initial
  67. begin
  68. clk12M=1'b0;
  69. end
  70. always
  71. #41.666666 clk12M=~clk12M; //clock generation
  72. //random test
  73. initial begin
  74. endOfConvRnd = 1;
  75. repeat (2) begin
  76. #100000000
  77. #100000000
  78. #100000000
  79. #100000000
  80. #100000000
  81. #100000000
  82. #100000000
  83. #100000000
  84. #100000000
  85. #100000000
  86. data_ADC_rnd.randomize();
  87. taster_rnd.randomize();
  88. taster = taster_rnd.data;
  89. data_ADC = data_ADC_rnd.data;
  90. // assertions
  91. // assert color green
  92. assert property(@(posedge clk12M) disable iff (alarm | alarm_r) ((data_ADC < 100) |=> ##4 (!RED && GRN)));
  93. //assert color yellow
  94. assert property(@(posedge clk12M) disable iff (alarm | alarm_r) (((data_ADC >= 100) && (data_ADC <= 168))|=> ##4 (RED && GRN)));
  95. //assert color red + alarm
  96. assert property(@(posedge clk12M) disable iff (alarm_r) (data_ADC > 168) |=> ##4 (RED && !GRN && alarm));
  97. //assert alarm reset working
  98. assert property(@(posedge clk12M) (alarm_r |=> ##4 (!RED && !GRN && !alarm)));
  99. $monitor("time=%t, data_ADC=%d, RED=%d, GRN=%d, taster=%d",$time,data_ADC, RED, GRN, taster);
  100. end
  101. $stop;
  102. end
  103. endmodule