在VHDL中,如何检测二进制输入是否可被3或4整除?
我的代码将把输入作为一个数字的二进制表示,介于0和15之间(包括两者) 我的目标是检查一个输入是否可以被3或4整除,如果它是:输出1,并使用非门实现此功能 我用K-Map方法推导了函数公式。以下哪一项是: ABCD是我的输入,4位 F=(A'+C'+D)(A'+B+C')(A+C+D')(A+B+C'+D)(A+B'+C'+D')(A'+B'+C+D')) 我实施了以下公式:在VHDL中,如何检测二进制输入是否可被3或4整除?,vhdl,fpga,Vhdl,Fpga,我的代码将把输入作为一个数字的二进制表示,介于0和15之间(包括两者) 我的目标是检查一个输入是否可以被3或4整除,如果它是:输出1,并使用非门实现此功能 我用K-Map方法推导了函数公式。以下哪一项是: ABCD是我的输入,4位 F=(A'+C'+D)(A'+B+C')(A+C+D')(A+B+C'+D)(A+B'+C'+D')(A'+B'+C+D')) 我实施了以下公式: library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGI
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity kod is
Port ( X : in STD_LOGIC_VECTOR (3 downto 0);
O : out STD_LOGIC);
end kod;
architecture Behavioral of kod is
-- Following are intermediate signals
signal CCC : STD_LOGIC;
signal MMM : STD_LOGIC;
signal EEE : STD_LOGIC;
signal RRR : STD_LOGIC;
signal TTT : STD_LOGIC;
signal DDD : STD_LOGIC;
begin
CCC <= NOT ((NOT X(3)) OR (NOT X(1)) OR X(0)) ;
MMM <= NOT ((NOT X(3)) OR X(2) OR (NOT X(1))) ;
EEE <= NOT (X(3) OR X(1) OR (NOT X(0))) ;
RRR <= NOT (X(3) OR X(2) OR (NOT X(1)) OR X(0));
TTT <= NOT (X(3) OR (NOT X(2)) OR (NOT X(1)) OR (NOT X(0)));
DDD <= NOT ((NOT X(3)) OR (NOT X(2)) OR X(1) OR (NOT X(0)));
O <= NOT (CCC OR MMM OR EEE OR RRR OR TTT OR DDD) ;
end Behavioral;
我只得到1作为输出。
我的错在哪里?我如何纠正它?您的方程式接受“0000”:
我添加了一个术语来排除“0000”以及一个小测试台:
library ieee;
use ieee.std_logic_1164.all;
entity kod is -- is x divisble by 3 or 4?
port (
x: in std_logic_vector (3 downto 0);
o: out std_logic
);
end entity kod;
architecture behavioral of kod is
-- following are intermediate signals
signal ccc: std_logic;
signal mmm: std_logic;
signal eee: std_logic;
signal rrr: std_logic;
signal ttt: std_logic;
signal ddd: std_logic;
signal zero: std_logic; -- added
begin
ccc <= not (not x(3) or not x(1) or x(0));
mmm <= not (not x(3) or x(2) or not x(1) );
eee <= not ( x(3) or x(1) or not x(0));
rrr <= not ( x(3) or x(2) or not x(1) or x(0));
ttt <= not ( x(3) or not x(2) or not x(1) or not x(0));
ddd <= not (not x(3) or not x(2) or x(1) or not x(0));
zero <= not ( x(3) or x(2) or x(1) or x(0)); -- added term
o <= not (ccc or mmm or eee or rrr or ttt or ddd or zero); -- ddd);
end architecture behavioral;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity kod_tb is
end entity;
architecture foo of kod_tb is
signal x: std_logic_vector (3 downto 0);
signal o: std_logic;
begin
DUT:
entity work.kod
port map (
x => x,
o => o
);
STIMULIS:
process
begin
wait for 10 ns;
for i in 0 to 15 loop
x <= std_logic_vector(to_unsigned(i,4));
wait for 10 ns;
end loop;
wait;
end process;
end architecture;
ieee库;
使用ieee.std_logic_1164.all;
实体kod是——x可以被3或4整除吗?
港口(
x:标准逻辑向量(3到0);
输出标准逻辑
);
终端实体kod;
kod的体系结构是
--以下是中间信号
信号ccc:std_逻辑;
信号mmm:std_逻辑;
信号eee:标准逻辑;
信号rrr:std_逻辑;
信号ttt:std_逻辑;
信号ddd:标准逻辑;
信号零:标准_逻辑;——补充
开始
ccc如果您直接模拟实体kod
,而没有为输入指定默认值(如第一次尝试),则输入X
的值将为“uuu”。值“U”是std\U逻辑类型的信号的默认值。类型std_logic
是9个可能值的枚举,例如,“0”表示(强)逻辑低,而“1”表示(强)逻辑高。值“U”表示信号尚未初始化。尚未指定,或者由于表达式而指定了“U”。您可以在VHDL标准之一中的std_logic
上或在VHDL工具附带的包std_logic_1164
的文件中查找布尔运算符的thruth表。(例如,它在Quartus工具链中被命名为std_1164.vhd
)
您可以使用更简单的示例再现观察到的行为:
library ieee;
use ieee.std_logic_1164.all;
entity test1 is
port (
x : in std_logic;
y : out std_logic);
end test1;
architecture rtl of test1 is
begin
y <= x;
end rtl;
ieee库;
使用ieee.std_logic_1164.all;
实体test1是
港口(
x:在标准逻辑中;
y:输出标准(U逻辑);
结束测试1;
test1的体系结构rtl是
开始
你能给我们看看你的测试台吗?如果我们看不到可以模拟的东西,则无法再现您的故障。IEEE Std 1076-2008 14.2设计层次结构的细化“实现可能允许但不要求允许设计层次结构根部的设计实体具有泛型和端口…”和6.5.6.3“如果中的模式端口未连接,则为错误(参见6.5.6.3)或非关联(参见6.5.7.3),除非其声明包含默认表达式(参见6.5.2)。“对于某些VHDL工具,向输入提供默认值就足够了,就像OP在这里所做的那样。请注意,值“0000”
导致O
上的输出不正确,问题的焦点是我的故障在哪里以及如何修复?在测试台代码中初始化输入端口。
library ieee;
use ieee.std_logic_1164.all;
entity test1 is
port (
x : in std_logic;
y : out std_logic);
end test1;
architecture rtl of test1 is
begin
y <= x;
end rtl;