2018-08-13 22:17:36 +00:00
|
|
|
|
2018-02-03 20:20:56 +00:00
|
|
|
`include "hvsync_generator.v"
|
|
|
|
`include "digits10.v"
|
2018-10-05 18:02:46 +00:00
|
|
|
`include "ram.v"
|
|
|
|
`include "lfsr.v"
|
2018-02-03 20:20:56 +00:00
|
|
|
|
2018-02-15 18:31:32 +00:00
|
|
|
module test_ram2_top(
|
2018-02-03 20:20:56 +00:00
|
|
|
input clk, reset,
|
2018-10-05 18:02:46 +00:00
|
|
|
output [1:0] out
|
2018-02-03 20:20:56 +00:00
|
|
|
);
|
|
|
|
wire display_on;
|
|
|
|
wire [8:0] hpos;
|
|
|
|
wire [8:0] vpos;
|
|
|
|
|
|
|
|
reg ram_writeenable = 0;
|
|
|
|
wire [9:0] ram_addr = {row,col};
|
|
|
|
reg [7:0] ram_write;
|
2018-10-05 18:02:46 +00:00
|
|
|
reg [7:0] ram_read;
|
|
|
|
reg [7:0] ram_write;
|
|
|
|
reg [7:0] rand;
|
2018-02-03 20:20:56 +00:00
|
|
|
|
2018-10-05 18:02:46 +00:00
|
|
|
reg clk2;
|
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
clk2 <= !clk2;
|
|
|
|
end
|
|
|
|
|
|
|
|
RAM_sync ram(
|
|
|
|
.clk(clk2),
|
|
|
|
.din(ram_write),
|
|
|
|
.dout(ram_read),
|
2018-02-03 20:20:56 +00:00
|
|
|
.addr(ram_addr),
|
|
|
|
.we(ram_writeenable)
|
|
|
|
);
|
|
|
|
|
2018-10-05 18:02:46 +00:00
|
|
|
LFSR lfsr(
|
|
|
|
.clk(clk2),
|
|
|
|
.reset(reset),
|
|
|
|
.enable(!reset),
|
|
|
|
.lfsr(rand)
|
|
|
|
);
|
|
|
|
|
|
|
|
hvsync_generator #(256,60,40,25) hvsync_gen(
|
|
|
|
.clk(clk2),
|
2018-02-03 20:20:56 +00:00
|
|
|
.reset(reset),
|
|
|
|
.hsync(hsync),
|
|
|
|
.vsync(vsync),
|
|
|
|
.display_on(display_on),
|
|
|
|
.hpos(hpos),
|
|
|
|
.vpos(vpos)
|
|
|
|
);
|
|
|
|
|
|
|
|
wire [4:0] row = vpos[7:3];
|
|
|
|
wire [4:0] col = hpos[7:3];
|
|
|
|
wire [3:0] digit = ram_read[3:0];
|
2018-10-05 18:02:46 +00:00
|
|
|
wire [2:0] xofs = hpos[2:0];
|
2018-02-03 20:20:56 +00:00
|
|
|
wire [2:0] yofs = vpos[2:0];
|
2018-10-05 18:02:46 +00:00
|
|
|
wire [7:0] bits; // TODO?
|
2018-02-03 20:20:56 +00:00
|
|
|
|
2018-10-05 18:02:46 +00:00
|
|
|
digits10_case numbers(
|
2018-02-03 20:20:56 +00:00
|
|
|
.digit(digit),
|
|
|
|
.yofs(yofs),
|
|
|
|
.bits(bits)
|
|
|
|
);
|
|
|
|
|
2018-10-05 18:02:46 +00:00
|
|
|
wire g = display_on && bits[xofs ^ 3'b111];
|
|
|
|
|
|
|
|
assign out = (hsync||vsync) ? 0 : (1+g+g);
|
|
|
|
|
|
|
|
always @(posedge clk2)
|
|
|
|
if (display_on && vpos[2:0] == 7 && rand[0])
|
2018-02-03 20:20:56 +00:00
|
|
|
case (hpos[2:0])
|
|
|
|
6: begin
|
|
|
|
ram_write <= ram_read + 1;
|
|
|
|
ram_writeenable <= 1;
|
|
|
|
end
|
|
|
|
7: ram_writeenable <= 0;
|
|
|
|
endcase
|
|
|
|
|
|
|
|
endmodule
|