flip-flop with VHDL (dataflow, structure, behavior)

1. D flip-flop

1.1 structure

1.1.1 just use nand gate

在这里插入图片描述

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity dffst is
	Port ( d,clk : in  STD_LOGIC;
	q,qb : inout STD_LOGIC);
end dffst; 

architecture dffstar of dffst is
component nand21
	port(a,b: in STD_LOGIC;
	y:out STD_LOGIC);
end component;	 
signal d1,s1,r1:STD_LOGIC;

begin
	
	n0: nand21 port map(d,clk,s1);
	n1: nand21 port map(d,d,d1);
	n2: nand21 port map(d1,clk,r1);
	n3: nand21 port map(s1,qb,q);
	n4: nand21 port map(r1,q,qb);

end dffstar;  

--— nand gate

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity nand21 is
Port ( a,b : in  STD_LOGIC;
	y : out  STD_LOGIC);
end nand21;
architecture Behavioral of nand21 is
begin
	y <= a nand b;
end Behavioral;

1.1.2 use not_gate and nand gate

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity dff_st is
Port ( d,clk : in  STD_LOGIC;
    q,qb : inout STD_LOGIC);
end dff_st;

architecture dffstar of dff_st is
component nand21
    port(
      a,b: in STD_LOGIC;
      y:out STD_LOGIC);
end component;

component not_gate
  port(
    a: in STD_LOGIC;
    y: out STD_LOGIC
  );
end component;
signal d1,s1,r1:STD_LOGIC;
begin
    n0: nand21 port map(d,clk,s1);
    n1: not_gate port map(d,d1);
    n2: nand21 port map(d1,clk,r1);
    n3: nand21 port map(s1,qb,q);
    n4: nand21 port map(r1,q,qb);
end dffstar;
-- nand gate

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity nand21 is
    Port ( a,b : in  STD_LOGIC;
    y : out  STD_LOGIC);

end nand21;
architecture Behavioral of nand21 is

begin
    y <= a nand b;
end Behavioral;

-- not_gate
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity not_gate is
  port(
    a: in STD_LOGIC;
    y: out STD_LOGIC
  );
end not_gate;

architecture Behavioral of not_gate is

begin
    y <= not a;
end Behavioral;

1.1.3 use not_gate and_2 gate



-- File: D_and_not.vhd
library ieee;
use ieee.std_logic_1164.all;

entity D_and_not is
    port(
        D : in std_logic;
        CLK : in std_logic;
        Q : inout std_logic;
        Q_bar : inout std_logic
    );
end D_and_not;

architecture structural of D_and_not is
    component not_gate
        port(
            A : in std_logic;
            Y : out std_logic
        );
    end component;

    component and_2
        port(
            A : in std_logic;
            B : in std_logic;
            Y : out std_logic
        );
    end component;

    signal not_D, d_and_clk, d_and_clk_not, d_and_clk_not_and, not_d_and_clk, not_d_and_clk_not, not_d_and_clk_not_and : std_logic;
begin
    U1: not_gate port map(A => D, Y => not_D);
    U2: and_2 port map(A => D, B => CLK, Y => d_and_clk);
    U3: not_gate port map(A => d_and_clk, Y => d_and_clk_not);
    U4: and_2 port map(A => d_and_clk_not, B => Q_bar, Y => d_and_clk_not_and);
    U5: not_gate port map(A => d_and_clk_not_and, Y => Q);
    U6: and_2 port map(A => not_D, B => CLK, Y => not_d_and_clk);
    U7: not_gate port map(A => not_d_and_clk, Y => not_d_and_clk_not);
    U8: and_2 port map(A => not_d_and_clk_not, B => Q, Y => not_d_and_clk_not_and);
    U9: not_gate port map(A => not_d_and_clk_not_and, Y => Q_bar);
end structural;



-- File: and_2.vhd
library ieee;
use ieee.std_logic_1164.all;

entity and_2 is
    port(
        A : in std_logic;
        B : in std_logic;
        Y : out std_logic
    );
end and_2;

architecture behavior of and_2 is
begin
    Y <= A and B;
end behavior;



-- File: not_gate.vhd
library ieee;
use ieee.std_logic_1164.all;

entity not_gate is
    port(
        A : in std_logic;
        Y : out std_logic
    );
end not_gate;

architecture behavior of not_gate is
begin
    Y <= not A;
end behavior;

1.1.4 simulation result of quartus and modelsim

在这里插入图片描述
在这里插入图片描述

2. JK flip-flop

2.1 structure

using D flip-flop as a component to build JK flip-flop, D flip flop could be behavior coding style.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值