我为EE项目编写了一个CLA 4位加法器,虽然它会添加偶数/偶数和奇数/奇数,但如果只有其中一个是奇数,则不会添加A和B.
基本上是这样的:
0001 + 0001 = 0010
0001 + 0010 = 0010(未检测到0001)
非常感谢帮助!
顶级实体中的代码:
signal g1 : unsigned(3 downto 0);
signal g2 : unsigned(3 downto 0);
signal g3 : unsigned(3 downto 0);
signal p1 : unsigned(3 downto 0);
signal p2 : unsigned(3 downto 0);
signal p3 : unsigned(3 downto 0);
signal c1 : unsigned(4 downto 0);
signal c2 : unsigned(4 downto 0);
signal c3 : unsigned(4 downto 0);
signal ci1 : std_logic;
signal ci2 : std_logic;
signal ci3 : std_logic;
signal co1 : std_logic;
signal co2 : std_logic;
signal co3 : std_logic;
signal sum : unsigned(4 downto 0);
signal sum1 : unsigned(3 downto 0);
signal sum2 : unsigned(3 downto 0);
signal sum3 : unsigned(3 downto 0);
signal tn : unsigned(3 downto 0) := "1010";
--A + B
p1 <= unsigned(A xor B);
g1 <= unsigned(A and B);
k1 : CLA1 port map (p1,g1,c1,ci1);
sum1 <= (p1 xor c1(3 downto 0));
co1 <= c1(4);
--A + 1
p2 <= unsigned(A xor "0001");
g2 <= unsigned(A and "0001");
k2 : CLA2 port map (p2,g2,c2,ci2);
sum2 <= (p2 xor c2(3 downto 0));
co2 <= c2(4);
--A + A
p3 <= unsigned(A xor A);
g3 <= unsigned(A and A);
k3 : CLA3 port map (p3,g3,c3,ci3);
sum3 <= (p3 xor c3(3 downto 0));
co3 <= c3(4);
CLA.vhd中的代码:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity CLA1 is
port (
ci : in std_logic;
p : in unsigned(3 downto 0);
g : in unsigned(3 downto 0);
c : out unsigned(4 downto 0)
);
end CLA1;
architecture Behavioral of CLA1 is
begin
c(0) <= ci;
c(1) <= g(0) or (p(0) and ci);
c(2) <= g(1) or (p(1) and g(0)) or (p(1) and p(0) and ci);
c(3) <= g(2) or (p(2) and g(1)) or (p(2) and p(1) and g(0))
or (p(2) and p(1) and p(0) and ci);
c(4) <= g(3) or (p(3) and g(2)) or (p(3) and p(2) and g(1))
or (p(3) and p(2) and p(1) and g(0)) or (p(3)
and p(2) and p(1) and p(0) and ci);
end Behavioral;
答案 0 :(得分:0)
您已按错误的顺序完成了端口映射。即k1:CLA1端口映射(p1,g1,c1,ci1);但它假设是k1:CLA1端口映射(ci1,p1,g1,c1); 做这个改变并尝试
答案 1 :(得分:0)
你有几个错误。
首先,您的顶级代码示例是不完整的,它不是Minimal, Complete, and Verifiable example,这意味着其他人无法复制您遇到的错误。
第二个CLA2和CLA3似乎具有u组件声明(否则您的代码将无法分析,详细说明和模拟)。这导致这些组件未绑定(并且它们的信号未显示在您的节点查找器中)。通过在k2和k3中使用CLA1代替CLA2和CLA3,这是正确的。
第三,Aril指出你在k1,k2和k3的实例化中搞乱了位置端口关联(并且Brian注意到这就是我们使用正式端口关联的原因)。您还可以注意到k1(如果先前已经分析过CLA1的实体和体系结构对,则在详细说明中绑定)不应该成功。它表示您的代码段与错误描述不符。
修复这些问题,你会得到更好的结果:
使用此刺激产生此波形转储:
STIMULUS:
process
begin
wait for 10 ns;
for i in 0 to 15 loop
B <= std_logic_vector(to_unsigned(i,4));
for j in 0 to 15 loop
A <= std_logic_vector(to_unsigned(j,4));
ci1 <= '0';
ci2 <= '0';
ci3 <= '0';
wait for 10 ns;
ci1 <= '1';
ci2 <= '1';
ci3 <= '1';
wait for 10 ns;
end loop;
end loop;
wait;
end process;
注意A和B是std_logic_vector子类型的假设,由以下类似:
p1 <= unsigned(A xor B);
g1 <= unsigned(A and B);
(所有这些都没有让你上课为你工作,同时告诉你错误所在。)