prod2u_p4_production_defaults_tb.v 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. `timescale 1ns/1ps
  2. module prod2u_p4_production_defaults_tb;
  3. reg sys_clk = 1'b0;
  4. reg host_uart_rx = 1'b1;
  5. reg x_limit_raw = 1'b0;
  6. reg y_limit_raw = 1'b0;
  7. wire host_uart_tx;
  8. wire [23:0] ptc_pwm_out;
  9. wire [3:0] fan_pwm_out;
  10. wire solenoid_out;
  11. wire motor_en_n;
  12. wire x_step;
  13. wire x_dir;
  14. wire y_step;
  15. wire y_dir;
  16. wire z_step;
  17. wire z_dir;
  18. always #20 sys_clk = ~sys_clk;
  19. prod2u_p4_normal_v3_top #(
  20. .POR_CYCLES(4),
  21. .SOLENOID_ACTIVE_HIGH(1)
  22. ) dut (
  23. .sys_clk(sys_clk),
  24. .host_uart_rx(host_uart_rx),
  25. .host_uart_tx(host_uart_tx),
  26. .ptc_pwm_out(ptc_pwm_out),
  27. .fan_pwm_out(fan_pwm_out),
  28. .solenoid_out(solenoid_out),
  29. .motor_en_n(motor_en_n),
  30. .x_step(x_step),
  31. .x_dir(x_dir),
  32. .y_step(y_step),
  33. .y_dir(y_dir),
  34. .z_step(z_step),
  35. .z_dir(z_dir),
  36. .x_limit_raw(x_limit_raw),
  37. .y_limit_raw(y_limit_raw)
  38. );
  39. task check_integer;
  40. input [8*48-1:0] label_text;
  41. input integer actual;
  42. input integer expected;
  43. begin
  44. if (actual != expected) begin
  45. $display("DEFAULT_FAIL %0s actual=%0d expected=%0d",
  46. label_text, actual, expected);
  47. $fatal(1);
  48. end
  49. end
  50. endtask
  51. initial begin
  52. #1;
  53. check_integer("watchdog seconds", dut.WATCHDOG_SECONDS, 5);
  54. check_integer("dir setup cycles", dut.MOTOR_DIR_SETUP_CYCLES, 25000);
  55. check_integer("step half cycles", dut.MOTOR_STEP_HALF_CYCLES, 12500);
  56. check_integer("core dir setup", dut.u_core.DIR_SETUP_CYCLES, 25000);
  57. check_integer("core step half", dut.u_core.STEP_HALF_CYCLES, 12500);
  58. check_integer("hub dir setup", dut.u_core.u_motors.DIR_SETUP_CYCLES, 25000);
  59. check_integer("hub step half", dut.u_core.u_motors.STEP_HALF_CYCLES, 12500);
  60. check_integer("X dir setup", dut.u_core.u_motors.u_x_axis.DIR_SETUP_CYCLES, 25000);
  61. check_integer("Y dir setup", dut.u_core.u_motors.u_y_axis.DIR_SETUP_CYCLES, 25000);
  62. check_integer("X step half", dut.u_core.u_motors.u_x_axis.STEP_HALF_CYCLES, 12500);
  63. check_integer("Y step half", dut.u_core.u_motors.u_y_axis.STEP_HALF_CYCLES, 12500);
  64. check_integer("X JOG counter bits", $bits(dut.u_core.u_motors.u_x_axis.remaining_steps), 16);
  65. check_integer("Y JOG counter bits", $bits(dut.u_core.u_motors.u_y_axis.remaining_steps), 16);
  66. wait (dut.sys_rst_n === 1'b1);
  67. repeat (4) @(posedge sys_clk);
  68. #1;
  69. if (motor_en_n || x_step || y_step || z_step ||
  70. dut.disabled !== 1'b1 || dut.watchdog_timeout !== 1'b0) begin
  71. $display("DEFAULT_SAFE_FAIL en_n=%0d step=%0d%0d%0d disabled=%0d timeout=%0d",
  72. motor_en_n, z_step, y_step, x_step,
  73. dut.disabled, dut.watchdog_timeout);
  74. $fatal(1);
  75. end
  76. $display("PASS: prod2u_p4_production_defaults_tb");
  77. $finish;
  78. end
  79. endmodule