vivado显示错误的实数 - testbench - vhdl

时间:2016-06-03 09:33:31

标签: vhdl vivado

 variable cmp_diference : real;
 variable y_aus_tb      : real := 4.9261;
 variable log3X         : real := 4.929947e+00;
 .     
 .
 cmp_diference := y_aus_tb - log3X;
 assert cmp_diference < 0.005 report "log3X = " & real'image(log3X);
 assert cmp_diference < 0.005 report "Diference = " & real'image(cmp_diference);

所以问题是& real'image(log3X)在TCL中的正确情况下显示正确的值,但& real'image(cmp_diference)在正确的情况下显示:3.252959e-03但错误的值...值要显示的是~ -0.003847 ...

Vivado 2016.1有什么问题,或者我做错了什么?

非常感谢!

    LIBRARY ieee;
    USE ieee.std_logic_1164.ALL;
    USE ieee.numeric_std.ALL;
    USE IEEE.MATH_REAL.ALL;

    ENTITY tb_log3X IS
    END tb_log3X;

    ARCHITECTURE behavior OF tb_log3X IS 

    BEGIN
     Test_IO : process 
         variable log3X  : real      := 0.0;
         variable x_ein_tb : integer := 0;
        variable cmp_diference : real := 0.0;
        variable y_aus_tb : real := 0.0;

     begin   
        wait for 21.2 ms; --wait for some reason
            x_ein_tb := 224;
            y_aus_tb := 4,9261;  
           -- Caclulate log3X
           log3X := (log(real(x_ein_tb)))/(log(3.0)); -- logarithm to base 3 of 224
           -- Compare log3X to Y
           cmp_diference := y_aus_tb - log3X;
           -- If diference > 0.009, generate Error message and dispaly the diference between log3X and Y
           assert cmp_diference > 0.009 report "log3X = " & real'image(log3X);
           assert cmp_diference > 0.009 report "Diference = " & real'image(cmp_diference);
      end process Test_IO;
    END;

1 个答案:

答案 0 :(得分:1)

制作完整的测试用例(MCVE)是有礼貌的,这样其他人就可以轻松测试您的代码而无需花费不必要的精力。像

这样的东西
entity tb_real is
end tb_real;

architecture basic of tb_real is
begin

process
 variable cmp_diference : real;
 variable y_aus_tb      : real := 4.9261;
 variable log3X         : real := 4.929947e+00;
begin
 report "Run process";
 cmp_diference := y_aus_tb - log3X;
 assert cmp_diference < 0.005 report "log3X = " & real'image(log3X);
 assert cmp_diference < 0.005 report "Diference = " & real'image(cmp_diference);
 report "reporting log3X = " & real'image(log3X);
 report "reporting Diference = " & real'image(cmp_diference);
 wait;
end process;

end basic;

使用其他模拟器运行...

$ ghdl -a tb_real.vhd
$ ghdl -e tb_real
$ ghdl -r tb_real
tb_real.vhd:12:2:@0ms:(report note): Run process
tb_real.vhd:16:2:@0ms:(report note): reporting log3X = 4.929947
tb_real.vhd:17:2:@0ms:(report note): reporting Diference = -3.847000000000377e-3

当断言测试返回true时,如果其中任何一个断言触发,则Vivado中的某些内容非常错误。

更有可能其他地方的某些其他断言正在解雇,在你没有发布的代码中 - 还记得MCVE吗? - 并且让你误以为其中一个被解雇了。