Vhdl 为什么JK触发器的输出在模拟中是红色的?
我正在用VHDL语言发布JK触发器的代码。根据JK触发器电路,代码是正确的。但我得到的输出是红线。谁能告诉我只有JK触发器有什么问题吗Vhdl 为什么JK触发器的输出在模拟中是红色的?,vhdl,flip-flop,Vhdl,Flip Flop,我正在用VHDL语言发布JK触发器的代码。根据JK触发器电路,代码是正确的。但我得到的输出是红线。谁能告诉我只有JK触发器有什么问题吗 节目:JK触发器 ----------=======具有三个输入的与非门=====--------------- ieee库; 使用ieee.std_logic_1164.all; 实体nand_gate3是端口( A、 B,C:在标准逻辑中; F:输出标准(U逻辑); 结束nand_网关3; nand_gate3的体系结构nandfunc3是 信号x:st
- 节目:JK触发器
ieee库;
使用ieee.std_logic_1164.all;
实体nand_gate3是端口(
A、 B,C:在标准逻辑中;
F:输出标准(U逻辑);
结束nand_网关3;
nand_gate3的体系结构nandfunc3是
信号x:std_逻辑;
开始
你的逻辑似乎有问题。正确的逻辑是:
Q=(J和Qbar_后)与clk与Qbar_后
Qbar=(K和Q_背面)与clk与Q_背面
and操作在您的逻辑中是一个nand操作。JK触发器必须有一个复位端口来初始化输出,否则因为输出(Q
,Qbar
)是由它们自己设置的(反馈),如果它们没有任何初始值,它们总是未定义的。然后,您应该在设计中添加重置端口
您可以使用以下代码获得正确的结果:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity JK_FF is
port(
Reset : in std_logic;
Clock : in std_logic;
J,K : in std_logic;
Q,Qbar : out std_logic
);
end JK_FF;
architecture Behavioral of JK_FF is
signal temp : std_logic;
begin
process (Clock)
begin
if rising_edge(Clock) then
if Reset='1' then
temp <= '0';
else
if (J='0' and K='0') then
temp <= temp;
elsif (J='0' and K='1') then
temp <= '0';
elsif (J='1' and K='0') then
temp <= '1';
elsif (J='1' and K='1') then
temp <= not (temp);
end if;
end if;
end if;
end process;
Q <= temp;
Qbar <= not temp;
end Behavioral;
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
实体JK_FF是
港口(
复位:在标准逻辑中;
时钟:标准逻辑;
J、 K:标准逻辑;
Q、 Qbar:输出标准逻辑
);
结束JK_FF;
JK_FF的架构行为是
信号温度:标准逻辑;
开始
进程(时钟)
开始
如果上升沿(时钟),则
如果Reset='1',则
温度值未定义,不是0或1!谢谢你,阿米尔,,,请你纠正门级的代码。VHDL不适合门级,你真的应该使用@amir代码或模拟模拟器。此外,您的nand3还应该阅读x My Thinks(@Jonathan Drolet),但如果您真的需要使用逻辑门,您可以在一些合成工具(如Xilinx合成工具)中合成我的代码,然后单击“查看原理图技术”。输出包含一些LUT、DFF等。(LUT可以转换为基本逻辑门)然后您可以使用在“原理图技术”窗口上看到的所有内容编写代码。如果您知道故障,请为我更正它。。。谢谢。@omgBob
library ieee;
use ieee.std_logic_1164.all;
entity jk_flipflop_tb is
end jk_flipflop_tb ;
architecture tb of jk_flipflop_tb is
---====Jk_flipflop
component JK_flipflop is port(
clk,J , K : in std_logic;
Q, Q_bar : out std_logic);
end component;
---===signals
signal clk,J ,K , Q, Q_bar : std_logic;
begin
mapping: JK_flipflop port map(clk, J, K, Q, Q_bar);
-------=========Process for Clcok ===========---------------
process
begin
clk <= '1';
wait for 5 ns;
clk <= '0';
wait for 5 ns;
end process;
--------===========Process for j,k inputs values=======--------------
process
begin
-------===TEST 1
J <= '0';
K <= '1';
wait for 20 ns;
-------====TEST 2
J <= '1';
K <= '1';
wait for 20 ns;
-------====TEST 3
J <= '1';
K <= '0';
wait for 20 ns;
-------====TEST 4
J <= '0';
K <= '0';
wait for 20 ns;
end process;
end tb;
--------------------------------------------
configuration cfg_tb of jk_flipflop_tb is
for tb
end for;
end cfg_tb;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity JK_FF is
port(
Reset : in std_logic;
Clock : in std_logic;
J,K : in std_logic;
Q,Qbar : out std_logic
);
end JK_FF;
architecture Behavioral of JK_FF is
signal temp : std_logic;
begin
process (Clock)
begin
if rising_edge(Clock) then
if Reset='1' then
temp <= '0';
else
if (J='0' and K='0') then
temp <= temp;
elsif (J='0' and K='1') then
temp <= '0';
elsif (J='1' and K='0') then
temp <= '1';
elsif (J='1' and K='1') then
temp <= not (temp);
end if;
end if;
end if;
end process;
Q <= temp;
Qbar <= not temp;
end Behavioral;