-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpadding_reg.v
172 lines (148 loc) · 3.81 KB
/
padding_reg.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2024/08/26 22:14:06
// Design Name:
// Module Name: padding_reg
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
// fsm
module padding_reg (
input clk,
input reset,
input en,
input [3343:0] R_padded,
input [3343:0] G_padded,
input [3343:0] B_padded,
output reg [3343:0] R_row0, //418x8=3344
output reg [3343:0] G_row0,
output reg [3343:0] B_row0,
output reg [3343:0] R_row1, //418x8=3344
output reg [3343:0] G_row1,
output reg [3343:0] B_row1,
output reg [3343:0] R_row2, //418x8=3344
output reg [3343:0] G_row2,
output reg [3343:0] B_row2,
output reg [8:0] count
);
reg [2:0] present_state, next_state;
reg [1:0] ctrl, wait_a;
localparam IDLE = 3'd0;
localparam S1 = 3'd1;
localparam S2 = 3'd2;
localparam S3 = 3'd3;
localparam WAIT = 3'd4;
always @(posedge clk) begin
if(reset) begin
present_state <= IDLE;
wait_a <= 0; // Reset `wait_a` on reset
end
else begin
present_state <= next_state;
end
end
always @(*) begin
case (present_state)
IDLE: begin
if (en) begin
next_state = WAIT;
end else begin
next_state = IDLE;
end
end
S1: begin
if (ctrl == 1) begin
next_state = S2;
end else begin
next_state = S1;
end
end
S2: begin
if (ctrl == 2) begin
next_state = S3;
end else begin
next_state = S2;
end
end
S3: begin
if (ctrl == 3) begin
next_state = WAIT; // Return to WAIT state after completing S3
end else begin
next_state = S3;
end
end
WAIT: begin
if(wait_a == 2'd2)
next_state = S1; // Move to S1 after wait period
else
next_state = WAIT; // Stay in WAIT state
end
default: begin
next_state = IDLE;
end
endcase
end
always @(posedge clk) begin
case(present_state)
IDLE: begin
R_row0 <= 3343'dz;
G_row0 <= 3343'dz;
B_row0 <= 3343'dz;
R_row1 <= 3343'dz;
G_row1 <= 3343'dz;
B_row1 <= 3343'dz;
R_row2 <= 3343'dz;
G_row2 <= 3343'dz;
B_row2 <= 3343'dz;
count <= 0;
ctrl <= 2'd1;
end
S1: begin
R_row0 <= R_padded;
G_row0 <= G_padded;
B_row0 <= B_padded;
if (count == 9'd416)
count <= 0;
count <= count + 1;
ctrl <= 2'd2;
end
S2: begin
R_row1 <= R_padded;
G_row1 <= G_padded;
B_row1 <= B_padded;
if (count == 9'd416)
count <= 0;
count <= count + 1;
ctrl <= 2'd3;
end
S3: begin
R_row2 <= R_padded;
G_row2 <= G_padded;
B_row2 <= B_padded;
if (count == 9'd416)
count <= 0;
count <= count + 1;
ctrl <= 2'd1;
wait_a <= 0;
end
WAIT: begin
wait_a <= wait_a + 1'b1 ;
if (count == 9'd416)
count <= 0;
count <= count + 1;
end
endcase
end
endmodule