0

I'm having problems coding a T Flip Flop with clear and reset. As the picture below shows, t_in is operating as enable input, that will be set to 1 or 0 from a mod-m counter. to_ldspkr will then toggle. The clr_FF will clear the flip flop.

Link to the block diagram

linked block diagram

I'm now sure how I should code this flip flop. This is my code, but it's not working:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;


entity T_FF is
    port(
        from_t_in : in std_logic;
        clk, reset : in std_logic;
        from_clr_FF : in std_logic;
        to_ldspkr : out std_logic
    );
end T_FF;

architecture Behavioral of T_FF is
    signal temp: std_logic;
    signal r_reg, r_next : std_logic;

    begin
    process(reset, clk, from_clr_FF, r_reg)
    begin
        if(reset = '1') then
            r_reg <= '0';   
        elsif(from_clr_FF = '1') then
            r_next  <= '0';
        elsif(clk'event and clk='1') then
            if(from_t_in = '1') then
                temp <= not temp;
            end if;
        end if;
    end process;
    to_ldspkr <= temp;
end Behavioral;
user2263752
  • 469
  • 1
  • 6
  • 8
  • You haven't qualified "it's not working". For simulation not working he simplest thing to do would be to move the assignment `to_ldspkr <= temp;` from the process and make it a concurrent signal assignment. `temp` isn't in the sensitivity list for the process. What are `r_reg` and `r_next`? they don't show up on the right hand side of an assignment, in a port declaration or in a condition. `to_ldspkr` is only affected by `from_clr_FF`. –  Oct 11 '14 at 22:13
  • Your T-FF has 2 'reset' signals called reset and from_clr_FF. Some documentation use the term 'reset' as a synchronous reset and clear as an asynchronous reset. If both signals are sync or async you can combine them into one if-statement with an OR. – Paebbels Oct 12 '14 at 07:52

1 Answers1

0

temp is not initialized. I guess you don't need r_reg and r_next. Just replace them with temp, so it gets initialized on the reset(s). r_reg is not needed then in the sensitivity.

higain
  • 16
  • 2