Skip to content

Commit 1def30a

Browse files
committed
feat(acquisition_sync_cache_wr.v): add wft_cnt variable to keep track of the number of cycles in the WFT state
1 parent 06713d2 commit 1def30a

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

ada.srcs/design/acquisition_sync_cache_wr.v

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,19 @@ module acquisition_sync_cache_wr (
5757
parameter WFRD_CNT_MAX_75 = 191;
5858
parameter WFRD_CNT_MAX_100 = 63;
5959

60+
// just incase state machine won't be stucked if we don't meet the trigger condition in WFT state
61+
parameter WFT_CNT_MAX = 2500;
62+
6063
// reg define
6164
reg [4:0] state;
6265
reg [4:0] next_state;
6366

64-
reg [7:0] cache_cnt;
67+
reg [15:0] cache_cnt;
68+
69+
reg [15:0] wfrd_cnt;
70+
reg [15:0] wfrd_cnt_max;
6571

66-
reg [7:0] wfrd_cnt;
67-
reg [7:0] wfrd_cnt_max;
72+
reg [15:0] wft_cnt;
6873

6974
reg trigger_enable;
7075

@@ -148,7 +153,7 @@ module acquisition_sync_cache_wr (
148153
end
149154
end
150155
CACHING: begin
151-
if (cache_cnt == 8'd255) begin
156+
if (cache_cnt == BRAM_DEPTH) begin
152157
if (trigger_enable) begin
153158
next_state = WFT;
154159
end else begin
@@ -161,6 +166,8 @@ module acquisition_sync_cache_wr (
161166
WFT: begin
162167
if (triggered) begin
163168
next_state = WFRD;
169+
end else if (wft_cnt == WFT_CNT_MAX) begin
170+
next_state = HANDSHAKE;
164171
end else begin
165172
next_state = WFT;
166173
end
@@ -185,23 +192,26 @@ module acquisition_sync_cache_wr (
185192
// state machine output logic
186193
always @(posedge wr_clk or negedge rst_n) begin
187194
if (!rst_n) begin
188-
cache_cnt <= 8'd0;
195+
cache_cnt <= 16'd0;
189196
wr_en <= 1'b0;
190197
push_ready <= 1'b0;
191-
wfrd_cnt <= 8'd0;
198+
wfrd_cnt <= 16'd0;
199+
wft_cnt <= 16'd0;
192200
end else begin
193201
case (state)
194202
IDLE: begin
195203
// reset ready flag
196204
push_ready <= 1'b0;
197205
// reset
198-
cache_cnt <= 8'd0;
199-
wfrd_cnt <= 8'd0;
206+
cache_cnt <= 16'd0;
207+
wfrd_cnt <= 16'd0;
208+
wft_cnt <= 16'd0;
200209
wr_en <= 1'b0;
201210
end
202211
CACHING: begin
203212
push_ready <= 1'b0;
204-
wfrd_cnt <= 8'd0;
213+
wfrd_cnt <= 16'd0;
214+
wft_cnt <= 16'd0;
205215
// filling cache, and use cache_cnt as the cache filled metric
206216
if (acquisition_pulse) begin
207217
cache_cnt <= cache_cnt + 1'b1;
@@ -213,18 +223,21 @@ module acquisition_sync_cache_wr (
213223
end
214224
WFT: begin
215225
push_ready <= 1'b0;
216-
cache_cnt <= 8'd0;
217-
wfrd_cnt <= 8'd0;
226+
cache_cnt <= 16'd0;
227+
wfrd_cnt <= 16'd0;
218228
// just keep sampling, state machine will automatically go to WFRD when trigger is detected
219229
if (acquisition_pulse) begin
220-
wr_en <= 1'b1;
230+
wr_en <= 1'b1;
231+
wft_cnt <= wft_cnt + 1'b1;
221232
end else begin
222-
wr_en <= 1'b0;
233+
wr_en <= 1'b0;
234+
wft_cnt <= wft_cnt;
223235
end
224236
end
225237
WFRD: begin
226238
push_ready <= 1'b0;
227-
cache_cnt <= 8'd0;
239+
cache_cnt <= 16'd0;
240+
wft_cnt <= 16'd0;
228241
// keep sampling, and use wfrd_cnt as the cache filled metric
229242
if (acquisition_pulse) begin
230243
wr_en <= 1'b1;
@@ -238,8 +251,9 @@ module acquisition_sync_cache_wr (
238251
// enable ready flag
239252
push_ready <= 1'b1;
240253
// reset
241-
cache_cnt <= 8'd0;
242-
wfrd_cnt <= 8'd0;
254+
cache_cnt <= 16'd0;
255+
wfrd_cnt <= 16'd0;
256+
wft_cnt <= 16'd0;
243257
wr_en <= 1'b0;
244258
end
245259
endcase

0 commit comments

Comments
 (0)