| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- `timescale 1ns/1ps
- module door_motor_engine_tb;
- reg clk = 1'b0;
- reg rst_n = 1'b0;
- reg start = 1'b0;
- reg inlet_dir = 1'b0;
- reg outlet_dir = 1'b1;
- wire busy;
- wire done;
- wire x_step;
- wire x_dir;
- wire y_step;
- wire y_dir;
- integer x_rises;
- integer y_rises;
- reg previous_x_step;
- reg previous_y_step;
- always #1 clk = ~clk;
- always @(posedge clk) begin
- if (x_step && !previous_x_step) x_rises = x_rises + 1;
- if (y_step && !previous_y_step) y_rises = y_rises + 1;
- previous_x_step = x_step;
- previous_y_step = y_step;
- end
- door_motor_engine #(
- .FIXED_STEPS(3), .STEP_HALF_CYCLES(2), .DIR_SETUP_CYCLES(2)
- ) dut (
- .clk(clk), .rst_n(rst_n), .start(start),
- .inlet_dir(inlet_dir), .outlet_dir(outlet_dir),
- .busy(busy), .done(done), .x_step(x_step), .x_dir(x_dir),
- .y_step(y_step), .y_dir(y_dir)
- );
- initial begin
- x_rises = 0;
- y_rises = 0;
- previous_x_step = 1'b0;
- previous_y_step = 1'b0;
- repeat (3) @(posedge clk);
- rst_n = 1'b1;
- @(negedge clk);
- start = 1'b1;
- @(negedge clk);
- start = 1'b0;
- wait (done);
- if (x_rises !== 3 || y_rises !== 3) $fatal(1, "step count mismatch x=%0d y=%0d", x_rises, y_rises);
- if (x_dir !== inlet_dir || y_dir !== outlet_dir) $fatal(1, "direction mismatch");
- if (busy || x_step || y_step) $fatal(1, "motor not idle after completion");
- $display("door_motor_engine_tb PASS");
- $finish;
- end
- endmodule
|