简体   繁体   中英

D flip flop with a feedback loop to clear

Here is my code for ad flip flop with active low asynchronous clear and reset. Clear has a an input which is a combination of q (output of d ff) and the reset signal.I have uploaded an image to show you the circuit for which I have written this program. I do not get the expected output; clear and q is always low. I have set reset as logic one in the simulation. Please help and let me know my mistake :) Thank you.

LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
use ieee.numeric_std.all;


ENTITY d_feedback_clr IS
PORT ( 
       clock, reset, d: IN STD_LOGIC ;  
       q : OUT STD_LOGIC
      ) ;

END d_feedback_clr ;

ARCHITECTURE Behavior OF d_feedback_clr IS
signal state, clear: STD_LOGIC:='0'; -- state implies the output of the d register

BEGIN

    clear <= reset nand state; 

    PROCESS (clock, clear, reset)
        BEGIN

             IF (clear='0') THEN
                state <= '0';
             elsif reset='0' then
                state <= '1'; 
             elsif (clock'event and clock='1') THEN
                state <= d;                                     
             END IF ;

    END PROCESS ;
    q <= state;
END Behavior ;

I think your problem is in the clear signal. If your state is '1' and reset is '1' then clear signal, as the output of a nand gate of these two, will become '0' and the state will immediately change to '0'. So the state and q will always be low.

I've used Modelsim Altera to simulate your design, and it clearly showed glitches in the signal.

模拟结果

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM