-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatrixTest.v.bak
211 lines (113 loc) · 3.5 KB
/
matrixTest.v.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
module matrixTest #(
parameter SCREEN_WIDTH = 64, //Depth of shift isters
parameter SCREEN_WIDTH_BITS = 6, //2^ of this should equal above
parameter SCREEN_LENGTH = 32,
parameter SCREEN_LENGTH_BITS = 5, //2^ of this should equal length
parameter OE_HOLD = 1000 //OE hold time in clock cycles
)(
input MCLK, //50MHZ board clock
//input source_vaid,
//input [BIN_WDITH-1:0] F_BIN_IN, //Input frequency bins from FFT core
//input RESET,
//RGB shift registers. One set for top half of matrix
//and other set for bottom half
output reg [2:0] RGB1 = 0, //Top half shift registers
output reg [2:0] RGB2 = 0, //Bottom half shift registers
output reg [3:0] ROW_ADDRESS = 0, //Row selects
output wire CLK_MATRIX, //output clock to matrix
output reg LATCH = 0,
output reg OE = 1, //Output enable
output reg [2:0] GND = 0
);
reg [23:0] test_bin_buffer [63:0];
reg [63:0] matrix_frame_buffer [31:0];
/** Function to calculate what LEDs should be on for current row */
function [63:0] row_set;
input [SCREEN_LENGTH_BITS-1:0] row_no;
integer k;
begin
for(k = 0; k < SCREEN_WIDTH; k = k + 1) begin
if(row_no < (test_bin_buffer[k] >> 19)) //>> By 19 to scale to between 2^24 to 0-32
row_set[k] = 0;
else
row_set[k] = 1;
end
end endfunction
integer i;
integer j;
initial begin
for (i=0;i<64;i=i+1) begin
test_bin_buffer[i] = 24'd8388608;
end
/* Create 'histogram' from bin_buffer values, store this in frame buffer */
for(j=0;j<32;j=j+1) begin
matrix_frame_buffer[j] = row_set(j);
end
end
/************** Driving the display *************************/
reg [3:0] clock_counter = 0;
reg clock_25 = 0;
always @(posedge MCLK) begin
clock_counter <= clock_counter + 1;
if(clock_counter == 3'd3)
clock_25 <= ~clock_25;
end
reg clk_enable = 0;
reg shift_in_clk;
reg RESET = 0;
reg [15:0] delay_counter = 0;
assign CLK_MATRIX = shift_in_clk;
reg [31:0] shift_counter = 0;
/* Initialize */
always @(posedge MCLK) begin
delay_counter <= delay_counter + 1'd1;
if(delay_counter[15]) begin
RESET <= 1;
GND <= 0;
end
end
/* Generate clock signal for shift regs simply by enabling the
main clock on whilst shifting bits in, and off before/after that.
*/
always @* begin
if(clk_enable == 1)
shift_in_clk <= clock_25;
else
shift_in_clk <= 0;
end
always @(posedge clock_25) begin
if(RESET) begin
//Shift data bits in
if(shift_counter == SCREEN_WIDTH) begin
LATCH <= 1; //Latch will latch bits into leds
ROW_ADDRESS <= ROW_ADDRESS + 4'd1; //Get ready to scan next row
end else begin
LATCH <= 0;
end
if(shift_counter < SCREEN_WIDTH) begin
clk_enable <= 1;
//Shift in bits from frame buffer
//Blue LEDs
RGB1[0] <= matrix_frame_buffer[ROW_ADDRESS][shift_counter];
RGB2[0] <= matrix_frame_buffer[ROW_ADDRESS+16][shift_counter]; //Bottom half
//Green LEDs
RGB1[1] <= 0;
RGB2[1] <= 0;
//Red LEDs
RGB1[2] <= 0;
RGB2[2] <= 0;
end else
clk_enable = 0; //Disable clocking signal for shift regs after all bits are shifted in
//Deassert output enable after latch to unblank the display
if(shift_counter > SCREEN_WIDTH + 1 && shift_counter < SCREEN_WIDTH + OE_HOLD-1)
OE <= 0;
else
OE <= 1;
//Reset counter to 0
if(shift_counter < SCREEN_WIDTH + OE_HOLD)
shift_counter <= shift_counter + 1'd1;
else
shift_counter <= 0;
end
end
endmodule