Altera_Forum
Honored Contributor
8 years agoRAM property help
Hi all,
I have a question about using on chip ram. According to what I read from the quartus handbook, the port input (e.g. address, input data) to a RAM should be clocked in order to let software fit the design to the on chip memory (otherwise it may use logic cell to finish the fitting). [Correct me if I did not get this right] Now, I am doing some kind of sorting data of a true dual port ram, m1. What I am trying to do is input two addresses, adr1 & adr2 into m1, and get two data output, q1 & q2. Then I need to compare q1 & q2 and save each pair in ascending order to another true dual port ram, m2. example : m1 :[ 4, 1, 5 ,2] ==[take pair 1 and compare] ==> m2 : [1, 4, X, X] m1 : [4, 1, 5 ,2 ] ==[take pair 2 and compare] ==> m2 : [1, 4, 2, 5] etc.. I can make sure the input (address) of m1 is clocked, but I am not sure if the input of m2 (input data & address) is clocked in this case, since the output data from m1 have to be compared before input to m2. The following is the code I have write
PROCESS (clk)
VARIABLE rd1 : INTEGER := 0;
VARIABLE rd2 : INTEGER := 1;
VARIABLE wr1 : INTEGER := 0;
VARIABLE wr2 : INTEGER := 1;
BEGIN
IF RISING_EDGE (CLK) THEN---------------------------------------
-- read data from m1----------------------------------------
IF (rd1 < 128) THEN
M1RdenA <= '1';
M1RdenB <= '1';
M1AdrA <= STD_LOGIC_VECTOR (TO_UNSIGNED (rd1, 7));
M1AdrB <= STD_LOGIC_VECTOR (TO_UNSIGNED (rd2, 7));
rd1 := rd1 + 2;
rd2 := rd2 + 2;
END IF;
--------------------------------------------
-- compare and save to m2
---------------------------------------------
IF (wr1 < 128) THEN
IF (rd_delay < 3) THEN ------------ read delay of 3 clock cycle due to clocked input and output for m1
rd_delay := rd_delay + 1;
ELSE
IF (M1QA = M1QB) THEN
M2WrenA <= '1';
M2WrenB <= '1';
M2AdrA <= STD_LOGIC_VECTOR (TO_UNSIGNED (wr1, 7));
M2AdrB <= STD_LOGIC_VECTOR (TO_UNSIGNED (wr2, 7));
M2DataA <= M1QA;
M2DataB <= M1QB;
wr1 := wr1 + 1;
wr2 := wr2 + 1;
ELSIF (M1QA < M1QB) THEN
M2WrenA <= '1';
M2WrenB <= '1';
M2AdrA <= STD_LOGIC_VECTOR (TO_UNSIGNED (wr1, 7));
M2AdrB <= STD_LOGIC_VECTOR (TO_UNSIGNED (wr2, 7));
M2DataA <= M1QA;
M2DataB <= M1QB;
wr1 := wr1 + 1;
wr2 := wr2 + 1;
ELSIF (M1QA > M1QB) THEN
M2WrenA <= '1';
M2WrenB <= '1';
M2AdrA <= STD_LOGIC_VECTOR (TO_UNSIGNED (wr2, 7));
M2AdrB <= STD_LOGIC_VECTOR (TO_UNSIGNED (wr1, 7));
M2DataA <= M1QA;
M2DataB <= M1QB;
wr1 := wr1 + 1;
wr2 := wr2 + 1;
END IF;
END IF;
END IF;
END IF;
END PROCESS;