I have written some DSP stuff in float inside FPGA and they are working as expected, also the end result should got to Cortex M7 for further process, because this algorithm is so math intensive, I decided to do some parts of it inside the FPGA, since it has enough room and it's relatively cheap, I can get gowin with 20K lut and 48 DSP and 48 Block ram and 32MB Internal SDRAM under 5$, so why not.
I have written a test bench for the Wiljan code sample,
But it seems it has wrong results, in positive and negative numbers,
Sample Test bench,
module fixed_to_float_tb ();
parameter MAIN_CLK_DELAY = 20; // 25 MHz
reg r_Rst_L = 1'b0;
reg r_Clk = 1'b0;
// Clock Generators:
always #(MAIN_CLK_DELAY) r_Clk = ~r_Clk;
reg [31:0] r_a;
wire [31:0] w_Out;
fixed_to_float DUT(
.fixed_sign(r_a[31]),
.fixed_mag(r_a[30:0]),
.float_out(w_Out)
);
initial
begin
r_Rst_L = 1'b1;
repeat(1) @(posedge r_Clk);
r_Rst_L = 1'b0;
repeat(3) @(posedge r_Clk);
r_a = 32'd1250302788;
repeat(1) @(posedge r_Clk);
r_a = 32'd8388608;
repeat(1) @(posedge r_Clk);
r_a = 32'd536870911;//32'h1fffffff;
repeat(1) @(posedge r_Clk);
r_a = 32'h00000001;
repeat(1) @(posedge r_Clk);
r_a = 32'd2147483520;//32'h7fffff80;
repeat(1) @(posedge r_Clk);
r_a = 32'd2147483584;//32'h7fffffc0;
repeat(1) @(posedge r_Clk);
r_a = 32'h80000000; //-2147483648
repeat(1) @(posedge r_Clk);
r_a = 32'h80000040;//-2147483584
repeat(1) @(posedge r_Clk);
r_a = 32'hffffffff;//-1
repeat(1) @(posedge r_Clk);
r_a = 32'h00000000;
end // initial begin
endmodule
// parameters of the code,
parameter FIXED_WIDTH = 31; // must not be > 32
parameter FIXED_FRACTIONAL = 0;
For example this input 1250302788 should produce 0x4e950c37, But it would produce 0x4e950c36, I know it's small value, But I want a perfect int to float conversion, since I would do lot's of float add and Mul, and it would increase the error.
I will test my data and it's result with this online calc
https://www.h-schmidt.net/FloatConverter/IEEE754.html