prod2u_p4_normal_v3_top_startup_tb.v 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. `timescale 1ns/1ps
  2. `include "src/generated/prod2u_door_temp_params.vh"
  3. // Top startup: axes begin on close limit, measure-open until open limit after
  4. // >=2 gated STEP rises, then sticky startup_complete.
  5. module prod2u_p4_normal_v3_top_startup_tb;
  6. reg sys_clk = 1'b0;
  7. reg host_uart_rx = 1'b1;
  8. wire host_uart_tx;
  9. wire [7:0] ptc_pwm_out;
  10. wire [3:0] fan_pwm_out;
  11. wire motor_en_n;
  12. wire x_step, x_dir, y_step, y_dir, z_step, z_dir;
  13. reg x_limit_ls = 1'b1;
  14. reg x_limit_hs = 1'b0;
  15. reg y_limit_ls = 1'b1;
  16. reg y_limit_hs = 1'b0;
  17. reg z_limit_ls = 1'b1;
  18. reg z_limit_hs = 1'b0;
  19. wire temp_scl, temp_sda;
  20. integer x_rises;
  21. integer y_rises;
  22. integer z_rises;
  23. always #20 sys_clk = ~sys_clk;
  24. prod2u_p4_normal_v3_top dut (
  25. .sys_clk(sys_clk), .host_uart_rx(host_uart_rx), .host_uart_tx(host_uart_tx),
  26. .ptc_pwm_out(ptc_pwm_out), .fan_pwm_out(fan_pwm_out), .motor_en_n(motor_en_n),
  27. .x_step(x_step), .x_dir(x_dir), .y_step(y_step), .y_dir(y_dir),
  28. .z_step(z_step), .z_dir(z_dir),
  29. .x_limit_ls(x_limit_ls), .x_limit_hs(x_limit_hs),
  30. .y_limit_ls(y_limit_ls), .y_limit_hs(y_limit_hs),
  31. .z_limit_ls(z_limit_ls), .z_limit_hs(z_limit_hs),
  32. .temp_scl(temp_scl), .temp_sda(temp_sda)
  33. );
  34. always @(posedge x_step) x_rises = x_rises + 1;
  35. always @(posedge y_step) y_rises = y_rises + 1;
  36. always @(posedge z_step) z_rises = z_rises + 1;
  37. initial begin
  38. #200_000_000 $fatal(1, "top_startup_tb timeout sc=%b rises=%0d/%0d/%0d",
  39. dut.startup_complete, x_rises, y_rises, z_rises);
  40. end
  41. initial begin
  42. x_rises = 0; y_rises = 0; z_rises = 0;
  43. // Wait until each axis produced >=2 open-direction rises, then hit open.
  44. begin : wait_rises
  45. integer k;
  46. for (k = 0; k < 5_000_000; k = k + 1) begin
  47. @(posedge sys_clk);
  48. if (x_rises >= 2 && y_rises >= 2 && z_rises >= 2)
  49. disable wait_rises;
  50. end
  51. $fatal(1, "insufficient measure rises x=%0d y=%0d z=%0d",
  52. x_rises, y_rises, z_rises);
  53. end
  54. x_limit_hs = 1'b1; y_limit_hs = 1'b1; z_limit_hs = 1'b1;
  55. x_limit_ls = 1'b0; y_limit_ls = 1'b0; z_limit_ls = 1'b0;
  56. begin : wait_sc
  57. integer k;
  58. for (k = 0; k < 200_000; k = k + 1) begin
  59. @(posedge sys_clk);
  60. if (dut.startup_complete) disable wait_sc;
  61. end
  62. $fatal(1, "startup_complete not reached");
  63. end
  64. if (motor_en_n !== 1'b1)
  65. $fatal(1, "EN must remain permanent_high");
  66. repeat (100) @(posedge sys_clk);
  67. if (!dut.startup_complete)
  68. $fatal(1, "startup_complete not sticky");
  69. $display("prod2u_p4_normal_v3_top_startup_tb PASS");
  70. $finish;
  71. end
  72. endmodule