generated from saji/ecp5-template
bram stuff
This commit is contained in:
parent
00ebfa8009
commit
75ef4ad594
|
@ -1,14 +1,17 @@
|
||||||
module hub75e (
|
module hub75e (
|
||||||
input clk,
|
input clk,
|
||||||
input write_trig,
|
input write_trig,
|
||||||
input [1:0][BIT_DEPTH - 1:0] rgb_row[ROW_DEPTH],
|
|
||||||
output reg [4:0] addr,
|
output reg [4:0] addr,
|
||||||
output reg [2:0] panel_rgb0,
|
output reg [2:0] panel_rgb0,
|
||||||
output reg [2:0] panel_rgb1,
|
output reg [2:0] panel_rgb1,
|
||||||
output reg display_clk = 0,
|
output reg display_clk = 0,
|
||||||
output reg out_enable = 1,
|
output reg out_enable = 1,
|
||||||
output reg latch = 0,
|
output reg latch = 0,
|
||||||
output reg done = 0
|
output reg done = 0,
|
||||||
|
|
||||||
|
// bram interface (using clk)
|
||||||
|
output reg [8:0] pixbuf_addr,
|
||||||
|
input [35:0] pixbuf_data
|
||||||
);
|
);
|
||||||
|
|
||||||
parameter integer ROW_DEPTH = 128, BIT_DEPTH = 8;
|
parameter integer ROW_DEPTH = 128, BIT_DEPTH = 8;
|
||||||
|
@ -27,8 +30,6 @@ module hub75e (
|
||||||
|
|
||||||
|
|
||||||
assign addr = 5'b10101;
|
assign addr = 5'b10101;
|
||||||
assign panel_rgb0 = 3'b101;
|
|
||||||
assign panel_rgb1 = 3'b010;
|
|
||||||
|
|
||||||
// initial begin
|
// initial begin
|
||||||
// state <= StateInit;
|
// state <= StateInit;
|
||||||
|
@ -55,11 +56,12 @@ module hub75e (
|
||||||
counter <= counter + 1;
|
counter <= counter + 1;
|
||||||
case (state)
|
case (state)
|
||||||
StateInit: begin
|
StateInit: begin
|
||||||
// wait for the signal to write out our lines.
|
|
||||||
if (write_trig) begin
|
|
||||||
bcm_shift <= 7;
|
bcm_shift <= 7;
|
||||||
counter <= 0;
|
counter <= 0;
|
||||||
done <= 0;
|
done <= 0;
|
||||||
|
pixbuf_addr <= 0;
|
||||||
|
// wait for the signal to write out our lines.
|
||||||
|
if (write_trig) begin
|
||||||
state <= StateWriteRow;
|
state <= StateWriteRow;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -68,20 +70,31 @@ module hub75e (
|
||||||
if (should_clock) begin
|
if (should_clock) begin
|
||||||
// we have data to clock
|
// we have data to clock
|
||||||
display_clk <= counter[0];
|
display_clk <= counter[0];
|
||||||
if (counter[0]) begin
|
if (~counter[0]) begin
|
||||||
// load the next pixel data. this is the falling edge since the
|
// the data from the previous cycle is now ready.
|
||||||
// previous value is 1.
|
panel_rgb0 <= {
|
||||||
|
(pixbuf_data[bcm_shift]),
|
||||||
|
(pixbuf_data[bcm_shift + 8]),
|
||||||
|
(pixbuf_data[bcm_shift + 16])
|
||||||
|
};
|
||||||
|
panel_rgb1 <= {
|
||||||
|
(pixbuf_data[bcm_shift]),
|
||||||
|
(pixbuf_data[bcm_shift + 8]),
|
||||||
|
(pixbuf_data[bcm_shift + 16])
|
||||||
|
};
|
||||||
|
// write it out!
|
||||||
|
end else begin
|
||||||
|
// update the bram address so it's ready at the next clock cycle.
|
||||||
|
pixbuf_addr <= pixbuf_addr + 1;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if (should_expose) begin
|
if (should_expose) begin
|
||||||
// we are still in our expose state, and our bcm shift is not the
|
|
||||||
// first one, so we should expose.
|
|
||||||
out_enable <= 0;
|
out_enable <= 0;
|
||||||
end else begin
|
end else begin
|
||||||
out_enable <= 1;
|
out_enable <= 1;
|
||||||
end
|
end
|
||||||
// if we're done with our data clock out and also done with exposing
|
// if we're done with our data clock out and also done with exposing
|
||||||
// the previous frame, go next.
|
// the previous line, go to the latchout stage.
|
||||||
if (~should_clock && ~should_expose) begin
|
if (~should_clock && ~should_expose) begin
|
||||||
counter <= 0;
|
counter <= 0;
|
||||||
state <= StateLatchout;
|
state <= StateLatchout;
|
||||||
|
@ -92,10 +105,11 @@ module hub75e (
|
||||||
// raise latch high; compute next bcm.
|
// raise latch high; compute next bcm.
|
||||||
latch <= 1;
|
latch <= 1;
|
||||||
out_enable <= 1;
|
out_enable <= 1;
|
||||||
|
pixbuf_addr <= 0;
|
||||||
counter <= counter + 1;
|
counter <= counter + 1;
|
||||||
if (counter > 3) begin
|
if (counter > 3) begin
|
||||||
if (bcm_shift == 0) begin
|
if (bcm_shift == 0) begin
|
||||||
// done with the line. do the last (short) expose
|
// we've reached the lsb of this data, go to the next one!
|
||||||
state <= StateFinishExpose;
|
state <= StateFinishExpose;
|
||||||
latch <= 0;
|
latch <= 0;
|
||||||
end else begin
|
end else begin
|
||||||
|
|
28
verilog/lineram.v
Normal file
28
verilog/lineram.v
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
module lineram #(
|
||||||
|
parameter DATA_WIDTH = 36,
|
||||||
|
parameter ADDR_WIDTH = 9
|
||||||
|
) (
|
||||||
|
input [DATA_WIDTH - 1:0] din,
|
||||||
|
input [ADDR_WIDTH - 1:0] addr_w,
|
||||||
|
output reg [DATA_WIDTH - 1:0] dout,
|
||||||
|
input [ADDR_WIDTH - 1:0] addr_r,
|
||||||
|
input write_en,
|
||||||
|
input read_clk,
|
||||||
|
input write_clk
|
||||||
|
);
|
||||||
|
|
||||||
|
reg [DATA_WIDTH - 1] ram[2**ADDR_WIDTH];
|
||||||
|
|
||||||
|
initial begin
|
||||||
|
for(int i=0; i < 2**ADDR_WIDTH; i=i+1) begin
|
||||||
|
ram[i] = 0;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
always @(posedge write_clk) begin
|
||||||
|
if (write_en) ram[addr_w] <= din;
|
||||||
|
end
|
||||||
|
always @(posedge read_clk) begin
|
||||||
|
dout <= ram[addr_r];
|
||||||
|
end
|
||||||
|
endmodule
|
|
@ -4,8 +4,6 @@ module hub75e_tb;
|
||||||
reg clk;
|
reg clk;
|
||||||
reg write_trig;
|
reg write_trig;
|
||||||
|
|
||||||
reg [1:0][7:0] rgb_row[128];
|
|
||||||
|
|
||||||
wire [4:0] addr_out;
|
wire [4:0] addr_out;
|
||||||
wire [2:0] rgb0;
|
wire [2:0] rgb0;
|
||||||
wire [2:0] rgb1;
|
wire [2:0] rgb1;
|
||||||
|
@ -15,27 +13,58 @@ module hub75e_tb;
|
||||||
wire done;
|
wire done;
|
||||||
|
|
||||||
|
|
||||||
|
// block ram inputs
|
||||||
|
reg [35:0] bram_data_in;
|
||||||
|
reg [8:0] bram_addr_w;
|
||||||
|
reg bram_write_en;
|
||||||
|
|
||||||
|
|
||||||
|
wire [8:0] bram_addr_r;
|
||||||
|
wire [35:0] bram_data_out;
|
||||||
|
|
||||||
|
|
||||||
|
lineram bram (
|
||||||
|
.din(bram_data_in),
|
||||||
|
.addr_w(bram_addr_w),
|
||||||
|
.dout(bram_data_out),
|
||||||
|
.addr_r(bram_addr_r),
|
||||||
|
.write_en(bram_write_en),
|
||||||
|
.read_clk(clk),
|
||||||
|
.write_clk(clk)
|
||||||
|
);
|
||||||
|
|
||||||
hub75e dut (
|
hub75e dut (
|
||||||
.clk(clk),
|
.clk(clk),
|
||||||
.write_trig(write_trig),
|
.write_trig(write_trig),
|
||||||
.rgb_row(rgb_row),
|
|
||||||
.addr(addr_out),
|
.addr(addr_out),
|
||||||
.panel_rgb0(rgb0),
|
.panel_rgb0(rgb0),
|
||||||
.panel_rgb1(rgb1),
|
.panel_rgb1(rgb1),
|
||||||
.display_clk(display_clk),
|
.display_clk(display_clk),
|
||||||
.out_enable(out_enable),
|
.out_enable(out_enable),
|
||||||
.latch(latch),
|
.latch(latch),
|
||||||
.done(done)
|
.done(done),
|
||||||
|
|
||||||
|
.pixbuf_addr(bram_addr_r),
|
||||||
|
.pixbuf_data(bram_data_out)
|
||||||
);
|
);
|
||||||
|
|
||||||
always #5 clk = !clk;
|
always #5 clk = !clk;
|
||||||
initial begin
|
initial begin
|
||||||
$dumpfile("wave.vcd");
|
$dumpfile("wave.vcd");
|
||||||
$dumpvars(0, hub75e_tb);
|
$dumpvars(0, hub75e_tb);
|
||||||
clk = 0;
|
clk <= 0;
|
||||||
write_trig = 1;
|
bram_addr_w <= 0;
|
||||||
|
bram_write_en <= 1;
|
||||||
|
repeat (1) @(posedge clk);
|
||||||
|
for (int i=0; i < 128; i=i+1) begin
|
||||||
|
bram_data_in <= $urandom % 'hFFFFFF;
|
||||||
|
bram_addr_w <= i;
|
||||||
|
repeat (1) @(posedge clk);
|
||||||
|
end
|
||||||
|
bram_write_en <= 1;
|
||||||
|
write_trig <= 1;
|
||||||
repeat (2) @(posedge clk);
|
repeat (2) @(posedge clk);
|
||||||
write_trig = 0;
|
write_trig <= 0;
|
||||||
|
|
||||||
@(done);
|
@(done);
|
||||||
repeat (20) @(posedge clk);
|
repeat (20) @(posedge clk);
|
||||||
|
|
Loading…
Reference in a new issue