我有点问题。我想做一个用固定点划分两个数字的程序。我的输出看起来没问题,但是当我在a上测试程序时 本地测试网站我得到了一些奇怪的结果。有人可以帮助我吗?谢谢。
module divider(
input[7:0] a,b,
output reg [15:0] q,
output reg [7:0] r,frac
);
reg[7:0] c2, r2;
integer c;
always @(*)
begin
c = 8'b00000000;
r = a;
frac = 8'b00000000;
repeat (30)
begin
if (r >= b )
begin
c = c + 1;
r = r - b;
end
end
q[15:8] = c;
repeat (8)
begin
if(r != 0)
begin
r = r*10;
c2 = 8'b00000000;
repeat(30)
begin
if (r>=b)
begin
c2 = c2 + 1;
r = r-b;
end
end
frac = frac*10 + c2;
end
end
q[7:0] = frac;
end
endmodule
输出本地网站:
error: a = 1, b = 2, q = 0.019531, expected q = 0.500000
error: a = 1, b = 4, q = 0.097656, expected q = 0.250000
error: a = 1, b = 5, q = 0.007813, expected q = 0.199219
error: a = 1, b = 7, q = 0.570313, expected q = 0.140625
error: a = 1, b = 8, q = 0.488281, expected q = 0.125000
error: a = 1, b = 9, q = 0.777344, expected q = 0.109375
error: a = 1, b = 10, q = 0.003906, expected q = 0.097656
error: a = 1, b = 11, q = 0.363281, expected q = 0.089844
error: a = 1, b = 14, q = 0.785156, expected q = 0.070313
error: a = 1, b = 15, q = 0.664063, expected q = 0.066406
error: a = 1, b = 16, q = 0.441406, expected q = 0.062500
error: a = 1, b = 17, q = 0.937500, expected q = 0.058594
error: a = 1, b = 18, q = 0.386719, expected q = 0.054688
error: a = 1, b = 19, q = 0.207031, expected q = 0.050781
error: a = 1, b = 20, q = 0.019531, expected q = 0.046875
error: a = 1, b = 21, q = 0.187500, expected q = 0.046875
error: a = 1, b = 22, q = 0.679688, expected q = 0.042969
error: a = 1, b = 23, q = 0.695313, expected q = 0.042969
error: a = 1, b = 25, q = 0.015625, expected q = 0.039063
error: a = 1, b = 27, q = 0.589844, expected q = 0.035156
error: a = 1, b = 28, q = 0.890625, expected q = 0.035156
error: a = 1, b = 29, q = 0.824219, expected q = 0.031250
error: a = 1, b = 30, q = 0.832031, expected q = 0.031250
error: a = 1, b = 31, q = 0.804688, expected q = 0.031250
error: a = 1, b = 32, q = 0.207031, expected q = 0.031250
error: a = 1, b = 33, q = 0.121094, expected q = 0.027344
error: a = 1, b = 34, q = 0.437500, expected q = 0.027344
error: a = 1, b = 35, q = 0.570313, expected q = 0.027344
error: a = 1, b = 36, q = 0.914063, expected q = 0.027344
error: a = 1, b = 37, q = 0.000000, expected q = 0.023438
error: a = 1, b = 38, q = 0.339844, expected q = 0.023438
error: a = 1, b = 40, q = 0.097656, expected q = 0.023438
答案 0 :(得分:0)
您不一定需要基数10来进行FPGA上的划分。 Radix2划分(例如shift and subtract)将更快更容易实现。我找到了this radix2 division的例子。