rayaprolu
Newbie level 5
- Joined
- Oct 9, 2013
- Messages
- 10
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 124
Hi,
I am trying to write a verilog code for a simple design of MUX and few ROs. I am very naive to verilog and hence not able to write it efficiently. Can some one help me write a synthesizable code for design attached with this post?
My code that i m trying to write is as follows but i am facing errors:
module top_tb ();
wire osc_out_tb;
reg in_tb, sel_tb;
top dut(in_tb, sel_tb, osc_out_tb);
initial begin
in_tb = 8'b00000001;
sel_tb = 3'b001;
#10 sel_tb=3'b010;
#10 sel_tb=3'b011;
end
endmodule
module top (in, sel, osc_out);
input [7:0] in;
input [2:0] sel;
wire [3:0] en;
output [3:0] osc_out ;
generic_RO u_generic_RO1( .en_G(en[0]), .osc_out_G(osc_out[0]));
generic_RO u_generic_RO2( .en_G(en[1]), .osc_out_G(osc_out[1]));
generic_RO u_generic_RO3( .en_G(en[2]), .osc_out_G(osc_out[2]));
generic_RO u_generic_RO4( .en_G(en[3]), .osc_out_G(osc_out[3]));
mux_top u_mux_top(.in (in),.sel (sel), .en_out (en) );
endmodule
module generic_RO (en_G, osc_out_G);
input en_G;
output osc_out_G;
reg [num-1:0] Rut_arr;
parameter num=25;
//reg Rut_AND = 1'b1;
genvar i;
generate
for(i=0; i<num; i=i+1) begin :inst
ringosc5 ringosc_n(
.Rosc_out (Rut_arr),
.en (en_G)
);
// Rut_AND = (Rut_arr && Rut_AND); //j variable will be constant for i=1 to 25.
//After 25 times of i, j increments 1 time.
end
//assign osc_out_G = Rut_AND;
endgenerate
endmodule
module ringosc5 (Rosc_out, en);
input en;
output Rosc_out;
wire Rosc_out;
reg [5:1] node /* synthesis keep*/;
reg Rosc_out_reg;
always @(Rosc_out or en)
begin
node[1]<= ~(node[5] & en);
node[2]<= ~node[1];
node[3]<= ~node[2];
node[4]<= ~node[3];
node[5]<= ~node[4];
Rosc_out_reg<=node[5];
end
assign Rosc_out = Rosc_out_reg;
endmodule
module mux_top(in,sel, en_out);
input [7:0] in;
input [2:0] sel;
output [3:0] en_out;
reg [3:0] en_out;
always @ (sel or in)
begin
case(sel)
3'b000 : begin
en_out[0] = in[0];
en_out[3:1] = 3'b0;
end
3'b001 : begin
en_out[0] = in[1];
en_out[3:1] = 3'b0;
end
3'b010 : begin
en_out[1] = in[2];
en_out[3:2] = 2'b0;
en_out[0] = 1'b0;
end
3'b011 : begin
en_out [1] = in[3];
en_out[3:2] = 2'b0;
en_out[0] = 1'b0;
end
3'b100 : begin
en_out[2] = in[4];
en_out[3] = 1'b0;
en_out[1:0] = 2'b0;
end
3'b101 : begin
en_out[2] = in[5];
en_out[3] = 1'b0;
en_out[1:0] = 2'b0;
end
3'b110 : begin
en_out[3] =in[6];
en_out[2:0] = 3'b0;
end
3'b111 : begin
en_out[3] = in[7];
en_out[2:0] = 3'b0;
end
endcase
end
endmodule
- - - Updated - - -
I forgot to mention, all the individual outputs of each RO, has to be tied together and AND them to draw it out on one pin. This will prevent the compiler to optimize and throw it away.
I am trying to write a verilog code for a simple design of MUX and few ROs. I am very naive to verilog and hence not able to write it efficiently. Can some one help me write a synthesizable code for design attached with this post?
My code that i m trying to write is as follows but i am facing errors:
module top_tb ();
wire osc_out_tb;
reg in_tb, sel_tb;
top dut(in_tb, sel_tb, osc_out_tb);
initial begin
in_tb = 8'b00000001;
sel_tb = 3'b001;
#10 sel_tb=3'b010;
#10 sel_tb=3'b011;
end
endmodule
module top (in, sel, osc_out);
input [7:0] in;
input [2:0] sel;
wire [3:0] en;
output [3:0] osc_out ;
generic_RO u_generic_RO1( .en_G(en[0]), .osc_out_G(osc_out[0]));
generic_RO u_generic_RO2( .en_G(en[1]), .osc_out_G(osc_out[1]));
generic_RO u_generic_RO3( .en_G(en[2]), .osc_out_G(osc_out[2]));
generic_RO u_generic_RO4( .en_G(en[3]), .osc_out_G(osc_out[3]));
mux_top u_mux_top(.in (in),.sel (sel), .en_out (en) );
endmodule
module generic_RO (en_G, osc_out_G);
input en_G;
output osc_out_G;
reg [num-1:0] Rut_arr;
parameter num=25;
//reg Rut_AND = 1'b1;
genvar i;
generate
for(i=0; i<num; i=i+1) begin :inst
ringosc5 ringosc_n(
.Rosc_out (Rut_arr),
.en (en_G)
);
// Rut_AND = (Rut_arr && Rut_AND); //j variable will be constant for i=1 to 25.
//After 25 times of i, j increments 1 time.
end
//assign osc_out_G = Rut_AND;
endgenerate
endmodule
module ringosc5 (Rosc_out, en);
input en;
output Rosc_out;
wire Rosc_out;
reg [5:1] node /* synthesis keep*/;
reg Rosc_out_reg;
always @(Rosc_out or en)
begin
node[1]<= ~(node[5] & en);
node[2]<= ~node[1];
node[3]<= ~node[2];
node[4]<= ~node[3];
node[5]<= ~node[4];
Rosc_out_reg<=node[5];
end
assign Rosc_out = Rosc_out_reg;
endmodule
module mux_top(in,sel, en_out);
input [7:0] in;
input [2:0] sel;
output [3:0] en_out;
reg [3:0] en_out;
always @ (sel or in)
begin
case(sel)
3'b000 : begin
en_out[0] = in[0];
en_out[3:1] = 3'b0;
end
3'b001 : begin
en_out[0] = in[1];
en_out[3:1] = 3'b0;
end
3'b010 : begin
en_out[1] = in[2];
en_out[3:2] = 2'b0;
en_out[0] = 1'b0;
end
3'b011 : begin
en_out [1] = in[3];
en_out[3:2] = 2'b0;
en_out[0] = 1'b0;
end
3'b100 : begin
en_out[2] = in[4];
en_out[3] = 1'b0;
en_out[1:0] = 2'b0;
end
3'b101 : begin
en_out[2] = in[5];
en_out[3] = 1'b0;
en_out[1:0] = 2'b0;
end
3'b110 : begin
en_out[3] =in[6];
en_out[2:0] = 3'b0;
end
3'b111 : begin
en_out[3] = in[7];
en_out[2:0] = 3'b0;
end
endcase
end
endmodule
- - - Updated - - -
I forgot to mention, all the individual outputs of each RO, has to be tied together and AND them to draw it out on one pin. This will prevent the compiler to optimize and throw it away.