Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

VHDL code for a T-Flip Flop

Status
Not open for further replies.

fm_com_28

Full Member level 1
Full Member level 1
Joined
Feb 2, 2006
Messages
99
Helped
11
Reputation
22
Reaction score
7
Trophy points
1,288
Location
Fayoum, Egypt
Activity points
1,916
t flip flop vhdl

Dear,
I want to write a VHDL code for a T-flip flop .can you help me with that.
regards
 

vhdl code for t flip flop

Here's a T flip flop with reset

Code:
library ieee;
use ieee.std_logic_1164.all
entity tff is
  port(
        clk: in std_logic;
        reset: in std_logic;
        t: in std_logic;
        q: out std_logic
      );
enf tff;

architecture behave of tff is
  signal q_reg: std_logic;
  signal q_next: std_logic;
begin
 process
 begin
       if (reset = '1') then
          q_reg <= '0';
       elsif (clk'event and clk = '1') then
          q_reg <= q_next;
       end if;
 end process;

       
       q_next <= q_reg when t = '0' else
                 not(q_reg);

       q <= q_reg;
end behave;


A T flip flop has the following equation: Q+ = T`Q+TQ` which is basically a D flip flop with a XOR gate connected to D, with one input being T and the other the Q output.

-Jayson
 
Re: vhdl code for t flip flop

can anyone give the vhdl code on how to convert integer to binary?
can it be done using the structural model?
 

I think this wiil be work

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity int2bin is
generic (N : integer := 64);-- Number of binary bits
port (
clk : in std_logic;
int : in integer;
bin : out std_logic_vector(N-1 downto 0)
);
end int2bin;

architecture behavior of int2bin is

signal count:integer;
signal d : integer;
signal b : std_logic_vector(N-1 downto 0);

begin

process(clk)
begin
if (clk'event and clk = '1') then
d <= 0;
b <= (others => '0');
L0: for i in 0 to int loop
if (d = int) then
bin <= b;
exit L0;
else
d <= d+1;
count <= 0;
for k in 0 to N-1 loop
if(count = 0) then
if(b(k) = '0') then
b(k) <= '1';
count <= 1;
else
b(k) <= '0';
end if;
end if;
end loop;
end if;
end loop L0;
bin <= b;
else
bin <= b;
end if;
end process;
end behavior;

let me know if any error
 
my_slv <= std_logic_vector(to_unsigned(my_int,my_slv'length));

there really isn't a applicable structural model. A module could be made, but it would simply do the above.

Also, realize that integers are defined as 32b signed values. (unsigned "positives" are limited to 31b). This is annoying as FPGA's now have the capability for > 32b math.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top