-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassorted_modules.sv.bak
197 lines (149 loc) · 5.89 KB
/
assorted_modules.sv.bak
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//==========================================================================
// SUBMODULES
//
// Basic submodules for cgol
//==========================================================================
module flop #(parameter WIDTH = 8)
(input logic ph1, ph2,
input logic [WIDTH-1:0] d,
output logic [WIDTH-1:0] q);
logic [WIDTH-1:0] mid;
latch #(WIDTH) master(ph2, d, mid);
latch #(WIDTH) slave(ph1, mid, q);
endmodule
module flopr #(parameter WIDTH = 8)
(input logic ph1, ph2, reset,
input logic [WIDTH-1:0] d,
output logic [WIDTH-1:0] q);
logic [WIDTH-1:0] d2, resetval;
assign resetval = 0;
mux2 #(WIDTH) enmux(q, 1'b0, en, d2);
flop #(WIDTH) f(ph1, ph2, d2, q);
endmodule
module flopen #(parameter WIDTH = 8)
(input logic ph1, ph2, en,
input logic [WIDTH-1:0] d,
output logic [WIDTH-1:0] q);
logic [WIDTH-1:0] d2;
mux2 #(WIDTH) enmux(q, d, en, d2);
flop #(WIDTH) f(ph1, ph2, d2, q);
endmodule
module flopenr #(parameter WIDTH = 8)
(input logic ph1, ph2, reset, en,
input logic [WIDTH-1:0] d,
output logic [WIDTH-1:0] q);
logic [WIDTH-1:0] d2, resetval;
assign resetval = 0;
mux3 #(WIDTH) enrmux(q, d, resetval, {reset, en}, d2);
flop #(WIDTH) f(ph1, ph2, d2, q);
endmodule
module latch #(parameter WIDTH = 8)
(input logic ph,
input logic [WIDTH-1:0] d,
output logic [WIDTH-1:0] q);
always_latch
if (ph) q <= d;
endmodule
module mux2 #(parameter WIDTH = 8)
(input logic [WIDTH-1:0] d0, d1,
input logic s,
output logic [WIDTH-1:0] y);
assign y = s ? d1 : d0;
endmodule
module mux3 #(parameter WIDTH = 8)
(input logic [WIDTH-1:0] d0, d1, d2,
input logic [1:0] s,
output logic [WIDTH-1:0] y);
always_comb
casez (s)
2'b00: y = d0;
2'b01: y = d1;
2'b1?: y = d2;
endcase
endmodule
//==========================================================================
// TOP-LEVEL DECODER MODULE
// computes the next state of an entire row using 8 decoder modules
//==========================================================================
module decoder_top (input logic [7:0] row_in, row_a, row_b,
output logic [7:0] row_out);
decoder d0(row_in[0], { row_a[1:0],row_a[7], row_b[1:0],row_b[7], row_in[1], row_in[7] }, row_out[0]);
decoder d1(row_in[1], { row_a[2:0],row_b[2:0], row_in[0], row_in[2] }, row_out[1]);
decoder d2(row_in[2], { row_a[3:1],row_b[3:1], row_in[1], row_in[3] }, row_out[2]);
decoder d3(row_in[3], { row_a[4:2],row_b[4:2], row_in[2], row_in[4] }, row_out[3]);
decoder d4(row_in[4], { row_a[5:3],row_b[5:3], row_in[3], row_in[5] }, row_out[4]);
decoder d5(row_in[5], { row_a[6:4],row_b[6:4], row_in[4], row_in[6] }, row_out[5]);
decoder d6(row_in[6], { row_a[7:5],row_b[7:5], row_in[5], row_in[7] }, row_out[6]);
decoder d7(row_in[7], { row_a[7:6],row_a[0], row_b[7:6],row_b[0], row_in[6], row_in[0] }, row_out[7]);
endmodule
//==========================================================================
// CONTROLLER
// RWSelect 1 for write, 0 for read
// every clock cycle, increment addr
// every 64 clock cycles is one frame
// every frame, increment count
// every 64 frames, switch from read to write for one frame
//==========================================================================
module controller (input logic ph1, input logic ph2, input logic reset,
output logic RWSelect, output logic [2:0] addr);
logic [2:0] count;
logic en_addr;
always_latch begin
if (reset) begin
//addr = 3'b000;
count = 6'b000000;
RWSelect = 1'b1;
end
else if ((addr == 3'b111)&(ph1)) begin
//increment counter every time the entire matrix is read or written through
count <= count + 1'b1;
//if we have gone through 64 life cycles, do a write
if (count == 3'b111) RWSelect <= 1'b0;
else RWSelect <= 1'b1;
end
//if (ph1) begin
//increment address value
//addr <= addr + 1'b1;
//end
end
assign en_addr = 1'b1;
assign addr_next = addr+3'b001
// maybe change to flopenr?
flopenr #(3) addr_flop(ph1, ph2, reset, en_addr, addr_next, addr);
endmodule
//==========================================================================
// DECODER MODULE
// returns true if the center cell, given by boolean input 'center', should
// be lit on the next generation (as determined by the 8-bit input 'sides')
//==========================================================================
module decoder (input logic center, input logic [7:0] sides,
output logic nexton);
always_comb begin
// sum the bits coming in
logic [2:0] sum;
sum = sides[0] + sides[1] + sides[2] + sides[3] + sides[4] + sides[5] + sides[6] + sides[7];
//consider center bits and bits of sum
casex ({center, sum})
4'b0011:
// a dead cell with 3 neighbors comes back to life
nexton = 1;
4'b101x:
// if a live cell has 2 or 3 neighbors, it survives
nexton = 1;
default:
// it should die in all other situations
nexton = 0;
endcase
end
endmodule
//==========================================================================
// DISPLAY CONTROLLER
//
// given inputs of bitline in and 3-bit address for bit to consider, choose
// which bits to output
//==========================================================================
module dispcontrol (input logic [2:0] addr, input logic [7:0] BitIn, input logic ph1, input logic ph2,
output logic [7:0] row, output logic [7:0] col);
assign row = (8'b00000001 << addr);
assign col = ~BitIn;
endmodule