This is doing the right thing in simulation... But in reality I am worried about the always @o_done edge... Again no warnings...
// Burst B o_clk then wait for a reset with flip every N i_clk
module divRNRB #(
parameter c_SIZE = 16, // Size of the counters in bits
parameter c_DELAY = 0 // start after c_DELAY*i_clk
) (
input wire [c_SIZE-1:0] i_N, // N*i_clk count before o_clk flip
input wire [c_SIZE-1:0] i_B, // B*o_clk then stop
input wire i_reset, // async reset , o_clk does not end on a i_clk edge
input wire i_clk, // Input clock
output reg o_done, // True means ready to start again.
output reg o_clk // Clock burst out
);
initial o_clk = 1'b0;
initial o_done = 1'b0;
reg [c_SIZE-1:0] r_clkcount = c_DELAY;
reg [c_SIZE-1:0] r_burstcount;
initial r_burstcount = i_B;
// Count of i_clk
always @ (negedge i_clk or negedge i_reset or posedge o_done) begin
if (~i_reset) begin
o_clk <= 1'b0;
r_clkcount <= c_DELAY;
end else begin // Reset low state here
if (o_done) begin
o_clk <= 1'b0;
end else begin
if (r_clkcount > 0) begin
r_clkcount <= r_clkcount - 1'b1;
end else begin
o_clk <= ~o_clk;
r_clkcount <= i_N;
end
end
end
end
// Count of o_clk
always @(posedge o_clk or negedge i_reset) begin
if (~i_reset) begin
o_done <= 1'b0;
r_burstcount <= i_B;
end else begin
if (o_clk) begin
if ( r_burstcount > 0 ) begin
r_burstcount <= r_burstcount - 1'b1;
end else begin
o_done <= 1'b1;
end
end
end
end
endmodule
`timescale 1ns / 1ps
module TestdivRNRB;
// Inputs
reg i_reset;
reg i_clk;
// Outputs
wire o_done;
wire o_clk;
// Instantiate the Unit Under Test (UUT)
divRNRB # (
.c_DELAY(4)
)uut (
.i_N(16'd2),
.i_B(16'd10),
.i_reset(i_reset),
.i_clk(i_clk),
.o_done(o_done),
.o_clk(o_clk)
);
initial begin
i_reset = 0;
i_clk = 0;
#50
i_reset = 1;
end
always #5 begin
i_clk <= ~i_clk;
end
endmodule
Is there a way not generating warnings and errors that will simplify this schematic ?
The async reset is nice as the burst may be triggered every 1 second and having to wait >1second is not ideal.
If I use (reset) instead of (~reset) the synthesis is not happy at all...