首页 > 解决方案 > VHDL shift_right 数字

问题描述

我想将一个数字除以 512,这意味着我需要将其除以 9。例如,在我的代码中,我想将二进制形式的数字 26 乘以 100,然后除以 512。但不是除以 512我需要做的就是将数字 26*100 向右移动 9 倍。但是当我执行shift_right命令时,出现以下错误:

错误 (10511):Multiplier_VHDL .vhd(34) 处的 VHDL 限定表达式错误:限定表达式中指定的 SHIFT_RIGHT 类型必须与上下文表达式隐含的 std_logic_vector 类型匹配

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity Multiplier_VHDL is
    GENERIC (
        display_resolution : INTEGER := 23; -- counter to get to the lowest frequency
        display_counter: INTEGER := 8);     -- counter to get to 97KHz frequency

    port (
        Nibble1 : in std_logic_vector(display_counter downto 0) := "000011010"; -- 26 in binary form
        Nibble2 : in std_logic_vector(display_counter downto 0);
        Result: out std_logic_vector(17 downto 0));
end entity Multiplier_VHDL;

architecture Behavioral of Multiplier_VHDL is
    signal number : unsigned(display_counter downto 0) := "001100100"; -- 100 in binary form

begin
    Result <= std_logic_vector(unsigned(Nibble1) * unsigned(number));
    Result <= (shift_right(unsigned(number), display_counter + 1));

end architecture Behavioral;

标签: vhdl

解决方案


shift_right 返回无符号或有符号,具体取决于您提供的内容。因此,您尝试将无符号写入 std_logic_vector(结果为 std_logic_vector 类型)。

此外,number已经是类型unsigned,因此无需unsigned再次将其转换为。

但是对于使用 numeric_std 而不是 std_logic_arith,我给你 +1 分。


推荐阅读