我正在尝试设置和加载d-flip flop代码(同步),但它一直给我count <= '0' & d; it has 2 elements but must have 9 elements
错误。提前谢谢
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity syn is
port (
clk : in std_logic;
rst_n : in std_logic;
d : in std_logic;
ld : in std_logic;
q : out std_logic_vector(7 downto 0);
co : out std_logic);
end syn;
architecture rtl of syn is
signal count : std_logic_vector(8 downto 0);
begin
co <= count(8);
q <= count(7 downto 0);
process (clk)
begin
if (clk'event and clk = '1') then
if (rst_n = '0') then
count <= (others => '0'); -- sync reset
elsif (ld = '1') then
count <= '0' & d; -- sync load
else
count <= count + 1; -- sync increment
end if;
end if;
end process;
end rtl;
答案 0 :(得分:2)
输入d是std_logic,因此'0' & d
是2位向量。 Count是长度为9的std_logic_vector,所以你不能这样做。
我不完全确定你想要实现的目标。如果你想指定'0'和&amp; d到矢量的某个部分,你可以写例如
count(1 downto 0) <= '0' & d
如果d应该是相同大小的计数器,那么在实体声明中改变它的大小。