| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- `timescale 1ns/1ps
- module ssr_time_proportion_tb;
- reg clk = 0, rst_n = 0;
- always #20 clk = ~clk;
- reg stage_we = 0, commit = 0, invalidate = 0;
- reg [5:0] stage_addr = 0;
- reg [7:0] stage_data = 0;
- reg [6:0] ext_phase = 0;
- wire [2:0] ssr_on;
- integer i, h0, h1, h2;
- reg measuring = 0;
- // Production 25 MHz clock and default 20 Hz PWM (1,250,000 clocks/period); no timer override.
- ssr_time_proportion dut (.*);
- always @(negedge clk) begin
- if (measuring) begin
- if (^ssr_on === 1'bx) $fatal(1,"undefined SSR outputs");
- h0 <= h0 + ssr_on[0];
- h1 <= h1 + ssr_on[1];
- h2 <= h2 + ssr_on[2];
- end
- end
- task stage;
- input [5:0] addr;
- input [7:0] value;
- begin
- @(negedge clk); stage_we = 1; stage_addr = addr; stage_data = value;
- @(negedge clk); stage_we = 0;
- end
- endtask
- task apply;
- begin
- @(negedge clk); commit = 1;
- @(negedge clk); commit = 0;
- end
- endtask
- task measure;
- input integer v0, v1, v2;
- begin
- @(negedge clk);
- h0=0; h1=0; h2=0;
- measuring = 1;
- #(1250000 * 40);
- measuring = 0;
- if(h0!=v0*12500 || h1!=v1*12500 || h2!=v2*12500)
- $fatal(1,"SSR duty mismatch %0d,%0d,%0d",h0,h1,h2);
- end
- endtask
- initial begin
- repeat(5) @(negedge clk); rst_n=1;
- measure(0,0,0);
- stage(32,1);stage(33,99);stage(34,100);
- measure(0,0,0); // staging alone has no output effect
- apply; measure(1,99,100);
- stage(32,50);stage(33,0);stage(34,20);
- measure(1,99,100); // partial/new inactive bank must not leak
- apply; measure(50,0,20);
- @(negedge clk); invalidate=1;
- @(negedge clk); invalidate=0;
- if(ssr_on !== 0) $fatal(1,"timeout must immediately disable all SSR");
- measure(0,0,0);
- apply; measure(50,0,20); // direct same-value recovery
- stage(32,100);stage(33,1);stage(34,0);
- apply; measure(100,1,0);
- $display("ssr_time_proportion_tb PASS: zero boot, staging isolation, 0/1/20/50/99/100 duty, shared phase, timeout and direct recovery");
- $finish;
- end
- initial begin #1000000000; $fatal(1,"SSR timeout"); end
- endmodule
|