繁体   English   中英

我的 FPGA 数学运算中缺少什么?

[英]What am I missing in my FPGA math operations?

我正在尝试在 VHDL 中设计一个模块以将一个范围转换为另一个范围。 例如,我想将 10 - 100 的范围转换为 0 - 15 的范围。当我将所有数学运算放在一行代码中时,它在模拟和 Basys3 开发板上都按预期工作。 但是,在 Vivado 2020.1 中,我遇到了计时错误。 为了修复时序错误,我将等式分解为单独的寄存器。 我相信这被称为流水线。 将等式分解为单独的寄存器后,它可以在行为模拟中工作,但当我将其上传到我的开发板时将无法工作。 任何想法为什么它在我的板上不起作用?

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity Range_Converter is
    generic (
        g_Old_Max : integer := 100;
        g_Old_Min : integer := 10;
        g_New_Max : integer := 15;
        g_New_Min : integer := 0
    );
    port (
        i_Clk       : in std_logic;
        i_Old_Value : in integer range g_Old_Min to g_Old_Max;
        o_New_Value : out integer range g_New_Min to g_New_Max
    );
end Range_Converter;

architecture RTL of Range_Converter is

    constant c_Old_Range : integer := (g_Old_Max - g_Old_Min);
    constant c_New_Range : integer := (g_New_Max - g_New_Min);

    signal reg1 : integer range g_New_Min to g_New_Max := 0;
    signal reg2 : integer range g_New_Min to g_New_Max := 0;
    signal reg3 : integer range g_New_Min to g_New_Max := 0;
    signal reg4 : integer range g_New_Min to g_New_Max := 0;

begin

    process (i_Clk)
    begin
        if rising_edge(i_Clk) then

            --This works but there are timing errors.
            -- o_New_Value <= ((((i_Old_Value - g_Old_Min) * c_New_Range) / c_Old_Range) + g_New_Min);

            --No timing errors, but will not work.
            reg1        <= (i_Old_Value - g_Old_Min);
            reg2        <= (reg1 * c_New_Range);
            reg3        <= (reg2 / c_Old_Range);
            reg4        <= (reg3 + g_New_Min);
            o_New_Value <= reg4;

        end if;
    end process;

end RTL;

谢谢你的回复,Tricky。 我发现了问题。 reg2 寄存器需要更大的大小。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM