-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_bench.v
141 lines (125 loc) · 2.92 KB
/
test_bench.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
`timescale 1ns / 1ps
// VGA_sycn icin ram yazilacak
// butonlarin debounce olayina bakmak gerek
// butonlara fonksiyonlar assign edilecek
// surekli cisim dusecek yapilabilir
module vga_test(
input wire clk, reset,
input wire [7:0] sw,
output wire hsync, vsync,
output wire [7:0] rgb,
output wire [7:0] led
);
wire [9:0] x, y;
wire [5:0] x_div,y_div;
wire [9:0] address;
wire [17:0] instruction;
wire [7:0] port_id;
wire write_strobe;
wire [7:0] out_port;
wire read_strobe;
reg [7:0] in_port;
reg [7:0] seed;
reg [7:0] ctextIn;
reg [7:0] ttime;
wire [7:0] zOut;
wire [7:0] pico_data_out;
wire rst;
assign rst = reset;
msdv5 program (
.address(address),
.instruction(instruction),
.clk(clk)
);
// Instantiate the module
LFSR3 My_RNG (
.clk(clk),
.rst(rst),
.ctextIn(ctextIn),
.zOut(zOut),
.seed(seed)
);
always@(posedge clk or posedge rst)
begin
if(rst)
begin
seed <= 0;
ctextIn <= 0;
ttime <= 0;
end
else
begin
if (ttime==6) begin
ttime <= 0;
end
else begin
ttime <= ttime + 1;
end
seed <= seed + 1;
ctextIn <= ctextIn + 3;
end
end
kcpsm3 my_pico (
.address(address),
.instruction(instruction),
.port_id(port_id),
.write_strobe(write_strobe),
.out_port(out_port),
.read_strobe(read_strobe),
.in_port(in_port),
.interrupt(interrupt),
.interrupt_ack(interrupt_ack),
.reset(rst),
.clk(clk)
);
// register for Basys 2 8-bit RGB DAC
reg [7:0] rgb_reg;
reg [7:0] led_reg;
// video status output from vga_sync to tell when to route out rgb signal to DAC
wire video_on;
wire [7:0] vga_out;
// VGA data control, edge detection
vga_data_controller vga_control (
.ptick(ptick),
.clk(clk),
.rst(rst),
.pico_addr(port_id),
.pico_data_in(out_port),
.pico_write_strobe(write_strobe),
.pico_read_strobe(read_strobe),
.x_div(x_div),
.y_div(y_div),
.pico_data_out(pico_data_out),
.vga_out(vga_out)
);
assign x_div = x[9:4]; // divide to 16 for pixel implementation
assign y_div = y[9:4]; // divide to 16 for pixel implementation
// instantiate vga_sync
vga_sync vga_sync_unit (.clk(clk),
.reset(rst),
.hsync(hsync),
.vsync(vsync),
.video_on(video_on),
.p_tick(ptick),
.x(x),
.y(y)
);
//assign Led = {clk, reset, hsync, vsync, video_on};
// rgb buffer
always @(posedge clk or posedge rst)
if (rst)
rgb_reg <= 0;
else
begin
rgb_reg <= vga_out;
case(port_id)
8'hFD: led_reg <=out_port;
8'hFE: in_port <= sw; //Read buttons
8'hFF: in_port <= ttime;
default: if(read_strobe == 1) in_port <= pico_data_out;
endcase
end
// output
assign rgb = (video_on) ? rgb_reg : 8'b0;
assign led = led_reg;
endmodule