【问题标题】:why is the output of JK flip flop red in simulation?为什么仿真中JK触发器的输出是红色的?
【发布时间】:2015-03-03 10:35:17
【问题描述】:

我正在用 VHDL 语言发布 JK 触发器的代码。根据 JK 触发器电路,代码是正确的。但我得到了红线的输出。谁能告诉我只有JK触发器有什么问题。

  • 程序:JK 触发器

---------=======N和三输入门=====---------------

library ieee;
 use ieee.std_logic_1164.all;
 entity nand_gate3 is port(
       A, B, C : in std_logic;
             F : out std_logic);
 end nand_gate3 ;


 architecture nandfunc3 of nand_gate3 is
  signal x : std_logic ;
 begin
      x <= A nand B ;
      F <= x nand C ;
end nandfunc3;

------====== END NANd GATE  with three inout ======--------

----=========NANd Gate with Two inputs==========------------
 library ieee;
use ieee.std_logic_1164.all;
 entity nand_gate2 is port(
          A, B : in std_logic;
             F : out std_logic );
end nand_gate2;

architecture nandFunc2 of nand_gate2 is
begin
      F <= A nand B ;
end nandFunc2;
------====== END NANd GATE  with three inout ======-
library ieee;
 use ieee.std_logic_1164.all;
 ENTITY  JK_flipflop IS PORT ( 
                     clk , J, K : IN  std_logic; 
                     Q , Q_bar  : OUT std_logic );
 END JK_flipflop ;  

 architecture JK_structure OF JK_flipflop  IS 
 ----===Compnents 
    COMPONENT nand_gate3 IS PORT (
                       A, B ,C  : IN std_logic ; 
                       F        : OUt std_logic );
    End Component ; 

    COMPONENT nand_gate2 IS PORT (
                       A, B   : IN std_logic ; 
                       F        : OUt std_logic );
    End Component ; 

    Signal X, Y , Qback ,Qbar_back: std_logic ; 
----== Structure
  Begin 

   U1: nand_gate3 PORT MAP ( J, clk, Qbar_back, X ); 
   U2: nand_gate3 PORT MAP ( K, clk, Qback    ,Y );
  U3: nand_gate2 PORT MAP ( X, Qbar_back  ,Qback); 
  U4: nand_gate2 PORT MAP ( Y, Qback  ,Qbar_back); 

   Q <= Qback;
    Q_bar <= Qbar_back;

END JK_structure ; 

--------JK触发器测试台----===

 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;

---------======------

【问题讨论】:

  • 值未定义,不是 0 或 1!

标签: vhdl flip-flop


【解决方案1】:

JK 触发器必须有一个复位端口来初始化输出,否则因为输出(QQbar)是自己设置的(反馈),如果它们没有任何初始值,它们总是未定义的。然后你应该在你的设计中添加一个重置端口。

您可以使用以下代码得到正确的结果:

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;

【讨论】:

  • 谢谢 amir,,, 请您更正门级代码。
  • VHDL 不适合门级,你真的应该使用@amir 代码或模拟模拟器。另外,你的 nand3 应该是 x
  • 我的想法也是如此(@Jonathan Drolet),但如果你真的必须使用逻辑门,你可以在一些综合工具(例如 Xilinx Synthesis Tool)中综合我的代码,然后点击“查看原理图”技术”。输出包含一些 LUT、DFF、...。 (LUT 可以转换为基本逻辑门)然后您可以使用您在 Schematic Technology 窗口中看到的所有内容编写代码。
【解决方案2】:

您的逻辑似乎有问题。正确的逻辑是: Q = (J and Qbar_back) nand clk nand Qbar_back Qbar = (K and Q_back) nand clk nand Q_back

and 操作是逻辑中的 nand 操作。

【讨论】:

  • 如果您知道错误,请帮我纠正...谢谢。@ omgBob
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-27
  • 2016-01-10
相关资源
最近更新 更多