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.

testbench_random.sv 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // ==================================================================
  2. // >>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<
  3. // ------------------------------------------------------------------
  4. // Copyright (c) 2017 by Lattice Semiconductor Corporation
  5. // ALL RIGHTS RESERVED
  6. // ------------------------------------------------------------------
  7. //
  8. // Permission:
  9. //
  10. // Lattice SG Pte. Ltd. grants permission to use this code
  11. // pursuant to the terms of the Lattice Reference Design License Agreement.
  12. //
  13. //
  14. // Disclaimer:
  15. //
  16. // This VHDL or Verilog source code is intended as a design reference
  17. // which illustrates how these types of functions can be implemented.
  18. // It is the user's responsibility to verify their design for
  19. // consistency and functionality through the use of formal
  20. // verification methods. Lattice provides no warranty
  21. // regarding the use or functionality of this code.
  22. //
  23. // --------------------------------------------------------------------
  24. //
  25. // Lattice SG Pte. Lt++++++++++++++++d.
  26. // 101 Thomson Road, United Square #07-02
  27. // Singapore 307591
  28. //
  29. //
  30. // TEL: 1-800-Lattice (USA and Canada)
  31. // +65-6631-2000 (Singapore)
  32. // +1-503-268-8001 (other locations)
  33. //
  34. // web: http://www.latticesemi.com/
  35. // email: techsupport@latticesemi.com
  36. //
  37. // --------------------------------------------------------------------
  38. //
  39. // Project: iCE5UP 5K RGB LED Tutorial
  40. // File: testbench.v
  41. // Title: LED PWM control
  42. // Description: Creates RGB PWM per control inputs
  43. //
  44. //
  45. // --------------------------------------------------------------------
  46. //
  47. //------------------------------------------------------------
  48. // Notes:
  49. //
  50. //
  51. //------------------------------------------------------------
  52. // Development History:
  53. //
  54. // __DATE__ _BY_ _REV_ _DESCRIPTION___________________________
  55. // 04/05/17 RK 1.0 Initial tutorial design for Lattice Radiant
  56. //
  57. //------------------------------------------------------------
  58. // Dependencies:
  59. //
  60. //
  61. //
  62. //------------------------------------------------------------
  63. //------------------------------------------------------------
  64. //
  65. //
  66. // Testbench
  67. //
  68. //------------------------------------------------------------
  69. class Rst_rnd;
  70. rand bit [1:0] data;
  71. constraint Rst_rnd
  72. {
  73. data dist {0:=70,1 :=30};
  74. }
  75. endclass
  76. class Data_valid_rnd;
  77. rand bit [1:0] data;
  78. constraint Data_valid_data
  79. {
  80. data dist {0:=10,1 :=90};
  81. }
  82. endclass
  83. class Data_input_rnd;
  84. rand bit [7:0] data;
  85. endclass
  86. `timescale 1ns/1ps
  87. // inputs and outputs
  88. module tb;
  89. reg clk12M;
  90. reg rst;
  91. reg [7:0]data_input;
  92. reg data_valid;
  93. wire RED;
  94. wire GRN;
  95. wire alarm;
  96. //random
  97. Rst_rnd rst_rnd = new();
  98. Data_valid_rnd data_valid_rnd = new();
  99. Data_input_rnd data_input_rnd = new();
  100. // connect module
  101. led_top dut(.clk12M(clk12M),
  102. .rst(rst),
  103. .data_input(data_input),
  104. .data_valid(data_valid),
  105. .RED(RED),
  106. .GRN(GRN),
  107. .alarm(alarm)
  108. );
  109. //clock
  110. initial
  111. begin
  112. clk12M=1'b0;
  113. end
  114. always
  115. #41.666666 clk12M=~clk12M; //clock generation
  116. int cycles = 0;
  117. //random test
  118. initial begin
  119. repeat (50) begin
  120. #50000
  121. cycles =cycles+1;
  122. rst_rnd.randomize();
  123. data_input_rnd.randomize();
  124. data_valid_rnd.randomize();
  125. rst = rst_rnd.data;
  126. data_input = data_input_rnd.data;
  127. data_valid = data_valid_rnd.data;
  128. // assertions
  129. // assert that reset resets
  130. assert property ( @(posedge clk12M) (##1 rst) |=> !alarm);
  131. // assert color green
  132. assert property(@(posedge clk12M) disable iff (rst | !data_valid| alarm) ((data_input < 100) |=> ##4 (!RED && GRN));
  133. //assert color yellow
  134. assert property(@(posedge clk12M) disable iff (rst | !data_valid| alarm) ((data_input >= 100) && (data_input <= 168))|=> ##4 (RED && GRN));
  135. //assert color red + alarm
  136. assert property(@(posedge clk12M) disable iff (rst | !data_valid) (data_input > 168) |=> ##4 (RED && !GRN && alarm));
  137. $monitor("time=%t,cycle%d, rst=%d, data_input=%d, data_valid = %d, RED=%d, GRN=%d, alarm=%d",$time,cycles,rst,data_input, data_valid, RED, GRN, alarm);
  138. end
  139. $stop;
  140. end
  141. endmodule