Programming
[VHDL] D Flip-Flop
__미니__
2016. 2. 11. 23:01
dff.vhd
library ieee; use ieee.std_logic_1164.all; entity dff is port ( d : IN std_logic; clk : IN std_logic; set, rst : IN std_logic; q : OUT std_logic ); end dff; architecture arch_dff of dff is begin process_dff : process(clk) is begin if ( rst = '1' ) then q <= '0'; elsif ( set = '1' ) then q <= '1'; elsif ( clk = '1' and clk'event ) then q <= d; end if; end process; end arch_dff;
dff_tb.vhd
library ieee; use ieee.std_logic_1164.all; entity dff_tb is end dff_tb; architecture arch_dff_tb of dff_tb is signal input_d, input_clk : std_logic; signal input_set, input_rst : std_logic; signal output_q : std_logic; component dff is port ( d : IN std_logic; clk : IN std_logic; set, rst : IN std_logic; q : OUT std_logic ); end component; begin dff_port : dff port map ( input_d, input_clk, input_set, input_rst, output_q ); process_clk : process begin input_clk <= '0'; wait for 10 ns; input_clk <= '1'; wait for 10 ns; end process; process_rst : process begin input_rst <= '1'; wait for 20 ns; input_rst <= '0'; wait for 200 ns; end process; process_d : process begin input_d <= '0'; wait for 40 ns; input_d <= '1'; wait for 60 ns; end process; end arch_dff_tb;
VHDL을 이용해 짜 본 D Flip-Flop 이다.
enable을 넣으면 D Latch가 되겠지만 넣기 귀찮아서 넣지 않았다.
위 이미지는 시뮬레이션을 돌려 본 화면이다.
현재 가리키고 있는 부분은 input_d에 1, input_clk에 1이 들어가 있고 input_rst가 0이므로 output_q가 1로 정상적인 출력을 보이고 있다.
만약 여기서 input_rst가 1이었을 경우에는 output_q 가 0이 나올 것이다.