Skip navigation.
Home

VHDL Flip Flops

This snippet demonstrates some basic flip flop styles in VHDL.

Rising edge triggered flip flop.

library ieee;
use ieee.std_logic_1164.all;
 
entity flip_flop_rising is
  port ( clk : in  std_logic;
         d   : in  std_logic;
         q   : out std_logic);
end flip_flop_rising;
 
architecture rtl of flip_flop_rising is
  begin
    process (clk)
    begin
      if (clk'event and clk='1') then
        q <= d;
      end if;
    end process;
  end rtl;

Falling edge triggered flip flop.

library ieee;
use ieee.std_logic_1164.all;
 
entity flip_flop_falling is
  port ( clk : in  std_logic;
         d   : in  std_logic;
         q   : out std_logic);
end flip_flop_falling;
 
architecture rtl of flip_flop_falling is
  begin
    process (clk)
    begin
      if (clk'event and clk='0') then
        q <= d;
      end if;
    end process;
  end rtl;

Rising edge triggered flip flop with active low asynchronous reset and clock enable.

library ieee;
use ieee.std_logic_1164.all;
 
entity async_reset_ce is
  port ( clk     : in  std_logic;
         n_reset : in  std_logic;
         ce      : in  std_logic;
         d       : in  std_logic;
         q       : out std_logic);
end async_reset_ce;
 
architecture rtl of async_reset_ce is
  begin
    process (clk,n_reset)
    begin
      if (n_reset='0') then
        q <= '0';
      elsif (clk'event and clk='1') then
        if (ce = '1') then
          q <= d;
        end if;
      end if;
    end process;
  end rtl;    

AttachmentSize
flip_flops.vhd1.23 KB

Wrong edge?

Last FF is triggering on *falling* edge (not rising...)

Thanks, fixed that now.

Thanks, fixed that now.