HDL Programming Verilog VHDL D Flip Flop
HDL Programming Verilog VHDL D Flip Flop
VERILOG VHDL
D FLIP FLOP:
module dflipflop(q,d,clk,reset); library ieee;
output q; use ieee.std_logic_1164.all;
input d,clk,reset; entity dff is
reg q; port(d,clk:in bit;q:inout bit:='0';qb:out bit:='1');
always @(posedge clk ) end dff;
if (reset) architecture behaviour of dff is
q= 1'b0; begin
else process(clk,d)
q=d; begin
endmodule if(clk='1' and clk'event)then
q<=d;
end if;
end process;
qb<=not q;
end behaviour;
JK FLIP FLOP:
library ieee;
module jjjjjjj(j, k, clk, q); use ieee.std_logic_1164.all;
input j, k, clk; entity jk is
output q; port(clk,j,k:in std_logic;q:inout
reg q; std_logic;qb:out std_logic);
always @(posedge clk) end jk;
case({j,k}) architecture behaviour of jk is
{1'b0,1'b0}:q=q; begin
{1'b0,1'b1}:q=1'b0; process(clk,j,k)
{1'b1,1'b0}:q=1'b1; begin
{1'b1,1'b1}:q=~q; if(clk='1' and clk'event)then
endcase if(j='0' and k='0')then
endmodule q<=q;
end if;
elsif(j='0' and k='1')then
q<='0';
elsif(j='1' and k='0')then
q<='1';
elsif(j='1' and k='1')then
q<=not q;
end if;
end process;qb<=not q;end behaviour;
T FLIP FLOP:
module tfftff(t,clk,reset,q); library IEEE;
input t,clk,reset; use IEEE.STD_LOGIC_1164.ALL;
output q; entity T_FF is
reg q; port( T: in std_logic;
always@(posedge clk) Clock: in std_logic;
if(reset) Q: out std_logic);
begin end T_FF;
q=1'b0; architecture Behavioral of T_FF is
end signal tmp: std_logic;
else begin
begin process (Clock)
q=~t; begin
end if Clock'event and Clock='1' then
endmodule if T='0' then
tmp <= tmp;
elsif T='1' then
tmp <= not (tmp);
end if;
end if;
end process;
Q <= tmp;
end Behavioral;
SR FLIPFLOP:
UPCOUNTER
library ieee;
module counter (C, ALOAD, D, Q); use ieee.std_logic_1164.all;
input C, ALOAD; use ieee.std_logic_unsigned.all;
input [3:0] D; entity vhdl_binary_counter is
output [3:0] Q; port(C, CLR : in std_logic;
reg [3:0] tmp; Q : out std_logic_vector(3 downto 0));
end vhdl_binary_counter;
always @(posedge C or posedge ALOAD) architecture bhv of vhdl_binary_counter is
begin signal tmp: std_logic_vector(3 downto 0);
if (ALOAD) begin
tmp = D; process (C, CLR)
else begin
tmp = tmp + 1'b1; if (CLR=1) then
end tmp <= "0000";
assign Q = tmp; elsif (Cevent and C=1) then
endmodule tmp <= tmp + 1;
end if;
end process;
Q <= tmp;
end bhv;
DOWN COUNTER library ieee;
use ieee.std_logic_1164.all;
module counter (C, S, Q); use ieee.std_logic_unsigned.all;
input C, S;
output [3:0] Q; entity counter is
reg [3:0] tmp; port(C, S : in std_logic;
Q : out std_logic_vector(3 downto 0));
always @(posedge C) end counter;
begin architecture archi of counter is
if (S) signal tmp: std_logic_vector(3 downto 0);
tmp = 4'b1111; begin
else process (C)
tmp = tmp - 1'b1; begin
end if (C'event and C='1') then
assign Q = tmp; if (S='1') then
endmodule tmp <= "1111";
else
tmp <= tmp - 1;
end if;
end if;
end process;
Q <= tmp;
end archi;