VHDL:将标准逻辑向量转换为整数时出错

VHDL:将标准逻辑向量转换为整数时出错,vhdl,Vhdl,我正在用vhdl(xilinx)为数字转速表编写代码。 将std_逻辑_向量m1转换为整数时,编译器显示以下错误 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.numeric_std.all; entity tacho is Port ( A : in STD_LOGIC; B : out STD_LOGIC_vector (15 downto 0)); end tacho; architecture

我正在用vhdl(xilinx)为数字转速表编写代码。 将
std_逻辑_向量
m1转换为整数时,编译器显示以下错误

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.all;

entity tacho is
    Port ( A : in  STD_LOGIC;
           B : out  STD_LOGIC_vector (15 downto 0));
end tacho;

architecture Behavioral of tacho is
component counter
            port(
            clk: in std_logic;
            m: out std_logic_vector (4 downto 0));
end component;
signal m1 : std_logic_vector (4 downto 0); 
variable y: integer := 0;
variable z: integer := 0;           
begin
x: counter port map(A,m1);
y:= to_integer(unsigned(m1)); --error1:Syntax error near ":=". error2:Expecting type  void for <to_integer>.
z:= y * 60; --Syntax error near ":=".
B <= std_logic_vector(to_unsigned(z, 16));
end Behavioral;
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用IEEE.numeric_std.all;
实体测速仪是
端口(A:标准_逻辑中;
B:输出标准逻辑向量(15到0);
终点测速仪;
tacho的架构是
组件计数器
港口(
clk:标准逻辑中;
m:输出标准逻辑向量(4到0);
端部元件;
信号m1:标准逻辑向量(4到0);
变量y:整数:=0;
变量z:整数:=0;
开始
x:计数器端口图(A,m1);
y:=to_整数(无符号(m1))--error1:靠近“:””的语法错误。错误2:的类型应为void。
z:=y*60--“:”附近出现语法错误。

B变量
y
z
不能在架构级别声明。改为使用信号,信号赋值
非共享变量只能在进程语句或子程序中声明。您可以将缩放代码放在一个流程中:

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

entity tacho is
    port ( A:   in  std_logic;
           B:   out std_logic_vector (15 downto 0)
    );
end entity tacho;

architecture behavioral of tacho is
    component counter is
        port (
            clk: in  std_logic;
            m:   out std_logic_vector (4 downto 0)
        );
    end component;
    signal m1 : std_logic_vector (4 downto 0);
begin

x: counter port map (A, m1);

scaling:
    process (m1)
        variable y: integer := 0;
        variable z: integer := 0;
    begin
        y := to_integer(unsigned(m1));
        z := y * 60;
        B <= std_logic_vector(to_unsigned(z, 16));
    end process;
end architecture behavioral;
ieee库;
使用ieee.std_logic_1164.all;
使用ieee.numeric_std.all;
实体测速仪是
端口(A:标准_逻辑中;
B:输出标准逻辑向量(15到0)
);
终端实体测速仪;
tacho的架构是
组件计数器是
港口(
clk:标准逻辑中;
m:输出标准逻辑向量(4到0)
);
端部元件;
信号m1:标准逻辑向量(4到0);
开始
x:计数器端口图(A,m1);
缩放比例:
过程(m1)
变量y:整数:=0;
变量z:整数:=0;
开始
y:=to_整数(无符号(m1));
z:=y*60;

B转速表通常统计某个采样间隔内的事件数。这在您的设计中并不明显。不要使用变量。。。至少,不是这样的。此外,不建议在合成中使用无约束的
整数
s,否则它们将扩展到32位值。
  ...
  x: counter port map(A, m1);
  B <= std_logic_vector(resize(60 * unsigned(m1), B'length));
  ...
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity tacho is
    port ( A:   in  std_logic;
           B:   out std_logic_vector (15 downto 0)
    );
end entity tacho;

architecture behavioral of tacho is
    component counter is
        port (
            clk: in  std_logic;
            m:   out std_logic_vector (4 downto 0)
        );
    end component;
    signal m1 : std_logic_vector (4 downto 0);
begin

x: counter port map (A, m1);

scaling:
    process (m1)
        variable y: integer := 0;
        variable z: integer := 0;
    begin
        y := to_integer(unsigned(m1));
        z := y * 60;
        B <= std_logic_vector(to_unsigned(z, 16));
    end process;
end architecture behavioral;
architecture scaled of tacho is
    component counter is
        port (
            clk: in  std_logic;
            m:   out std_logic_vector (4 downto 0)
        );
    end component;
    signal m1 : std_logic_vector (4 downto 0);
    function scale(m1: std_logic_vector (4 downto 0); SIZE: natural := 16)
            return std_logic_vector is
        variable y: integer;
        variable z: integer;
    begin
        y := to_integer(unsigned(m1));
        z := y * 60;
        return std_logic_vector(to_unsigned(z, SIZE));
    end function;
begin

x: counter port map (A, m1);
scaled_output:
    B <= scale(m1);
end architecture;