【问题标题】:VHDL expression is not constantVHDL 表达式不是恒定的
【发布时间】:2012-11-30 23:06:26
【问题描述】:

我正在 quartus II 上为 CYCLONE III EP3C25 FPGA 编写 VHDL 程序,但遇到了问题。

这是我的程序的重要部分:

odata : out std_logic_vector(15 downto 0);

signal buf_data : std_logic_vector(255 downto 0);

signal nb_word : integer :=0;

Process(clk,RST)
begin
    if(RST='0') then
        nb_word<=0;
    elsif(clk'event and clk='0') then
        if(Current_state_w=s2) then
            if(nb_word<=X"F0") then
                nb_word<=nb_word+16;
            else
                nb_word<=0;
            end if;
        end if;
    end if;
end process;

Process(clk,RST)

begin
    if(RST='0') then
        odata<=(OTHERS=>'0');
    elsif(clk'event and clk='0') then
            odata<=buf_data(nb_word+15 downto nb_word);
    end if;
end process;

这段代码编译得很好,但没有做我想做的事,然后我只想改变:

odata<=buf_data(nb_word+15 downto nb_word);

odata<=buf_data(nb_word downto nb_word-15);

我将 nb_word 的初始化和重置值更改为 15 而不是 0。

问题是,当我这样做并尝试编译时,我得到了这个错误:

Error (10779): VHDL error at VL_control.vhd(99): expression is not constant

该行对应odata行的变化。

我真的不明白为什么会出现这个错误。为什么可以做加法而不是减法? 我还尝试定义另一个信号并在像这样寻址缓冲区之前对信号进行减法:

nb_word1 := (nb_word-15);
odata<=buf_data(nb_word downto nb_word1);

但我仍然遇到同样的错误。这是哪里来的??????

【问题讨论】:

    标签: vector compiler-errors vhdl


    【解决方案1】:

    您应该将nb_word 限制在一个整数范围内,这样合成工具就可以确定nb_word - 15 的值不能为负数。

    另外,为什么要将整数与位串文字进行比较?为什么不直接说if nb_word &lt; 15

    【讨论】:

    • 我认为您的意思是自然范围,但是是的,这是要走的路;还与整数进行比较。
    • 不,我的意思是整数范围:signal i : integer range 0 to 15; 你可以使用 natural,它本身就是整数的子类型。
    • 只要他对范围 0 到 15 进行所需的其他更改,任何一个都可以。使用更窄的类型对我来说似乎更...自然。
    • 实际上我正在审查一个现有的代码,所以我真的不知道他为什么使用这种语法
    【解决方案2】:

    使用正确的测试可能更容易

    if nb_word < X"F0" then
    

    而不是

    if(nb_word<=X"F0") then
    

    只留下“odata”进程。

    但是我不确定为什么您的解决方案无法编译,只要您在所需的所有三个地方都更改了 nb_word 的初始值(您只提到了两个)。

    布尔表达式周围的无意义括号的流行从何而来?好像有很多...

    【讨论】:

    • where does the fashion for pointless parentheses around boolean expressions come from - 答案是一个字母:C :)
    • 我感觉你是对的。但是如果人们认为所有的代码都必须看起来像 C,那就太可惜了。
    • 我不认为这是一个思考过程——只是他们的手指会自动完成!当我在 C 和 VHDL 之间切换时,我发现自己也在这样做 - 然后我有点颤抖和整理:)
    猜你喜欢
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多