-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplay_control.v
203 lines (176 loc) · 5.09 KB
/
display_control.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
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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 15:10:28 06/14/2015
// Design Name:
// Module Name: display_control
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module display_control
#(
parameter COLOR_BITS = 4,
parameter COL_ADDR_BITS = 6, // Number of address bits for columns in a row
parameter ROW_ADDR_BITS = 4, // Number of address bits for rows in a column
parameter COLOR_COUNT = 3
)
(
input wire clk,
input wire [ROW_DAT_WIDTH-1:0] row_in,
output wire [ROW_ADDR_BITS-1:0] next_row,
output reg hub_clk, hub_noe, hub_lat,
output reg [ROW_ADDR_BITS-1:0] hub_mux,
output wire [COLOR_COUNT-1:0] s_out
);
// All the local definitions!
localparam NUM_COL = (2**COL_ADDR_BITS); // Number of LEDs in a row
localparam COLOR_DAT_WIDTH = (NUM_COL * COLOR_BITS);
localparam ROW_DAT_WIDTH = (COLOR_DAT_WIDTH * COLOR_COUNT); // Number of bits to hold the data for 1 row
localparam LAST_STATE = (NUM_COL * 2);
localparam LAST_BCM_STATE = (2**COLOR_BITS) - 2;
// Constants
localparam HUB_EN_ON = 1'b0;
localparam HUB_LATCH_EN = 1'b1;
localparam SHIFT_LATCH_EN = 1'b1;
localparam SHIFT_EN_ON = 1'b1;
// convenience wires
wire [COLOR_DAT_WIDTH-1:0] color_in [COLOR_COUNT-1:0];
// Stuff we'll actually control!
reg outshift_latch = 1'b0;
reg outshift_en = 1'b0;
reg colorshift_latch = 1'b0;
reg colorshift_en = 1'b0;
// Loop variables
reg [ROW_ADDR_BITS-1:0] cur_row = 0; // For keeping track of which row we're on
reg [COLOR_BITS-1:0] bcm_count = LAST_BCM_STATE - 2; // Which bit are we on in the current row
reg [COL_ADDR_BITS+1:0] load_shift_latch = 0; // We need (2**COL_ADDR_BITS) shift clocks and 1 more for the latch
// Generators!
genvar i, j;
integer k;
generate for (i = 0; i < COLOR_COUNT; i = i + 1) begin : COLOR_BREAKOUT
for (j = 0; j < NUM_COL; j = j + 1) begin : ELEM_BREAKOUT
localparam CUR_SRC = ((COLOR_COUNT*j)+i)*COLOR_BITS;
localparam NEXT_SRC = CUR_SRC + COLOR_BITS;
localparam CUR_DST = j*COLOR_BITS;
localparam NEXT_DST = CUR_DST + COLOR_BITS;
assign color_in[i][NEXT_DST-1:CUR_DST] = row_in[NEXT_SRC-1:CUR_SRC];
end
end
endgenerate
generate for (i = 0; i < COLOR_COUNT; i= i + 1) begin : COLORSHIFTGEN
wire [NUM_COL-1:0] color_shift_out;
parallel_shift #(.SHIFT_WIDTH(COLOR_BITS), .PARALLEL(NUM_COL)) color_shift (
.clk(clk), .en(colorshift_en), .latch(colorshift_latch),
.in(color_in[i]), .out(color_shift_out)
);
shift_reg #(.N(NUM_COL)) outshift (
.clk(clk),
.in(color_shift_out), .out(s_out[i]),
.latch(outshift_latch),
.en(outshift_en)
);
end
endgenerate
always @(posedge clk) begin
// State updater!
if (load_shift_latch == LAST_STATE) begin
load_shift_latch <= 0;
end
else begin
load_shift_latch <= load_shift_latch + 1;
end
// Ouput clock handler
if (~load_shift_latch[0]) begin
hub_clk <= ~hub_clk;
end
else begin
hub_clk <= 1'b0;
end
// HUB75 mux pins handled here
if (load_shift_latch == LAST_STATE) begin
if (bcm_count == LAST_BCM_STATE) begin
hub_mux <= cur_row; // Bring the mux up to date
end
end
// HUB75 latch
if (load_shift_latch == LAST_STATE) begin
hub_lat <= HUB_LATCH_EN; // Latch the ouput from the previous cycle
end
else begin
hub_lat <= ~HUB_LATCH_EN;
end
// HUB75 enable
if (load_shift_latch == LAST_STATE - 1) begin
if (bcm_count == LAST_BCM_STATE) begin
hub_noe <= ~HUB_EN_ON;
end
end
else if (load_shift_latch == 2) begin
hub_noe <= HUB_EN_ON;
end
// Outshift enable pulses
if (~load_shift_latch[0] && load_shift_latch != (LAST_STATE-1) && load_shift_latch != LAST_STATE) begin
outshift_en <= SHIFT_EN_ON;
end
else begin
outshift_en <= ~SHIFT_EN_ON;
end
// Latch the output shifter
if (load_shift_latch == (LAST_STATE-1)) begin
outshift_latch <= SHIFT_LATCH_EN; // Get the next bit latched into the outshifter
end
else begin
outshift_latch <= ~SHIFT_LATCH_EN;
end
// Colorshifter latching
if (load_shift_latch == 2) begin
if (bcm_count == LAST_BCM_STATE-1) begin
colorshift_latch <= SHIFT_LATCH_EN; // Put the 0th bit of the next row on the shifter
end
end
else begin
colorshift_latch <= ~SHIFT_LATCH_EN;
end
// Color shifter enabling
if (load_shift_latch == 2) begin
for (k = 2; ((2**k)-3) < LAST_BCM_STATE-2; k = k + 1) begin
if (bcm_count == ((2**k)-3)) begin
colorshift_en <= SHIFT_EN_ON;
end
end
if (bcm_count == LAST_BCM_STATE) begin
colorshift_en <= SHIFT_EN_ON; // Put the 1st bit of the next row on the shifter
end
end
else begin
colorshift_en <= ~SHIFT_EN_ON;
end
// Update the current row!
if (load_shift_latch == 0) begin
if (bcm_count == LAST_BCM_STATE) begin
cur_row <= cur_row + 1;
end
end
// BCM state update
if (load_shift_latch == LAST_STATE) begin
if (bcm_count == LAST_BCM_STATE) begin
bcm_count <= 0;
end
else begin
bcm_count <= bcm_count + 1;
end
end
end
assign next_row = cur_row + 1;
endmodule