UFK
Member level 3
Dear Verilog users
Please help me synthesize a simple Verilog program which calculates the log base 2 of a value.
My code is
The testbench is
If i use the datatype reg for variable 'i' the program synthesizes but does not give results. Please help me synthesize this code.
Thankyou
Please help me synthesize a simple Verilog program which calculates the log base 2 of a value.
My code is
module Log_max(v,n_var,T);
input [31:0]v;
output [31:0]n_var;
output reg [31:0] T=0;
wire [31:0] v;
reg [31:0]n_var;
reg [3:0] base = 2;
//floor of the log base 2
function integer CLogB2;
input [31:0] Depth;
reg i;
begin
i = Depth;
for(CLogB2 = 0; i > 1; CLogB2 = CLogB2 + 1)
i = i >> 1;
end
endfunction
always @ (v)
begin
n_var = CLogB2(v);
T = 2 ** n_var;
end
endmodule
The testbench is
module Log_max_tb;
// Inputs
reg [31:0] v;
// Outputs
wire [31:0] n_var;
wire [31:0] T;
// Instantiate the Unit Under Test (UUT)
Log_max uut (
.v(v),
.n_var(n_var),
.T(T)
);
initial begin
v = 2614;
end
endmodule
If i use the datatype reg for variable 'i' the program synthesizes but does not give results. Please help me synthesize this code.
Thankyou