Altera_Forum
Honored Contributor
18 years agoChanging The Value of a Register On Both Negative and Positive Edge of a Clock.
ENTITY test IS
PORT (
CLK1,CLK2, done : IN STD_LOGIC;
pr_out : OUT STD_LOGIC
);
END test;
ARCHITECTURE test1 OF test IS
SIGNAL PR, done_flag : STD_LOGIC;
BEGIN
PROCESS (CLK1, CLK2, done)
BEGIN
IF ( done = '1' ) THEN
done_flag <= '1';
ELSIF (CLK1'EVENT AND CLK1 = '1') THEN
IF ( done_flag = '1') THEN
PR <='1';
END IF;
ELSIF (CLK2'EVENT AND CLK2 = '0') THEN
IF ( done_flag = '1') THEN
done_flag <= '0';
PR <='0';
END IF;
END IF;
END PROCESS;
pr_out <= PR;
END test1;
--- -------- -------
--- | | | |
--- --------- -------- -------- (CLK1)
--- ----- -------- --------
--- | | | | |
--- -------- -------- -------- (CLK2)
Hello, The logic behind this code is simple. You get an ASYNC ‘done’ at any point during the clock cycle CLK1 then you raise a flag called done_flag. On the next positive edge of the clock (CLK1) I set PR = 1 if done_flag is set from the previous cycle, and I lower both PR and done_flag on the NEGATIVE edge of the SECOND clock (clk2). The clocks has a 90 degrees phase shift as seen in the commented section in the code. this code will not compile because pr will be an inferred register and its behaviour will depend on the edges of 2 independent clocks. i understand that. however i still need to write a code that will make the circuit behave in an equivalent manner. What do you do when you are faced with a similar problem? How do you go around it?