@@ -21,6 +21,7 @@ module tt_um_tt_tinyQV #(parameter CLOCK_MHZ=64) (
2121 localparam PERI_GPIO_OUT_SEL = 4'h3 ;
2222 localparam PERI_DEBUG_UART = 4'h6 ;
2323 localparam PERI_DEBUG_UART_STATUS = 4'h7 ;
24+ localparam PERI_TIME_LIMIT = 4'hB ;
2425 localparam PERI_DEBUG = 4'hC ;
2526 localparam PERI_USER = 4'hF ;
2627
@@ -85,6 +86,7 @@ module tt_um_tt_tinyQV #(parameter CLOCK_MHZ=64) (
8586 wire debug_uart_tx_start = write_n != 2'b11 && connect_peripheral == PERI_DEBUG_UART;
8687
8788 // Time
89+ reg [6 :2 ] time_limit;
8890 wire time_pulse;
8991
9092 // Peripherals interface
@@ -193,6 +195,7 @@ module tt_um_tt_tinyQV #(parameter CLOCK_MHZ=64) (
193195 case (connect_peripheral)
194196 PERI_GPIO_OUT_SEL:data_from_read = {24'h0 , gpio_out_sel, 6'h0 };
195197 PERI_DEBUG_UART_STATUS: data_from_read = {31'h0 , debug_uart_tx_busy};
198+ PERI_TIME_LIMIT: data_from_read = {25'h0 , time_limit, 2'b11 };
196199 PERI_USER: data_from_read = peri_data_out;
197200 default : data_from_read = 32'hFFFF_FFFF ;
198201 endcase
@@ -204,9 +207,11 @@ module tt_um_tt_tinyQV #(parameter CLOCK_MHZ=64) (
204207 always @(posedge clk) begin
205208 if (! rst_reg_n) begin
206209 gpio_out_sel <= {! ui_in[0 ], 1'b0 };
210+ time_limit <= (CLOCK_MHZ / 4 - 1 );
207211 end
208212 if (write_n != 2'b11 ) begin
209213 if (connect_peripheral == PERI_GPIO_OUT_SEL) gpio_out_sel <= data_to_write[7 :6 ];
214+ if (connect_peripheral == PERI_TIME_LIMIT) time_limit <= data_to_write[6 :2 ];
210215 end
211216 end
212217
@@ -219,29 +224,17 @@ module tt_um_tt_tinyQV #(parameter CLOCK_MHZ=64) (
219224 .uart_tx_busy(debug_uart_tx_busy)
220225 );
221226
222- reg [5 :0 ] time_count;
223-
224- generate
225- if (CLOCK_MHZ == 64 ) begin
226- always @(posedge clk) begin
227- if (! rst_reg_n) begin
228- time_count <= 0 ;
229- end else begin
230- time_count <= time_count + 1 ;
231- end
232- end
227+ reg [6 :0 ] time_count;
228+
229+ always @(posedge clk) begin
230+ if (! rst_reg_n) begin
231+ time_count <= 0 ;
233232 end else begin
234- always @(posedge clk) begin
235- if (! rst_reg_n) begin
236- time_count <= 0 ;
237- end else begin
238- if (time_count == (CLOCK_MHZ - 1 )) time_count <= 0 ;
239- else time_count <= time_count + 1 ;
240- end
241- end
233+ if (time_pulse) time_count <= 0 ;
234+ else time_count <= time_count + 1 ;
242235 end
243- endgenerate
244- assign time_pulse = time_count == (CLOCK_MHZ - 1 ) ;
236+ end
237+ assign time_pulse = time_count == {time_limit, 2'b11 } ;
245238
246239 // Debug
247240 always @(posedge clk) begin
0 commit comments