@@ -57,14 +57,19 @@ module acquisition_sync_cache_wr (
57
57
parameter WFRD_CNT_MAX_75 = 191 ;
58
58
parameter WFRD_CNT_MAX_100 = 63 ;
59
59
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
+
60
63
// reg define
61
64
reg [4 :0 ] state;
62
65
reg [4 :0 ] next_state;
63
66
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;
65
71
66
- reg [7 :0 ] wfrd_cnt;
67
- reg [7 :0 ] wfrd_cnt_max;
72
+ reg [15 :0 ] wft_cnt;
68
73
69
74
reg trigger_enable;
70
75
@@ -148,7 +153,7 @@ module acquisition_sync_cache_wr (
148
153
end
149
154
end
150
155
CACHING: begin
151
- if (cache_cnt == 8'd255 ) begin
156
+ if (cache_cnt == BRAM_DEPTH ) begin
152
157
if (trigger_enable) begin
153
158
next_state = WFT;
154
159
end else begin
@@ -161,6 +166,8 @@ module acquisition_sync_cache_wr (
161
166
WFT: begin
162
167
if (triggered) begin
163
168
next_state = WFRD;
169
+ end else if (wft_cnt == WFT_CNT_MAX) begin
170
+ next_state = HANDSHAKE;
164
171
end else begin
165
172
next_state = WFT;
166
173
end
@@ -185,23 +192,26 @@ module acquisition_sync_cache_wr (
185
192
// state machine output logic
186
193
always @(posedge wr_clk or negedge rst_n) begin
187
194
if (! rst_n) begin
188
- cache_cnt <= 8 'd0 ;
195
+ cache_cnt <= 16 'd0 ;
189
196
wr_en <= 1'b0 ;
190
197
push_ready <= 1'b0 ;
191
- wfrd_cnt <= 8'd0 ;
198
+ wfrd_cnt <= 16'd0 ;
199
+ wft_cnt <= 16'd0 ;
192
200
end else begin
193
201
case (state)
194
202
IDLE: begin
195
203
// reset ready flag
196
204
push_ready <= 1'b0 ;
197
205
// 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 ;
200
209
wr_en <= 1'b0 ;
201
210
end
202
211
CACHING: begin
203
212
push_ready <= 1'b0 ;
204
- wfrd_cnt <= 8'd0 ;
213
+ wfrd_cnt <= 16'd0 ;
214
+ wft_cnt <= 16'd0 ;
205
215
// filling cache, and use cache_cnt as the cache filled metric
206
216
if (acquisition_pulse) begin
207
217
cache_cnt <= cache_cnt + 1'b1 ;
@@ -213,18 +223,21 @@ module acquisition_sync_cache_wr (
213
223
end
214
224
WFT: begin
215
225
push_ready <= 1'b0 ;
216
- cache_cnt <= 8 'd0 ;
217
- wfrd_cnt <= 8 'd0 ;
226
+ cache_cnt <= 16 'd0 ;
227
+ wfrd_cnt <= 16 'd0 ;
218
228
// just keep sampling, state machine will automatically go to WFRD when trigger is detected
219
229
if (acquisition_pulse) begin
220
- wr_en <= 1'b1 ;
230
+ wr_en <= 1'b1 ;
231
+ wft_cnt <= wft_cnt + 1'b1 ;
221
232
end else begin
222
- wr_en <= 1'b0 ;
233
+ wr_en <= 1'b0 ;
234
+ wft_cnt <= wft_cnt;
223
235
end
224
236
end
225
237
WFRD: begin
226
238
push_ready <= 1'b0 ;
227
- cache_cnt <= 8'd0 ;
239
+ cache_cnt <= 16'd0 ;
240
+ wft_cnt <= 16'd0 ;
228
241
// keep sampling, and use wfrd_cnt as the cache filled metric
229
242
if (acquisition_pulse) begin
230
243
wr_en <= 1'b1 ;
@@ -238,8 +251,9 @@ module acquisition_sync_cache_wr (
238
251
// enable ready flag
239
252
push_ready <= 1'b1 ;
240
253
// 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 ;
243
257
wr_en <= 1'b0 ;
244
258
end
245
259
endcase
0 commit comments