| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- `timescale 1ns/1ps
- module prod2u_p4_pwm_outputs_tb;
- reg clk;
- reg rst_n;
- reg [191:0] ptc_percent;
- reg [31:0] fan_percent;
- reg [7:0] solenoid_percent;
- wire [23:0] ptc_pwm_out;
- wire [3:0] fan_pwm_out;
- wire solenoid_on;
- integer cycle;
- integer ptc_high;
- integer fan_raw_high;
- prod2u_p4_pwm_outputs #(
- .PTC_STEP_CLKS(1),
- .FAN_STEP_CLKS(1)
- ) dut (
- .clk(clk),
- .rst_n(rst_n),
- .ptc_percent(ptc_percent),
- .fan_percent(fan_percent),
- .solenoid_percent(solenoid_percent),
- .ptc_pwm_out(ptc_pwm_out),
- .fan_pwm_out(fan_pwm_out),
- .solenoid_on(solenoid_on)
- );
- initial begin
- clk = 1'b0;
- forever #5 clk = ~clk;
- end
- initial begin
- rst_n = 1'b0;
- ptc_percent = 192'd0;
- fan_percent = {8'd100, 8'd0, 8'd70, 8'd30};
- ptc_percent[7:0] = 8'd10;
- ptc_percent[15:8] = 8'd100;
- solenoid_percent = 8'd0;
- repeat (3) @(negedge clk);
- rst_n = 1'b1;
- ptc_high = 0;
- fan_raw_high = 0;
- for (cycle = 0; cycle < 100; cycle = cycle + 1) begin
- @(negedge clk);
- if (ptc_pwm_out[0]) ptc_high = ptc_high + 1;
- if (fan_pwm_out[0]) fan_raw_high = fan_raw_high + 1;
- if (ptc_pwm_out[1] !== 1'b1 || ptc_pwm_out[2] !== 1'b0 ||
- fan_pwm_out[1] !== (dut.fan_phase < 7'd30) ||
- fan_pwm_out[2] !== 1'b1 || fan_pwm_out[3] !== 1'b0) begin
- $display("PWM edge semantics mismatch cycle=%0d", cycle);
- $fatal;
- end
- end
- if (ptc_high !== 10 || fan_raw_high !== 70) begin
- $display("PWM duty mismatch ptc=%0d fan_raw=%0d", ptc_high, fan_raw_high);
- $fatal;
- end
- solenoid_percent = 8'd100;
- @(negedge clk);
- if (!solenoid_on) begin
- $display("solenoid logical output did not turn on at 100");
- $fatal;
- end
- solenoid_percent = 8'd0;
- @(negedge clk);
- if (solenoid_on) begin
- $display("solenoid logical output did not turn off at 0");
- $fatal;
- end
- $display("PASS: prod2u_p4_pwm_outputs_tb");
- $finish;
- end
- endmodule
|