| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- `timescale 1ns/1ps
- `include "src/generated/prod2u_door_temp_params.vh"
- // Top startup: axes begin on close limit, measure-open until open limit after
- // >=2 gated STEP rises, then sticky startup_complete.
- module prod2u_p4_normal_v3_top_startup_tb;
- reg sys_clk = 1'b0;
- reg host_uart_rx = 1'b1;
- wire host_uart_tx;
- wire [7:0] ptc_pwm_out;
- wire [3:0] fan_pwm_out;
- wire motor_en_n;
- wire x_step, x_dir, y_step, y_dir, z_step, z_dir;
- reg x_limit_ls = 1'b1;
- reg x_limit_hs = 1'b0;
- reg y_limit_ls = 1'b1;
- reg y_limit_hs = 1'b0;
- reg z_limit_ls = 1'b1;
- reg z_limit_hs = 1'b0;
- wire temp_scl, temp_sda;
- integer x_rises;
- integer y_rises;
- integer z_rises;
- always #20 sys_clk = ~sys_clk;
- prod2u_p4_normal_v3_top dut (
- .sys_clk(sys_clk), .host_uart_rx(host_uart_rx), .host_uart_tx(host_uart_tx),
- .ptc_pwm_out(ptc_pwm_out), .fan_pwm_out(fan_pwm_out), .motor_en_n(motor_en_n),
- .x_step(x_step), .x_dir(x_dir), .y_step(y_step), .y_dir(y_dir),
- .z_step(z_step), .z_dir(z_dir),
- .x_limit_ls(x_limit_ls), .x_limit_hs(x_limit_hs),
- .y_limit_ls(y_limit_ls), .y_limit_hs(y_limit_hs),
- .z_limit_ls(z_limit_ls), .z_limit_hs(z_limit_hs),
- .temp_scl(temp_scl), .temp_sda(temp_sda)
- );
- always @(posedge x_step) x_rises = x_rises + 1;
- always @(posedge y_step) y_rises = y_rises + 1;
- always @(posedge z_step) z_rises = z_rises + 1;
- initial begin
- #200_000_000 $fatal(1, "top_startup_tb timeout sc=%b rises=%0d/%0d/%0d",
- dut.startup_complete, x_rises, y_rises, z_rises);
- end
- initial begin
- x_rises = 0; y_rises = 0; z_rises = 0;
- // Wait until each axis produced >=2 open-direction rises, then hit open.
- begin : wait_rises
- integer k;
- for (k = 0; k < 5_000_000; k = k + 1) begin
- @(posedge sys_clk);
- if (x_rises >= 2 && y_rises >= 2 && z_rises >= 2)
- disable wait_rises;
- end
- $fatal(1, "insufficient measure rises x=%0d y=%0d z=%0d",
- x_rises, y_rises, z_rises);
- end
- x_limit_hs = 1'b1; y_limit_hs = 1'b1; z_limit_hs = 1'b1;
- x_limit_ls = 1'b0; y_limit_ls = 1'b0; z_limit_ls = 1'b0;
- begin : wait_sc
- integer k;
- for (k = 0; k < 200_000; k = k + 1) begin
- @(posedge sys_clk);
- if (dut.startup_complete) disable wait_sc;
- end
- $fatal(1, "startup_complete not reached");
- end
- if (motor_en_n !== 1'b1)
- $fatal(1, "EN must remain permanent_high");
- repeat (100) @(posedge sys_clk);
- if (!dut.startup_complete)
- $fatal(1, "startup_complete not sticky");
- $display("prod2u_p4_normal_v3_top_startup_tb PASS");
- $finish;
- end
- endmodule
|