Skip to content

Commit 71cc596

Browse files
authored
Merge pull request #271 from SiLab-Bonn/stretch-tdc-input-signal
Stretch TDC input signal
2 parents eb81736 + 240563f commit 71cc596

4 files changed

Lines changed: 24 additions & 18 deletions

File tree

basil/firmware/modules/tdl_tdc/controller.v

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ module controller #(
2424
output reg [mux_bits-1:0] mux_addr
2525
);
2626

27-
2827
// 2 bit flag to store hit and miss information of the group of
2928
// samples. This needs to be in sync with the sample deser
3029
localparam TDL_IDLE = 0;
@@ -38,12 +37,6 @@ localparam SIG_IN = 1;
3837
localparam SIG_IN_B = 2;
3938
localparam CALIB_OSC = 3;
4039

41-
// function [state_bits-1:0] int_to_gray;
42-
// input [state_bits-1:0] int;
43-
// begin
44-
// int_to_gray = int ^ (int >> 1);
45-
// end
46-
// endfunction
4740
// TDC states
4841
// These need to be in sync with the word broker.
4942
localparam [state_bits-1:0] IDLE = 0;
@@ -70,9 +63,6 @@ wire hit;
7063
// still a solid 1 do we count a hit.
7164
assign hit = (hit_status == TDL_HIT) && tdl_status;
7265

73-
74-
75-
7666
always @(state, en_write_trigger_distance) begin
7767
// State dependent control outputs
7868
case(state)

basil/firmware/modules/tdl_tdc/sw_interface.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ graycode_2stage_cdc #(.DATA_WIDTH(32)) event_count_cdc (
213213
.data_out_clk(event_cnt)
214214
);
215215

216-
// This is a strange additional buffer from the original tdc_s3 (L:420).
216+
// Buffer upper bits of counter to preserve while reading in blocks of 1 byte (width of bus data)
217217
always @(posedge BUS_CLK) begin
218218
event_cnt_buf <= event_cnt;
219219
if (ip_add == 2 && ip_rd)

basil/firmware/modules/tdl_tdc/tdl_tdc.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ always @(posedge CLK160) begin
118118
fifo_over_cnt <= fifo_over_cnt;
119119
end
120120

121-
gerneric_fifo #(
121+
generic_fifo #(
122122
.DATA_SIZE(32),
123123
.DEPTH(512)
124124
) fifo_i (

basil/firmware/modules/tdl_tdc/tdl_tdc_core.v

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ module tdc_core #(
3838
output wire [31:0] event_cnt
3939
);
4040

41-
42-
4341
localparam dlyline_bits = 96; // TODO: should this be a localparam?
4442
localparam clk_ratio = 3;
4543
// The following numbers of bits should add up to 33, as the bus is 32 bit and
@@ -50,9 +48,7 @@ localparam fine_time_bits = 2; // We need that clk_ratio <= 2^fine_time_bits
5048
localparam state_bits = 4;
5149
localparam word_type_bits = 3; // TODO: this isn't yet parametric
5250

53-
54-
55-
// corse counter.
51+
// Coarse counter
5652
wire [corsebits-1:0] corse_count;
5753
wire counter_count, counter_reset;
5854
// TODO: should clip_reset be set?
@@ -81,6 +77,26 @@ clock_divider #(.DIVISOR(14)) calib_sig_gen (
8177
.CLOCK(sig_calib)
8278
);
8379

80+
// Stretch trig_in to make sure we do not miss very short pulses (such as scintillator)
81+
reg [1:0] cnt;
82+
reg trig_in_delayed;
83+
always @(posedge trig_in or posedge CLK or posedge rst) begin
84+
if (rst) begin
85+
trig_in_delayed <= 0;
86+
cnt <= 0;
87+
end
88+
else if (trig_in) begin // asynchronous trigger in
89+
trig_in_delayed <= 1'b1;
90+
cnt <= 2'd2;
91+
end
92+
else begin // synchronous trigger out
93+
if (cnt != 0)
94+
cnt <= cnt - 1;
95+
96+
if (cnt == 1)
97+
trig_in_delayed <= 0;
98+
end
99+
end
84100

85101
// Input mux addresses for more verbose code
86102
// For 4 inputs, 2 bits are sufficient
@@ -103,7 +119,7 @@ always @ (posedge CLK)
103119
input_mux_addr_buf <= input_mux_addr;
104120
always @(*) begin
105121
case(input_mux_addr_buf)
106-
TRIG_IN: tdl_input <= trig_in;
122+
TRIG_IN: tdl_input <= trig_in_delayed;
107123
SIG_IN: tdl_input <= sig_in;
108124
SIG_IN_B: tdl_input <= ~sig_in;
109125
CALIB_OSC: tdl_input <= sig_calib;

0 commit comments

Comments
 (0)