| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- `timescale 1ns/1ps
- module actuator_domain_tb;
- reg clk;
- reg rst_n;
- reg pid_valid;
- reg [4:0] pid_channel;
- reg signed [17:0] pid_ctrl_q;
- reg pid_fault;
- reg global_enable;
- reg fault_latched;
- reg [3:0] fault_code;
- reg motor_open_req;
- reg motor_close_req;
- reg button_open_req;
- reg button_close_req;
- reg limit_open;
- reg limit_close;
- reg [5:0] fan_tach_in;
- reg interlock;
- wire ptc_enable;
- wire [4:0] ptc_channel;
- wire [17:0] ptc_duty_or_level;
- wire ptc_force_off;
- wire [3:0] ptc_reason;
- wire fan_enable;
- wire [17:0] fan_duty_or_level;
- wire fan_force_off;
- wire [3:0] fan_reason;
- wire motor_enable;
- wire [1:0] motor_dir;
- wire motor_force_off;
- wire [3:0] motor_reason;
- wire [23:0] ptc_bank_enable;
- wire [23:0] ptc_bank_force_off;
- wire [24*18-1:0] ptc_bank_duty_or_level;
- wire [23:0] ptc_pwm_out;
- wire [5:0] fan_pwm_enable;
- wire [5:0] fan_pwm_logic_high;
- wire [5:0] fan_pwm_drive_low;
- wire [6*16-1:0] fan_tach_count;
- wire [6*16-1:0] fan_tach_window_edges;
- wire [6*16-1:0] fan_rpm_estimate;
- wire [1:0] motor_state;
- wire [1:0] limit_status;
- wire [1:0] button_status;
- actuator_domain dut (
- .clk(clk),
- .rst_n(rst_n),
- .pid_valid(pid_valid),
- .pid_channel(pid_channel),
- .pid_ctrl_q(pid_ctrl_q),
- .pid_fault(pid_fault),
- .global_enable(global_enable),
- .fault_latched(fault_latched),
- .fault_code(fault_code),
- .motor_open_req(motor_open_req),
- .motor_close_req(motor_close_req),
- .button_open_req(button_open_req),
- .button_close_req(button_close_req),
- .limit_open(limit_open),
- .limit_close(limit_close),
- .fan_tach_in(fan_tach_in),
- .interlock(interlock),
- .ptc_enable(ptc_enable),
- .ptc_channel(ptc_channel),
- .ptc_duty_or_level(ptc_duty_or_level),
- .ptc_force_off(ptc_force_off),
- .ptc_reason(ptc_reason),
- .fan_enable(fan_enable),
- .fan_duty_or_level(fan_duty_or_level),
- .fan_force_off(fan_force_off),
- .fan_reason(fan_reason),
- .motor_enable(motor_enable),
- .motor_dir(motor_dir),
- .motor_force_off(motor_force_off),
- .motor_reason(motor_reason),
- .ptc_bank_enable(ptc_bank_enable),
- .ptc_bank_force_off(ptc_bank_force_off),
- .ptc_bank_duty_or_level(ptc_bank_duty_or_level),
- .ptc_pwm_out(ptc_pwm_out),
- .fan_pwm_enable(fan_pwm_enable),
- .fan_pwm_logic_high(fan_pwm_logic_high),
- .fan_pwm_drive_low(fan_pwm_drive_low),
- .fan_tach_count(fan_tach_count),
- .fan_tach_window_edges(fan_tach_window_edges),
- .fan_rpm_estimate(fan_rpm_estimate),
- .motor_state(motor_state),
- .limit_status(limit_status),
- .button_status(button_status)
- );
- initial begin
- clk = 1'b0;
- forever #5 clk = ~clk;
- end
- task pulse_pid;
- input [4:0] channel;
- input signed [17:0] ctrl;
- begin
- pid_channel = channel;
- pid_ctrl_q = ctrl;
- pid_valid = 1'b1;
- @(negedge clk);
- pid_valid = 1'b0;
- @(negedge clk);
- end
- endtask
- initial begin
- rst_n = 1'b0;
- pid_valid = 1'b0;
- pid_channel = 5'd0;
- pid_ctrl_q = 18'sd0;
- pid_fault = 1'b0;
- global_enable = 1'b1;
- fault_latched = 1'b0;
- fault_code = 4'd0;
- motor_open_req = 1'b0;
- motor_close_req = 1'b0;
- button_open_req = 1'b0;
- button_close_req = 1'b0;
- limit_open = 1'b0;
- limit_close = 1'b0;
- fan_tach_in = 6'd0;
- interlock = 1'b0;
- repeat (4) @(negedge clk);
- rst_n = 1'b1;
- pulse_pid(5'd2, 18'sd90);
- if (!ptc_enable || ptc_force_off || ptc_duty_or_level !== 18'd90 || ptc_reason !== 4'd0 ||
- !ptc_bank_enable[2] || ptc_bank_force_off[2] || ptc_bank_duty_or_level[(2*18) +: 18] !== 18'd90 ||
- !ptc_pwm_out[2]) begin
- $display("normal PTC route mismatch");
- $fatal;
- end
- if (!fan_enable || fan_duty_or_level !== 18'd38 || !fan_pwm_logic_high[0] || fan_pwm_drive_low[0]) begin
- $display("safe actuator domain should drive fixed low fan pwm");
- $fatal;
- end
- pulse_pid(5'd24, 18'sd90);
- if (!ptc_force_off || ptc_reason !== 4'd6) begin
- $display("invalid channel should force off PTC");
- $fatal;
- end
- fault_latched = 1'b1;
- fault_code = 4'd5;
- pulse_pid(5'd1, 18'sd80);
- if (!ptc_force_off || ptc_reason !== 4'd5) begin
- $display("fault should force off PTC");
- $fatal;
- end
- if (!fan_enable || fan_force_off || fan_duty_or_level !== 18'd127 || fan_reason !== 4'd5) begin
- $display("overtemp should drive fan fallback");
- $fatal;
- end
- if (fan_pwm_enable !== 6'h3f || !fan_pwm_logic_high[0] || fan_pwm_drive_low[0]) begin
- $display("overtemp fan fallback should enable all fan pwm outputs");
- $fatal;
- end
- if (ptc_pwm_out !== 24'd0) begin
- $display("overtemp should force all ptc pwm outputs off");
- $fatal;
- end
- fault_latched = 1'b0;
- fault_code = 4'd0;
- global_enable = 1'b1;
- motor_open_req = 1'b1;
- @(negedge clk);
- if (!motor_enable || motor_dir !== 2'd1 || motor_force_off || motor_state !== 2'd1) begin
- $display("motor should open when safe and not at limit");
- $fatal;
- end
- limit_open = 1'b1;
- @(negedge clk);
- if (motor_enable || motor_dir !== 2'd0) begin
- $display("motor should stop at open limit");
- $fatal;
- end
- fault_latched = 1'b1;
- fault_code = 4'd7;
- interlock = 1'b1;
- @(negedge clk);
- if (!motor_force_off || motor_reason !== 4'd7) begin
- $display("interlock should force off motor");
- $fatal;
- end
- $display("PASS: actuator_domain_tb");
- $finish;
- end
- endmodule
|