jpglotzer
Newbie level 5
Hi, I'm trying to code a bubble sort algorithm to sort the values in my RAM based on size. I'm using the RAM 2-port megafunction in Quartus, and creating instances of the module in my main module.
The 2 port RAM megafunction has the following inputs/outputs:
module ram_2port (
address_a,
address_b,
clock,
data_a,
data_b,
wren_a,
wren_b,
q_a,
q_b);
Here is my code: (the 1st instance of the megafunction is to read the values of 2 addresses. If the first is bigger than the second, the values are swapped. The 2nd instance of the megafunction should do this; write the first value in the address of the 2nd and the 2nd value in the address of the first). I don't know why it's not working.
module question3(clock,j1,j2,q_a,q_b);
input clock;
output reg [7:0] j1,j2;
reg [4:0] i,j;
always @(posedge clock)
begin
for (i=5'd19; i>5'd0; i=i-5'd1)
begin
for (j=5'd1; j<i+5'd1; j=j+5'd1)
begin
j2<=j;
j1<=j-8'd1;
ram_2port ram1(j1,j2,clock,0,0,1,1,q_a,q_b);
if (q_a > q_b)
begin
ram_2port ram2(j1,j2,clock,q_b,q_a,0,0,0,0);
end
end
end
end
endmodule
Any help would be much appreciated!
The 2 port RAM megafunction has the following inputs/outputs:
module ram_2port (
address_a,
address_b,
clock,
data_a,
data_b,
wren_a,
wren_b,
q_a,
q_b);
Here is my code: (the 1st instance of the megafunction is to read the values of 2 addresses. If the first is bigger than the second, the values are swapped. The 2nd instance of the megafunction should do this; write the first value in the address of the 2nd and the 2nd value in the address of the first). I don't know why it's not working.
module question3(clock,j1,j2,q_a,q_b);
input clock;
output reg [7:0] j1,j2;
reg [4:0] i,j;
always @(posedge clock)
begin
for (i=5'd19; i>5'd0; i=i-5'd1)
begin
for (j=5'd1; j<i+5'd1; j=j+5'd1)
begin
j2<=j;
j1<=j-8'd1;
ram_2port ram1(j1,j2,clock,0,0,1,1,q_a,q_b);
if (q_a > q_b)
begin
ram_2port ram2(j1,j2,clock,q_b,q_a,0,0,0,0);
end
end
end
end
endmodule
Any help would be much appreciated!