Monday, January 17, 2011

HDL Programming T flip-flop

VHDL File Name:
 t_ff.vhd
--T Flip Flop
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity t_ff is
Port ( t,clk,rst : in  STD_LOGIC;
q,qb : out  STD_LOGIC);
end t_ff;
architecture Behavioral of t_ff is
signal temp : std_logic := '0';
begin
process(clk,rst)
begin
if(rst = '1')  then
temp <= '0';
elsif(clk'event and clk = '1' and t = '1')  then
temp <= not temp;
end if;
end process;
q <= temp;
qb <= not temp;
end Behavioral;

Verilog File Name:
t_ff.v
//Async T Flip Flop
module t_ff( t, clk, reset, q, qb );
input t, clk, reset ;
output q,qb;
reg q,qb;
always @ ( posedge clk or posedge reset)
if (reset)
begin
q = 1'b0;
qb=~q;
end
else
if (t)
begin
q  = ~q;
qb = ~q;
end
endmodule

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Search On Flipkart

Facebook Connect