DL-TDC: Difference between revisions

From DaqWiki
Jump to navigation Jump to search
 
(44 intermediate revisions by the same user not shown)
Line 1: Line 1:
= DL-TDC DarkLight FPGA TDC =
= DL-TDC DarkLight FPGA TDC =


= Cyclone-1 =
= ODB settings =


* dl_enable - yes/no - enable or disable TDC readout in the midas frontend
* dl_ctrl - 32 bits of general control
<pre>
<pre>
report_path -to [get_keepers {TDC6:tdc|TDC2ef:a|TDC2e:tdc|TDC1:le|TDClcell40:phase|TDClcell10:d|latch[9]}] -npaths 1 -panel_name {Report Path}
bit - quartus - description
  0 - dl_ctrl_gate  - jam TDC gate open, enable un-triggered free-running mode
  1 - dl_ctrl_gate_A - gate TDC from A-side trigger
  2 - dl_ctrl_gate_B - gate TDC from B-side trigger
  3 - dl_ctrl_gate_AB - gate TDC from A*B
  4 - dl_ctrl_gate_T - gate TDC from T trigger (T = A*B)
  5 - dl_ctrl_ena_A - enable TDC channel 32 (A)
  6 - dl_ctrl_ena_B - enable TDC channel 33 (B)
  7 - dl_ctrl_ena_T - enable TDC channel 34 (T)
15..8 - dl_ctrl_gate_w - TDC gate width in units of 8 ns
31..16 - not used
</pre>
</pre>
* dl_trg_mask - 16 bits of trigger mask
<pre>
bit - description
  0 - enable A pair 1-9
  1 - enable A pair 2-10
  2 - enable A pair 3-11
  3 - enable A pair 4-12
  4
  5
  6
  7
  8 - enable B pair 5-13
  9 - enable B pair 6-14
10 - enable B pair 7-15
11 - enable B pair 8-16
</pre>
* dl_tdc_mask - 32 bits to enable 32 TDC channels, in sequence
= Channel map =
<pre>
// map TDC cable to SiPM channels
 
  assign ch[1]  = tdc[0];
  assign ch[2]  = tdc[1];
  assign ch[3]  = tdc[10];
  assign ch[4]  = tdc[11];
  assign ch[5]  = tdc[2];
  assign ch[6]  = tdc[3];
  assign ch[7]  = tdc[8];
  assign ch[8]  = tdc[9];
  assign ch[9]  = tdc[15];
  assign ch[10] = tdc[14];
  assign ch[11] = tdc[7];
  assign ch[12] = tdc[6];
  assign ch[13] = tdc[13];
  assign ch[14] = tdc[12];
  assign ch[15] = tdc[5];
  assign ch[16] = tdc[4];
  assign ch[16+1]  = tdc[16+0];  // 16
  assign ch[16+2]  = tdc[16+1];  // 17
  assign ch[16+3]  = tdc[16+10]; // 26
  assign ch[16+4]  = tdc[16+11]; // 27
  assign ch[16+5]  = tdc[16+2];  // 18
  assign ch[16+6]  = tdc[16+3];  // 19
  assign ch[16+7]  = tdc[16+8];  // 24
  assign ch[16+8]  = tdc[16+9];  // 25
  assign ch[16+9]  = tdc[16+15]; // 31
  assign ch[16+10] = tdc[16+14]; // 30
  assign ch[16+11] = tdc[16+7];  // 23
  assign ch[16+12] = tdc[16+6];  // 22
  assign ch[16+13] = tdc[16+13]; // 29
  assign ch[16+14] = tdc[16+12]; // 28
  assign ch[16+15] = tdc[16+5];  // 21
  assign ch[16+16] = tdc[16+4];  // 20
  // compute SiPM pair concindences
 
  assign A[0] = ch[1] & ch[9]  & enable_input[0]; //  0 * 15 -> pair1
  assign A[1] = ch[2] & ch[10] & enable_input[1]; //  1 * 14 -> pair2
  assign A[2] = ch[3] & ch[11] & enable_input[2]; // 10 *  7 -> pair3
  assign A[3] = ch[4] & ch[12] & enable_input[3]; // 11 *  6 -> pair4
  assign A[4] = ch[5] & ch[13] & enable_input[4];
  assign A[5] = ch[6] & ch[14] & enable_input[5];
  assign A[6] = ch[7] & ch[15] & enable_input[6];
  assign A[7] = ch[8] & ch[16] & enable_input[7];
  assign B[0] = ch[16+1] & ch[16+9]  & enable_input[8];  // 16 * 31
  assign B[1] = ch[16+2] & ch[16+10] & enable_input[9];  // 17 * 30
  assign B[2] = ch[16+3] & ch[16+11] & enable_input[10]; // 26 * 23
  assign B[3] = ch[16+4] & ch[16+12] & enable_input[11]; // 27 * 22
  assign B[4] = ch[16+5] & ch[16+13] & enable_input[12]; // 18 * 29 -> pair5
  assign B[5] = ch[16+6] & ch[16+14] & enable_input[13]; // 19 * 28 -> pair6
  assign B[6] = ch[16+7] & ch[16+15] & enable_input[14]; // 24 * 21 -> pair7
  assign B[7] = ch[16+8] & ch[16+16] & enable_input[15]; // 25 * 20 -> pair8


  wire        A_or = |A;
  wire        B_or = |B;
  //wire        A_or = A[0] | A{1] | A{2] | A[3] | A[4] | A{5] | A{6] | A[7];
  //wire        B_or = B[0] | B{1] | B{2] | B[3] | B[4] | B{5] | B{6] | B[7];
  wire        AB_and = A_or & B_or;
</pre>
= D3 delay tuning =
* quartus report "DL trigger GPIO to dlA", "to dlB" and "through dlT"
* delay values are set in quartus assignements file. Delay values go from 0 to 7 in increments of about 0.5 ns.
<pre>
<pre>
tdc6g.pdf
dsdaqgw:chronobox_firmware$ grep D3_DELAY *.qsf
min bin: 0.003 0.108 0.047 0.086 ns, max bin: 0.769 0.845 0.700 0.709 ns, max phase 31 30 32 30
DE10_NANO_SoC_GHRD.qsf:set_instance_assignment -name D3_DELAY 5 -to GPIO_1_21
min bin: 0.167 0.091 0.058 0.099 ns, max bin: 0.821 0.935 0.636 0.729 ns, max phase 29 25 31 29
</pre>
</pre>


<pre>
<pre>
tdc6h.pdf
9.109 GPIO_1_20 dl|WideOr0|combout -> 1
min bin: 0.021 0.090 0.130 0.076 ns, max bin: 0.863 0.868 0.731 0.686 ns, max phase 33 32 33 32
9.025 GPIO_1_33 dl|WideOr0|combout -> 1
min bin: 0.079 0.069 0.021 0.119 ns, max bin: 0.812 0.871 0.818 0.845 ns, max phase 33 32 31 30
9.022 GPIO_1_26 dl|WideOr0|combout -> 0
8.966 GPIO_1_28 dl|WideOr0|combout -> 5            = 8.494 add 1
8.787 GPIO_1_22 dl|WideOr0|combout -> 0
8.714 GPIO_1_21 dl|WideOr0|combout -> 5
8.711 GPIO_1_34 dl|WideOr0|combout -> 0
8.597 GPIO_1_30 dl|WideOr0|combout -> 0           = 8.240 add 1 -> 1 = 9.733 sub 1
8.590 GPIO_1_29 dl|WideOr0|combout -> 1 add 1 -> 2 = 9.588 sub 1
8.506 GPIO_1_27 dl|WideOr0|combout -> 4 add 1 --------------------> 5 = 10.097 sub 1
8.453 GPIO_1_24 dl|WideOr0|combout -> 2 add 1 -> 3 = 9.588 sub 1
8.412 GPIO_1_35 dl|WideOr0|combout add 1
8.380 GPIO_1_31 dl|WideOr0|combout -> 4 add 1 -> 5 = 9.208 sub 1
8.312 GPIO_1_25 dl|WideOr0|combout -> 1 add 1 -> 2 = 8.555 add 1 -> 3 = 9.379
7.992 GPIO_1_32 dl|WideOr0|combout add 2
7.248 GPIO_1_23 dl|WideOr0|combout -> 2 add 3 -> 5 = 9.425 sub 1
</pre>
</pre>


<pre>
<pre>
with set_max_delay -to {TDC6:tdc|TDC2ef:*|TDC2e:tdc|TDC1:*|TDClcell40:phase|TDClcell10:d|latch[9]} 10.0
9.339 GPIO_0_14 dl|WideOr1|combout -> 6 sub 1 -> 5 = 8.587
13.237 ns
9.207 GPIO_0_2 dl|WideOr1|combout -> 7 sub 1 -> 6 = 8.360 add 1
13.237 13.237 data path 1
9.174 GPIO_0_10 dl|WideOr1|combout -> 6
0.000   0.000 1 LC_X3_Y17_N0 TS_DFF[0] 1
9.161 GPIO_0_6 dl|WideOr1|combout -> 7
0.000   0.000 RR CELL 10 LC_X3_Y17_N0 TS_DFF[0]|regout 2
9.105 GPIO_0_11 dl|WideOr1|combout -> 7
1.285   1.285 RR IC 2 LC_X8_Y13_N0 tdc|a|tdc|le|phase|a|latch[0]|datad 3
9.019 GPIO_0_7 dl|WideOr1|combout -> 7
1.373   0.088 RR CELL 1 LC_X8_Y13_N0 tdc|a|tdc|le|phase|a|latch[0]|combout 4
8.731 GPIO_0_15 dl|WideOr1|combout add 0 -> 0 = 8.540 add 1
1.513   0.140 RR IC 2 LC_X8_Y13_N1 tdc|a|tdc|le|phase|a|latch[1]|datad 5
8.462 GPIO_0_12 dl|WideOr1|combout add 1 -> 1 = 9.189
1.601   0.088 RR CELL 1 LC_X8_Y13_N1 tdc|a|tdc|le|phase|a|latch[1]|combout 6
8.256 GPIO_0_4 dl|WideOr1|combout add 2 -> 2 = 9.750 sub 1
1.741   0.140 RR IC 2 LC_X8_Y13_N2 tdc|a|tdc|le|phase|a|latch[2]|datad 7
8.214 GPIO_0_5 dl|WideOr1|combout add 2
1.829   0.088 RR CELL 1 LC_X8_Y13_N2 tdc|a|tdc|le|phase|a|latch[2]|combout 8
8.182 GPIO_0_1 dl|WideOr1|combout add 2
1.969   0.140 RR IC 2 LC_X8_Y13_N3 tdc|a|tdc|le|phase|a|latch[3]|datad 9
7.328 GPIO_0_3 dl|WideOr1|combout add 3
2.057   0.088 RR CELL 1 LC_X8_Y13_N3 tdc|a|tdc|le|phase|a|latch[3]|combout 10
6.584 GPIO_0_8 dl|WideOr1|combout add 5
2.197   0.140 RR IC 2 LC_X8_Y13_N4 tdc|a|tdc|le|phase|a|latch[4]|datad 11
6.409 GPIO_0_13 dl|WideOr1|combout add 5 -> 5 =  9.943 sub 2
2.285   0.088 RR CELL 1 LC_X8_Y13_N4 tdc|a|tdc|le|phase|a|latch[4]|combout 12
6.009 GPIO_0_9 dl|WideOr1|combout add 6 -> 6 = 10.189 sub 2
2.547   0.262 RR IC 2 LC_X8_Y13_N5 tdc|a|tdc|le|phase|a|latch[5]|datad 13
5.917 GPIO_0_0 dl|WideOr1|combout add 6
2.635   0.088 RR CELL 1 LC_X8_Y13_N5 tdc|a|tdc|le|phase|a|latch[5]|combout 14
</pre>
2.775   0.140 RR IC 2 LC_X8_Y13_N6 tdc|a|tdc|le|phase|a|latch[6]|datad 15
 
2.863   0.088 RR CELL 1 LC_X8_Y13_N6 tdc|a|tdc|le|phase|a|latch[6]|combout 16
= Theory of operation =
3.003   0.140 RR IC 2 LC_X8_Y13_N7 tdc|a|tdc|le|phase|a|latch[7]|datad 17
3.091   0.088 RR CELL 1 LC_X8_Y13_N7 tdc|a|tdc|le|phase|a|latch[7]|combout 18
3.231   0.140 RR IC 2 LC_X8_Y13_N8 tdc|a|tdc|le|phase|a|latch[8]|datad 19
3.319   0.088 RR CELL 1 LC_X8_Y13_N8 tdc|a|tdc|le|phase|a|latch[8]|combout 20
3.459   0.140 RR IC 2 LC_X8_Y13_N9 tdc|a|tdc|le|phase|a|latch[9]|datad 21
3.547   0.088 RR CELL 1 LC_X8_Y13_N9 tdc|a|tdc|le|phase|a|latch[9]|combout 22
4.074   0.527 RR IC 2 LC_X9_Y13_N1 tdc|a|tdc|le|phase|b|latch[0]|datad 23
4.162   0.088 RR CELL 1 LC_X9_Y13_N1 tdc|a|tdc|le|phase|b|latch[0]|combout 24
4.302   0.140 RR IC 2 LC_X9_Y13_N2 tdc|a|tdc|le|phase|b|latch[1]|datad 25
4.390   0.088 RR CELL 1 LC_X9_Y13_N2 tdc|a|tdc|le|phase|b|latch[1]|combout 26
4.530   0.140 RR IC 2 LC_X9_Y13_N3 tdc|a|tdc|le|phase|b|latch[2]|datad 27
4.618   0.088 RR CELL 1 LC_X9_Y13_N3 tdc|a|tdc|le|phase|b|latch[2]|combout 28
4.758   0.140 RR IC 2 LC_X9_Y13_N4 tdc|a|tdc|le|phase|b|latch[3]|datad 29
4.846   0.088 RR CELL 1 LC_X9_Y13_N4 tdc|a|tdc|le|phase|b|latch[3]|combout 30
5.108   0.262 RR IC 2 LC_X9_Y13_N5 tdc|a|tdc|le|phase|b|latch[4]|datad 31
5.196   0.088 RR CELL 1 LC_X9_Y13_N5 tdc|a|tdc|le|phase|b|latch[4]|combout 32
5.336   0.140 RR IC 2 LC_X9_Y13_N6 tdc|a|tdc|le|phase|b|latch[5]|datad 33
5.424   0.088 RR CELL 1 LC_X9_Y13_N6 tdc|a|tdc|le|phase|b|latch[5]|combout 34
5.564   0.140 RR IC 2 LC_X9_Y13_N7 tdc|a|tdc|le|phase|b|latch[6]|datad 35
5.652   0.088 RR CELL 1 LC_X9_Y13_N7 tdc|a|tdc|le|phase|b|latch[6]|combout 36
5.792   0.140 RR IC 2 LC_X9_Y13_N8 tdc|a|tdc|le|phase|b|latch[7]|datad 37
5.880   0.088 RR CELL 1 LC_X9_Y13_N8 tdc|a|tdc|le|phase|b|latch[7]|combout 38
6.218   0.338 RR IC 2 LC_X9_Y13_N0 tdc|a|tdc|le|phase|b|latch[8]|datac 39
6.443   0.225 RR CELL 1 LC_X9_Y13_N0 tdc|a|tdc|le|phase|b|latch[8]|combout 40
6.762   0.319 RR IC 2 LC_X9_Y13_N9 tdc|a|tdc|le|phase|b|latch[9]|datad 41
6.850   0.088 RR CELL 1 LC_X9_Y13_N9 tdc|a|tdc|le|phase|b|latch[9]|combout 42
7.767   0.917 RR IC 2 LC_X8_Y14_N0 tdc|a|tdc|le|phase|c|latch[0]|datad 43
7.855   0.088 RR CELL 1 LC_X8_Y14_N0 tdc|a|tdc|le|phase|c|latch[0]|combout 44
7.995   0.140 RR IC 2 LC_X8_Y14_N1 tdc|a|tdc|le|phase|c|latch[1]|datad 45
8.083   0.088 RR CELL 1 LC_X8_Y14_N1 tdc|a|tdc|le|phase|c|latch[1]|combout 46
8.223   0.140 RR IC 2 LC_X8_Y14_N2 tdc|a|tdc|le|phase|c|latch[2]|datad 47
8.311   0.088 RR CELL 1 LC_X8_Y14_N2 tdc|a|tdc|le|phase|c|latch[2]|combout 48
8.451   0.140 RR IC 2 LC_X8_Y14_N3 tdc|a|tdc|le|phase|c|latch[3]|datad 49
8.539   0.088 RR CELL 1 LC_X8_Y14_N3 tdc|a|tdc|le|phase|c|latch[3]|combout 50
8.679   0.140 RR IC 2 LC_X8_Y14_N4 tdc|a|tdc|le|phase|c|latch[4]|datad 51
8.767   0.088 RR CELL 1 LC_X8_Y14_N4 tdc|a|tdc|le|phase|c|latch[4]|combout 52
9.029   0.262 RR IC 2 LC_X8_Y14_N5 tdc|a|tdc|le|phase|c|latch[5]|datad 53
9.117   0.088 RR CELL 1 LC_X8_Y14_N5 tdc|a|tdc|le|phase|c|latch[5]|combout 54
9.257   0.140 RR IC 2 LC_X8_Y14_N6 tdc|a|tdc|le|phase|c|latch[6]|datad 55
9.345   0.088 RR CELL 1 LC_X8_Y14_N6 tdc|a|tdc|le|phase|c|latch[6]|combout 56
9.485   0.140 RR IC 2 LC_X8_Y14_N7 tdc|a|tdc|le|phase|c|latch[7]|datad 57
9.573   0.088 RR CELL 1 LC_X8_Y14_N7 tdc|a|tdc|le|phase|c|latch[7]|combout 58
9.713   0.140 RR IC 2 LC_X8_Y14_N8 tdc|a|tdc|le|phase|c|latch[8]|datad 59
9.801   0.088 RR CELL 1 LC_X8_Y14_N8 tdc|a|tdc|le|phase|c|latch[8]|combout 60
9.941   0.140 RR IC 2 LC_X8_Y14_N9 tdc|a|tdc|le|phase|c|latch[9]|datad 61
10.029   0.088 RR CELL 1 LC_X8_Y14_N9 tdc|a|tdc|le|phase|c|latch[9]|combout 62
10.551   0.522 RR IC 2 LC_X9_Y14_N0 tdc|a|tdc|le|phase|d|latch[0]|datad 63
10.639   0.088 RR CELL 1 LC_X9_Y14_N0 tdc|a|tdc|le|phase|d|latch[0]|combout 64
10.779   0.140 RR IC 2 LC_X9_Y14_N1 tdc|a|tdc|le|phase|d|latch[1]|datad 65
10.867   0.088 RR CELL 1 LC_X9_Y14_N1 tdc|a|tdc|le|phase|d|latch[1]|combout 66
11.007   0.140 RR IC 2 LC_X9_Y14_N2 tdc|a|tdc|le|phase|d|latch[2]|datad 67
11.095   0.088 RR CELL 1 LC_X9_Y14_N2 tdc|a|tdc|le|phase|d|latch[2]|combout 68
11.235   0.140 RR IC 2 LC_X9_Y14_N3 tdc|a|tdc|le|phase|d|latch[3]|datad 69
11.323   0.088 RR CELL 1 LC_X9_Y14_N3 tdc|a|tdc|le|phase|d|latch[3]|combout 70
11.463   0.140 RR IC 2 LC_X9_Y14_N4 tdc|a|tdc|le|phase|d|latch[4]|datad 71
11.551   0.088 RR CELL 1 LC_X9_Y14_N4 tdc|a|tdc|le|phase|d|latch[4]|combout 72
11.813   0.262 RR IC 2 LC_X9_Y14_N5 tdc|a|tdc|le|phase|d|latch[5]|datad 73
11.901   0.088 RR CELL 1 LC_X9_Y14_N5 tdc|a|tdc|le|phase|d|latch[5]|combout 74
12.041   0.140 RR IC 2 LC_X9_Y14_N6 tdc|a|tdc|le|phase|d|latch[6]|datad 75
12.129   0.088 RR CELL 1 LC_X9_Y14_N6 tdc|a|tdc|le|phase|d|latch[6]|combout 76
12.269   0.140 RR IC 2 LC_X9_Y14_N7 tdc|a|tdc|le|phase|d|latch[7]|datad 77
12.357   0.088 RR CELL 1 LC_X9_Y14_N7 tdc|a|tdc|le|phase|d|latch[7]|combout 78
12.497   0.140 RR IC 2 LC_X9_Y14_N8 tdc|a|tdc|le|phase|d|latch[8]|datad 79
12.585   0.088 RR CELL 1 LC_X9_Y14_N8 tdc|a|tdc|le|phase|d|latch[8]|combout 80
12.725   0.140 RR IC 1 LC_X9_Y14_N9 tdc|a|tdc|le|phase|d|latch[9]|datad 81
12.813   0.088 RR CELL 1 LC_X9_Y14_N9 tdc|a|tdc|le|phase|d|latch[9]|combout 82
13.148   0.335 RR IC 1 LC_X9_Y14_N9 tdc|a|tdc|le|phase|d|latch[9]|datac 83
13.237   0.089 RR CELL 1 LC_X9_Y14_N9 TDC6:tdc|TDC2ef:a|TDC2e:tdc|TDC1:le|TDClcell40:phase|TDClcell10:d|latch[9] 84


minimal time bin: 140+88 = 228 ps
== Why FPGA TDC? ==
10.0 ns period / 0.228 ps = 43.9 bins


tdc6i.pdf
* combine trigger logic, hit recording and time measurement in one device
min bin: 0.065 0.038 0.062 0.040 ns, max bin: 1.000 0.840 0.681 0.913 ns, max phase 39 39 39 39
* avoid having to split signals to FPGA trigger and to external TDC and to coordinate clocks and timestamps between them
min bin: 0.062 0.035 0.075 0.029 ns, max bin: 0.895 1.042 0.800 0.997 ns, max phase 39 39 39 39
* ability to construct custom TDC with data paths tuned to experiment requirements, i.e. ultra high data rates. this avoids the well known problem with the CERN TDC ASIC (V1190) where high rate on one channel will cause data loss on other channels.
min bin: 0.063 0.036 0.027 0.033 ns, max bin: 0.918 0.985 0.596 0.933 ns, max phase 39 39 39 39
* ability to get the data out at FPGA speeds, not limited to VME, USB or Ethernet speeds.
* ability to "right-size" the TDC. ASIC TDCs come in fixed increments: 96 channels (Lecroy Fastbus TDC), 64 or 128 channels (CAEN V1190 VME TDC), 64 channels (PicoTDC), overkill of fewer channels are actually needed. Compared to FPGA TDC where size (cost) of FPGA can be selected according to need and where FPGAs of different sizes often are available as interchangeable plug-in modules.
 
Downsides:
 
* ASIC TDC design can control internal timing much better than an FPGA TDC. as result per-time-bin and per-channel variations can be made much smaller.
* ASIC TDC can run at much higher clock frequencies and have much smaller time bins.
* ASIC TDC may have internal temperature compensation functions in order to avoid temperature drift of TDC calibration.
 
== Types of FPGA TDC ==
 
FPGA TDC come in two basic types: based on delay lines and based on the Vernier method. Delay line TDC resolution is limited to size and number of delay line elements. Vernier TDCs requires precise clock generators (usually not available on standard FPGA devices). Delay line TDCs have several designs. Delay line captures phase of input signal relative to the clock. Delay line captures phase of the clock relative to the input signal. Delay line encoder looks for 1 edge transition, or looks for many edge transitions ("wavelet TDC").
 
== Delay line FPGA TDC building blocks ==
 
* signal capture and clock synchronizer - asynchronous input signal is latched and synchronized to the TDC clock. Per-hit dead time (LE to next pulse), minimum pulse width requirement (LE to TE), minimum time double-pulse resolution (TE to next LE) are created here.
* tdc clock counter - latched and synchronized input signal records the hit coarse time (10 ns time bin)
* delay line - tdc clock (50 MHz/20 ns) waveform travels throught the 60-element delay line (~25 ns) total delay), latched input signal captures this waveform in the phase latch register (60 bits). Typical bit pattern: "00...000111...11100..000"
* "temperature encoder" - looks for the position of the first 0->1 or 1->0 transition and converts it into a time bin number 1..60 (for 0->1 transitions) and -1..-60 (for 1->0 transitions). This clock phase time bin number corresponds to the TDC fine time. After calibration that accounts for individual delay of each time bin.
* per-channel input buffer - 64 hits per channel for LE and TE (32 LE+TE hits), to handle bursts of hits
* main multiplexor - data from 32+3 TDC channels is funneled into 1 output stream
* main data FIFO - "the bigger, the better" data buffer to hold the data before it is transmitted out of the TDC
* data transmitter - DL-TDC uses a MIDAS frontend to read the main data FIFO via a 64-bit AXI bus, package data as MIDAS events and send them to the main computer via the Cyclone-5 SoC 1gige ethernet (data rate about 50 Mbytes/sec; at 8+8 bytes per TDC hit (LE+TE), about 3 Mhits/sec, sustained).
 
== Implementation details ==
 
* delay line element: use LCELL or cyclonev_lcell_comb (TDClcellff.sv), quartus fitter does not care which, does it's own thing regarding which LCELL input ports to use. Input "F" must be used for best timing (shortest delay): LUT mask: F0 = vcc 0xFFFF, F1 = vcc 0xFFFF, F2 = gnd 0x0000, F3 = gnd 0x0000, Combout equation: LCELL(F), [[Image:TDC_LCELL.pdf|150px|Cyclone-V logic cell]]
* delay line: in theory, 20 delay line elements can be packed in a 10-ALM block. In practice, to ensure routing uses LCELL input "F", TDC uses 8 delay elements per 10-ALM block. (quartus uses the "leftover" ALMs to implement the encoder and other logic). Typical timing reported by quartus is 0.087 ns transmit time through combinatorial logic from input F to COMBOUT output, 0.250 ns transit time to the next delay element inthe same 10-ALM block, 0.800 ns transmit time to the first delay element of the next 10-ALM block. [[Image:TDC_DELAY_CHAIN1.pdf|150px|one block of TDC delay chain]] and [[Image:TDC_DELAY_CHAIN2.pdf|150px|complete TDC delay chain]]
* timing of TDC delay chain for each TDC channel is shown in "Report DL-TDC-NN-{LE,TE}", use "Locate path" to "Locate path in chip planner", them zoom in and click in logic elements to examine the physical layout. Use "show routing" to see more detail of connection between logic elements.
* layout of the 60-element TDC delay line is done manually using quartus qsf file dltdc.qsf. This file is generated by a perl script (dltdc_qsf.perl). Location of each TDC channel is selected manually and must be adjusted to have them close to the FPGA input pins and to spread things around to avoid FPGA resource congestion.
<pre>
set_location_assignment LABCELL_X11_Y10_N6 -to "TDCn:tdcs|TDC2ef:tdc[17].tdc|TDC2e:tdc|TDC1:le|TDClcellN:phase|TDClcellff:e[0].c|lcell"
set_location_assignment FF_X11_Y10_N7 -to "TDCn:tdcs|TDC2ef:tdc[17].tdc|TDC2e:tdc|TDC1:le|TDClcellN:phase|TDClcellff:e[0].c|ff1"
set_location_assignment LABCELL_X11_Y10_N12 -to "TDCn:tdcs|TDC2ef:tdc[17].tdc|TDC2e:tdc|TDC1:le|TDClcellN:phase|TDClcellff:e[1].c|lcell"
set_location_assignment FF_X11_Y10_N13 -to "TDCn:tdcs|TDC2ef:tdc[17].tdc|TDC2e:tdc|TDC1:le|TDClcellN:phase|TDClcellff:e[1].c|ff1"
</pre>
</pre>
* Cyclone-V SoC FPGA on the DE-10 evaluation board comfortably fits 32+3 TDC channels with room to spare: [[Image:TDC_LAYOUT.pdf|150px|TDC layout]] (each TDC channel is shown in a different colour, explosion at the paint factory)


<pre>
== TDC calibration ==
without set_max_delay
 
19.341
* the DL-TDC design uses the delay line for the clock and the latched hit signal to capture the clock phase. if TDC hits are uncorrelated with the TDC clock (i.e. cosmic rays or calibration pulser running from a different clock oscillator), we can assume a uniform distribution of TDC fine time (0 to 10 ns) and use the TDC fine time bin distribution to compute actual TDC delay line bin size and construct the mapping from TDC fine time bin (1..60) to TDC fine time (0..10 ns).
19.341 19.341 data path 1
* calibration pulser run 286, TDC firmware 0x66dbbf18
0.000   0.000 1 LC_X14_Y20_N0 TS_DFF[0] 1
* channel tdc00-LE fine time bin occupancy distribution: [[Image:TDC_TIME_BIN_OCCUPANCY.pdf|150px|TDC fine time bin occupancy]]
0.000   0.000 RR CELL 10 LC_X14_Y20_N0 TS_DFF[0]|regout 2
* fine time bin size (actual bin size is smaller than bin size computed by quartus because quartus must assume the worst possible FPGA timing): [[Image:TDC_TIME_BIN_SIZE.pdf|150px|TDC fine time bin occupancy]]
1.339   1.339 RR IC 2 LC_X13_Y15_N4 tdc|a|tdc|le|phase|a|latch[0]|datad 3
* typical TDC delay line size is 45-50 bins (out of 60 available), average time bins size 0.200..0.222 ns, actual computed typical bin size 0.180 ps (or so) with 5 or 6 extra-wide bins that correspond to TDC delay line transit from one block of logic elements to the next block of logic elements.
1.427   0.088 RR CELL 1 LC_X13_Y15_N4 tdc|a|tdc|le|phase|a|latch[0]|combout 4
* for each run the fine time distribution is computed, if distortion from uniform 0..10 ns becomes too big, fine time calibration must be redone. [[Image:TDC_FINE_TIME.pdf|150px|TDC fine time distribution]]
1.763   0.336 RR IC 2 LC_X13_Y15_N9 tdc|a|tdc|le|phase|a|latch[1]|datac 5
* in addition to TDC delay line calibration, the TDC per-channel input delays must be calibrated. this is done by sending a common signal to all TDC inputs: [[Image:TDC_PULSER_LE.pdf|150px|TDC calibration pulser LE]]
1.988   0.225 RR CELL 1 LC_X13_Y15_N9 tdc|a|tdc|le|phase|a|latch[1]|combout 6
 
2.324   0.336 RR IC 2 LC_X13_Y15_N2 tdc|a|tdc|le|phase|a|latch[2]|datac 7
== Future improvement 1 ==
2.549   0.225 RR CELL 1 LC_X13_Y15_N2 tdc|a|tdc|le|phase|a|latch[2]|combout 8
 
2.689   0.140 RR IC 2 LC_X13_Y15_N3 tdc|a|tdc|le|phase|a|latch[3]|datad 9
FPGA TDCs that use LCELL delay lines are unusual. Most FPGA TDCs reported on the literature use CARRY-chain delay lines.
2.777   0.088 RR CELL 1 LC_X13_Y15_N3 tdc|a|tdc|le|phase|a|latch[3]|combout 10
 
3.097   0.320 RR IC 2 LC_X13_Y15_N5 tdc|a|tdc|le|phase|a|latch[4]|datad 11
Typical LCELL delay is 0.200 ns, typical CARRY delay is .050 ns (even for very old Cyclone-I FPGAs) and TDCs with much higher nominal resolution can be built.
3.185   0.088 RR CELL 1 LC_X13_Y15_N5 tdc|a|tdc|le|phase|a|latch[4]|combout 12
 
3.325   0.140 RR IC 2 LC_X13_Y15_N6 tdc|a|tdc|le|phase|a|latch[5]|datad 13
The trade-off between the two designs is the interplay between length of the delay line and frequency of the TDC fine clock. Slow clock and very fast delay line result in a very long delay line. Very long delay lines require edge ("temperature") encoders that use too many logic elements and this limits the number of channels that can be implemented in an FPGA of given size.
3.413   0.088 RR CELL 1 LC_X13_Y15_N6 tdc|a|tdc|le|phase|a|latch[5]|combout 14
4.355   0.942 RR IC 2 LC_X13_Y16_N9 tdc|a|tdc|le|phase|a|latch[6]|datac 15
4.580   0.225 RR CELL 1 LC_X13_Y16_N9 tdc|a|tdc|le|phase|a|latch[6]|combout 16
4.919   0.339 RR IC 2 LC_X13_Y16_N6 tdc|a|tdc|le|phase|a|latch[7]|datac 17
5.144   0.225 RR CELL 1 LC_X13_Y16_N6 tdc|a|tdc|le|phase|a|latch[7]|combout 18
5.470   0.326 RR IC 2 LC_X13_Y16_N0 tdc|a|tdc|le|phase|a|latch[8]|datad 19
5.558   0.088 RR CELL 1 LC_X13_Y16_N0 tdc|a|tdc|le|phase|a|latch[8]|combout 20
5.887   0.329 RR IC 2 LC_X13_Y16_N8 tdc|a|tdc|le|phase|a|latch[9]|datad 21
5.975   0.088 RR CELL 1 LC_X13_Y16_N8 tdc|a|tdc|le|phase|a|latch[9]|combout 22
6.314   0.339 RR IC 2 LC_X13_Y16_N7 tdc|a|tdc|le|phase|b|latch[0]|datac 23
6.539   0.225 RR CELL 1 LC_X13_Y16_N7 tdc|a|tdc|le|phase|b|latch[0]|combout 24
6.879   0.340 RR IC 2 LC_X13_Y16_N3 tdc|a|tdc|le|phase|b|latch[1]|datac 25
7.104   0.225 RR CELL 1 LC_X13_Y16_N3 tdc|a|tdc|le|phase|b|latch[1]|combout 26
7.433   0.329 RR IC 2 LC_X13_Y16_N5 tdc|a|tdc|le|phase|b|latch[2]|datad 27
7.521   0.088 RR CELL 1 LC_X13_Y16_N5 tdc|a|tdc|le|phase|b|latch[2]|combout 28
7.850   0.329 RR IC 2 LC_X13_Y16_N1 tdc|a|tdc|le|phase|b|latch[3]|datad 29
7.938   0.088 RR CELL 1 LC_X13_Y16_N1 tdc|a|tdc|le|phase|b|latch[3]|combout 30
8.262   0.324 RR IC 2 LC_X13_Y16_N4 tdc|a|tdc|le|phase|b|latch[4]|datad 31
8.350   0.088 RR CELL 1 LC_X13_Y16_N4 tdc|a|tdc|le|phase|b|latch[4]|combout 32
8.691   0.341 RR IC 2 LC_X13_Y16_N2 tdc|a|tdc|le|phase|b|latch[5]|datac 33
8.916   0.225 RR CELL 1 LC_X13_Y16_N2 tdc|a|tdc|le|phase|b|latch[5]|combout 34
9.445   0.529 RR IC 2 LC_X14_Y16_N5 tdc|a|tdc|le|phase|b|latch[6]|datad 35
9.533   0.088 RR CELL 1 LC_X14_Y16_N5 tdc|a|tdc|le|phase|b|latch[6]|combout 36
9.673   0.140 RR IC 2 LC_X14_Y16_N6 tdc|a|tdc|le|phase|b|latch[7]|datad 37
9.761   0.088 RR CELL 1 LC_X14_Y16_N6 tdc|a|tdc|le|phase|b|latch[7]|combout 38
10.081   0.320 RR IC 2 LC_X14_Y16_N3 tdc|a|tdc|le|phase|b|latch[8]|datad 39
10.169   0.088 RR CELL 1 LC_X14_Y16_N3 tdc|a|tdc|le|phase|b|latch[8]|combout 40
10.488   0.319 RR IC 2 LC_X14_Y16_N7 tdc|a|tdc|le|phase|b|latch[9]|datad 41
10.576   0.088 RR CELL 1 LC_X14_Y16_N7 tdc|a|tdc|le|phase|b|latch[9]|combout 42
10.716   0.140 RR IC 2 LC_X14_Y16_N8 tdc|a|tdc|le|phase|c|latch[0]|datad 43
10.804   0.088 RR CELL 1 LC_X14_Y16_N8 tdc|a|tdc|le|phase|c|latch[0]|combout 44
10.944   0.140 RR IC 2 LC_X14_Y16_N9 tdc|a|tdc|le|phase|c|latch[1]|datad 45
11.032   0.088 RR CELL 1 LC_X14_Y16_N9 tdc|a|tdc|le|phase|c|latch[1]|combout 46
11.557   0.525 RR IC 2 LC_X15_Y16_N3 tdc|a|tdc|le|phase|c|latch[2]|datad 47
11.645   0.088 RR CELL 1 LC_X15_Y16_N3 tdc|a|tdc|le|phase|c|latch[2]|combout 48
11.972   0.327 RR IC 2 LC_X15_Y16_N6 tdc|a|tdc|le|phase|c|latch[3]|datad 49
12.060   0.088 RR CELL 1 LC_X15_Y16_N6 tdc|a|tdc|le|phase|c|latch[3]|combout 50
12.200   0.140 RR IC 2 LC_X15_Y16_N7 tdc|a|tdc|le|phase|c|latch[4]|datad 51
12.288   0.088 RR CELL 1 LC_X15_Y16_N7 tdc|a|tdc|le|phase|c|latch[4]|combout 52
12.627   0.339 RR IC 2 LC_X15_Y16_N5 tdc|a|tdc|le|phase|c|latch[5]|datac 53
12.852   0.225 RR CELL 1 LC_X15_Y16_N5 tdc|a|tdc|le|phase|c|latch[5]|combout 54
13.182   0.330 RR IC 2 LC_X15_Y16_N0 tdc|a|tdc|le|phase|c|latch[6]|datad 55
13.270   0.088 RR CELL 1 LC_X15_Y16_N0 tdc|a|tdc|le|phase|c|latch[6]|combout 56
13.599   0.329 RR IC 2 LC_X15_Y16_N8 tdc|a|tdc|le|phase|c|latch[7]|datad 57
13.687   0.088 RR CELL 1 LC_X15_Y16_N8 tdc|a|tdc|le|phase|c|latch[7]|combout 58
13.827   0.140 RR IC 2 LC_X15_Y16_N9 tdc|a|tdc|le|phase|c|latch[8]|datad 59
13.915   0.088 RR CELL 1 LC_X15_Y16_N9 tdc|a|tdc|le|phase|c|latch[8]|combout 60
14.255   0.340 RR IC 2 LC_X15_Y16_N1 tdc|a|tdc|le|phase|c|latch[9]|datac 61
14.480   0.225 RR CELL 1 LC_X15_Y16_N1 tdc|a|tdc|le|phase|c|latch[9]|combout 62
14.799   0.319 RR IC 2 LC_X15_Y16_N4 tdc|a|tdc|le|phase|d|latch[0]|datad 63
14.887   0.088 RR CELL 1 LC_X15_Y16_N4 tdc|a|tdc|le|phase|d|latch[0]|combout 64
15.223   0.336 RR IC 2 LC_X15_Y16_N2 tdc|a|tdc|le|phase|d|latch[1]|datac 65
15.448   0.225 RR CELL 1 LC_X15_Y16_N2 tdc|a|tdc|le|phase|d|latch[1]|combout 66
16.378   0.930 RR IC 2 LC_X14_Y15_N0 tdc|a|tdc|le|phase|d|latch[2]|datad 67
16.466   0.088 RR CELL 1 LC_X14_Y15_N0 tdc|a|tdc|le|phase|d|latch[2]|combout 68
16.606   0.140 RR IC 2 LC_X14_Y15_N1 tdc|a|tdc|le|phase|d|latch[3]|datad 69
16.694   0.088 RR CELL 1 LC_X14_Y15_N1 tdc|a|tdc|le|phase|d|latch[3]|combout 70
17.015   0.321 RR IC 2 LC_X14_Y15_N5 tdc|a|tdc|le|phase|d|latch[4]|datad 71
17.103   0.088 RR CELL 1 LC_X14_Y15_N5 tdc|a|tdc|le|phase|d|latch[4]|combout 72
17.243   0.140 RR IC 2 LC_X14_Y15_N6 tdc|a|tdc|le|phase|d|latch[5]|datad 73
17.331   0.088 RR CELL 1 LC_X14_Y15_N6 tdc|a|tdc|le|phase|d|latch[5]|combout 74
17.471   0.140 RR IC 2 LC_X14_Y15_N7 tdc|a|tdc|le|phase|d|latch[6]|datad 75
17.559   0.088 RR CELL 1 LC_X14_Y15_N7 tdc|a|tdc|le|phase|d|latch[6]|combout 76
17.898   0.339 RR IC 2 LC_X14_Y15_N4 tdc|a|tdc|le|phase|d|latch[7]|datac 77
18.123   0.225 RR CELL 1 LC_X14_Y15_N4 tdc|a|tdc|le|phase|d|latch[7]|combout 78
18.459   0.336 RR IC 2 LC_X14_Y15_N8 tdc|a|tdc|le|phase|d|latch[8]|datac 79
18.684   0.225 RR CELL 1 LC_X14_Y15_N8 tdc|a|tdc|le|phase|d|latch[8]|combout 80
18.824   0.140 RR IC 1 LC_X14_Y15_N9 tdc|a|tdc|le|phase|d|inst9|datad 81
18.912   0.088 RR CELL 1 LC_X14_Y15_N9 tdc|a|tdc|le|phase|d|inst9|combout 82
19.252   0.340 RR IC 1 LC_X14_Y15_N3 tdc|a|tdc|le|phase|d|latch[9]|datac 83
19.341   0.089 RR CELL 1 LC_X14_Y15_N3 TDC6:tdc|TDC2ef:a|TDC2e:tdc|TDC1:le|TDClcell40:phase|TDClcell10:d|latch[9]


tdc6j.pdf
The DL-TDC uses a 100 MHz fine time clock which is typical of FPGA logic designs used at TRIUMF (i.e. state of the art DarkSide FPGA logic runs only just faster at 125 MHz). Coupled with 0.200 ns LCELL delay this yields 50-60 element delay lines that comfortably fit inside the FPGA and use encoders that need only 1 level of pipelining to meet the timing. FPGA compilation time is 20 minutes (AMD 7700 CPU with DDR5 memory). A well balanced design. The fairly low time resolution (0.2 ns time bin vs 0.1 ns time bin of very old V1190 TDC) is deemed adequate to resolve the 1.5 ns e-linac bunches.


</pre>
For better time resolution a CARRY chain TDC must be developed:
* faster TDC fine clock, 200-500 MHz
* keep delay line length under 50-60 time bins
* keep the TDC back-end (endoder, data buffers, multiplexors) on the TDC slow clock (100-125 MHz)


= Cyclone-5 =
== Future improvement 2 ==


<pre>
The Cyclone-V SoC FPGA is now very old and is no longer a flagship at Altera (now Intel). It is still available, but for how long? Better, bigger, faster FPGAs are now available.
report_path -multi_corner -panel_name {Report Path} -to [get_keepers {TDC6:TDC6_inst|TDC2ef:a|TDC2e:tdc|TDC1:le|TDClcell40:phase|TDClcell10:d|latch[9]}] -npaths 1


21.108 21.108 data path 1
Next step would be to finish converting the TDC design to system-verilog and to port it to the Xilinx FPGA architecture.
0.000   0.000 1 FF_X85_Y18_N2 tdc_ts[0] 1
0.000   0.000 RR CELL 9 FF_X85_Y18_N2 tdc_ts[0]|q 2
1.530   1.530 RR IC 1 MLABCELL_X87_Y10_N15 TDC6_inst|a|tdc|le|phase|a|inst0|dataf 3
1.617   0.087 RR CELL 2 MLABCELL_X87_Y10_N15 TDC6_inst|a|tdc|le|phase|a|inst0|combout 4
1.860   0.243 RR IC 1 MLABCELL_X87_Y10_N6 TDC6_inst|a|tdc|le|phase|a|inst1|dataf 5
1.946   0.086 RR CELL 2 MLABCELL_X87_Y10_N6 TDC6_inst|a|tdc|le|phase|a|inst1|combout 6
2.714   0.768 RR IC 1 LABCELL_X85_Y11_N51 TDC6_inst|a|tdc|le|phase|a|inst2|dataf 7
2.800   0.086 RR CELL 2 LABCELL_X85_Y11_N51 TDC6_inst|a|tdc|le|phase|a|inst2|combout 8
3.323   0.523 RR IC 1 LABCELL_X85_Y11_N48 TDC6_inst|a|tdc|le|phase|a|inst3|datad 9
3.576   0.253 RR CELL 2 LABCELL_X85_Y11_N48 TDC6_inst|a|tdc|le|phase|a|inst3|combout 10
3.827   0.251 RR IC 1 LABCELL_X85_Y11_N15 TDC6_inst|a|tdc|le|phase|a|inst4|dataf 11
3.914   0.087 RR CELL 2 LABCELL_X85_Y11_N15 TDC6_inst|a|tdc|le|phase|a|inst4|combout 12
4.146   0.232 RR IC 1 LABCELL_X85_Y11_N12 TDC6_inst|a|tdc|le|phase|a|inst5|dataf 13
4.233   0.087 RR CELL 2 LABCELL_X85_Y11_N12 TDC6_inst|a|tdc|le|phase|a|inst5|combout 14
4.484   0.251 RR IC 1 LABCELL_X85_Y11_N9 TDC6_inst|a|tdc|le|phase|a|inst6|dataf 15
4.571   0.087 RR CELL 2 LABCELL_X85_Y11_N9 TDC6_inst|a|tdc|le|phase|a|inst6|combout 16
4.800   0.229 RR IC 1 LABCELL_X85_Y11_N6 TDC6_inst|a|tdc|le|phase|a|inst7|dataf 17
4.887   0.087 RR CELL 2 LABCELL_X85_Y11_N6 TDC6_inst|a|tdc|le|phase|a|inst7|combout 18
5.124   0.237 RR IC 1 LABCELL_X85_Y11_N3 TDC6_inst|a|tdc|le|phase|a|inst8|dataf 19
5.211   0.087 RR CELL 2 LABCELL_X85_Y11_N3 TDC6_inst|a|tdc|le|phase|a|inst8|combout 20
5.459   0.248 RR IC 1 LABCELL_X85_Y11_N0 TDC6_inst|a|tdc|le|phase|a|inst9|datac 21
5.864   0.405 RR CELL 2 LABCELL_X85_Y11_N0 TDC6_inst|a|tdc|le|phase|a|inst9|combout 22
6.075   0.211 RR IC 1 LABCELL_X85_Y11_N27 TDC6_inst|a|tdc|le|phase|b|inst0|dataa 23
6.656   0.581 RR CELL 2 LABCELL_X85_Y11_N27 TDC6_inst|a|tdc|le|phase|b|inst0|combout 24
6.901   0.245 RR IC 1 LABCELL_X85_Y11_N24 TDC6_inst|a|tdc|le|phase|b|inst1|datac 25
7.306   0.405 RR CELL 2 LABCELL_X85_Y11_N24 TDC6_inst|a|tdc|le|phase|b|inst1|combout 26
7.552   0.246 RR IC 1 LABCELL_X85_Y11_N21 TDC6_inst|a|tdc|le|phase|b|inst2|dataf 27
7.639   0.087 RR CELL 2 LABCELL_X85_Y11_N21 TDC6_inst|a|tdc|le|phase|b|inst2|combout 28
7.886   0.247 RR IC 1 LABCELL_X85_Y11_N18 TDC6_inst|a|tdc|le|phase|b|inst3|datac 29
8.291   0.405 RR CELL 2 LABCELL_X85_Y11_N18 TDC6_inst|a|tdc|le|phase|b|inst3|combout 30
8.548   0.257 RR IC 1 LABCELL_X85_Y11_N45 TDC6_inst|a|tdc|le|phase|b|inst4|dataf 31
8.635   0.087 RR CELL 2 LABCELL_X85_Y11_N45 TDC6_inst|a|tdc|le|phase|b|inst4|combout 32
8.839   0.204 RR IC 1 LABCELL_X85_Y11_N42 TDC6_inst|a|tdc|le|phase|b|inst5|datab 33
9.394   0.555 RR CELL 2 LABCELL_X85_Y11_N42 TDC6_inst|a|tdc|le|phase|b|inst5|combout 34
9.638   0.244 RR IC 1 LABCELL_X85_Y11_N39 TDC6_inst|a|tdc|le|phase|b|inst6|dataf 35
9.725   0.087 RR CELL 2 LABCELL_X85_Y11_N39 TDC6_inst|a|tdc|le|phase|b|inst6|combout 36
9.959   0.234 RR IC 1 LABCELL_X85_Y11_N36 TDC6_inst|a|tdc|le|phase|b|inst7|dataf 37
10.046   0.087 RR CELL 2 LABCELL_X85_Y11_N36 TDC6_inst|a|tdc|le|phase|b|inst7|combout 38
10.250   0.204 RR IC 1 LABCELL_X85_Y11_N33 TDC6_inst|a|tdc|le|phase|b|inst8|dataa 39
10.831   0.581 RR CELL 2 LABCELL_X85_Y11_N33 TDC6_inst|a|tdc|le|phase|b|inst8|combout 40
11.059   0.228 RR IC 1 LABCELL_X85_Y11_N30 TDC6_inst|a|tdc|le|phase|b|inst9|dataf 41
11.145   0.086 RR CELL 2 LABCELL_X85_Y11_N30 TDC6_inst|a|tdc|le|phase|b|inst9|combout 42
11.724   0.579 RR IC 1 LABCELL_X88_Y11_N57 TDC6_inst|a|tdc|le|phase|c|inst0|dataf 43
11.811   0.087 RR CELL 2 LABCELL_X88_Y11_N57 TDC6_inst|a|tdc|le|phase|c|inst0|combout 44
12.018   0.207 RR IC 1 LABCELL_X88_Y11_N54 TDC6_inst|a|tdc|le|phase|c|inst1|datab 45
12.573   0.555 RR CELL 2 LABCELL_X88_Y11_N54 TDC6_inst|a|tdc|le|phase|c|inst1|combout 46
12.780   0.207 RR IC 1 LABCELL_X88_Y11_N51 TDC6_inst|a|tdc|le|phase|c|inst2|dataa 47
13.361   0.581 RR CELL 2 LABCELL_X88_Y11_N51 TDC6_inst|a|tdc|le|phase|c|inst2|combout 48
13.591   0.230 RR IC 1 LABCELL_X88_Y11_N48 TDC6_inst|a|tdc|le|phase|c|inst3|dataf 49
13.678   0.087 RR CELL 2 LABCELL_X88_Y11_N48 TDC6_inst|a|tdc|le|phase|c|inst3|combout 50
13.935   0.257 RR IC 1 LABCELL_X88_Y11_N15 TDC6_inst|a|tdc|le|phase|c|inst4|dataf 51
14.022   0.087 RR CELL 2 LABCELL_X88_Y11_N15 TDC6_inst|a|tdc|le|phase|c|inst4|combout 52
14.254   0.232 RR IC 1 LABCELL_X88_Y11_N12 TDC6_inst|a|tdc|le|phase|c|inst5|dataf 53
14.341   0.087 RR CELL 2 LABCELL_X88_Y11_N12 TDC6_inst|a|tdc|le|phase|c|inst5|combout 54
14.592   0.251 RR IC 1 LABCELL_X88_Y11_N9 TDC6_inst|a|tdc|le|phase|c|inst6|dataf 55
14.679   0.087 RR CELL 2 LABCELL_X88_Y11_N9 TDC6_inst|a|tdc|le|phase|c|inst6|combout 56
14.908   0.229 RR IC 1 LABCELL_X88_Y11_N6 TDC6_inst|a|tdc|le|phase|c|inst7|dataf 57
14.995   0.087 RR CELL 2 LABCELL_X88_Y11_N6 TDC6_inst|a|tdc|le|phase|c|inst7|combout 58
15.247   0.252 RR IC 1 LABCELL_X88_Y11_N33 TDC6_inst|a|tdc|le|phase|c|inst8|dataf 59
15.334   0.087 RR CELL 2 LABCELL_X88_Y11_N33 TDC6_inst|a|tdc|le|phase|c|inst8|combout 60
15.568   0.234 RR IC 1 LABCELL_X88_Y11_N30 TDC6_inst|a|tdc|le|phase|c|inst9|dataf 61
15.655   0.087 RR CELL 2 LABCELL_X88_Y11_N30 TDC6_inst|a|tdc|le|phase|c|inst9|combout 62
15.909   0.254 RR IC 1 LABCELL_X88_Y11_N27 TDC6_inst|a|tdc|le|phase|d|inst0|dataf 63
15.996   0.087 RR CELL 2 LABCELL_X88_Y11_N27 TDC6_inst|a|tdc|le|phase|d|inst0|combout 64
16.241   0.245 RR IC 1 LABCELL_X88_Y11_N24 TDC6_inst|a|tdc|le|phase|d|inst1|datac 65
16.646   0.405 RR CELL 2 LABCELL_X88_Y11_N24 TDC6_inst|a|tdc|le|phase|d|inst1|combout 66
16.892   0.246 RR IC 1 LABCELL_X88_Y11_N21 TDC6_inst|a|tdc|le|phase|d|inst2|dataf 67
16.979   0.087 RR CELL 2 LABCELL_X88_Y11_N21 TDC6_inst|a|tdc|le|phase|d|inst2|combout 68
17.226   0.247 RR IC 1 LABCELL_X88_Y11_N18 TDC6_inst|a|tdc|le|phase|d|inst3|datac 69
17.631   0.405 RR CELL 2 LABCELL_X88_Y11_N18 TDC6_inst|a|tdc|le|phase|d|inst3|combout 70
17.888   0.257 RR IC 1 LABCELL_X88_Y11_N45 TDC6_inst|a|tdc|le|phase|d|inst4|dataf 71
17.975   0.087 RR CELL 2 LABCELL_X88_Y11_N45 TDC6_inst|a|tdc|le|phase|d|inst4|combout 72
18.185   0.210 RR IC 1 LABCELL_X88_Y11_N42 TDC6_inst|a|tdc|le|phase|d|inst5|datab 73
18.740   0.555 RR CELL 2 LABCELL_X88_Y11_N42 TDC6_inst|a|tdc|le|phase|d|inst5|combout 74
18.984   0.244 RR IC 1 LABCELL_X88_Y11_N39 TDC6_inst|a|tdc|le|phase|d|inst6|dataf 75
19.071   0.087 RR CELL 2 LABCELL_X88_Y11_N39 TDC6_inst|a|tdc|le|phase|d|inst6|combout 76
19.305   0.234 RR IC 1 LABCELL_X88_Y11_N36 TDC6_inst|a|tdc|le|phase|d|inst7|dataf 77
19.392   0.087 RR CELL 2 LABCELL_X88_Y11_N36 TDC6_inst|a|tdc|le|phase|d|inst7|combout 78
19.618   0.226 RR IC 1 LABCELL_X88_Y11_N3 TDC6_inst|a|tdc|le|phase|d|inst8|dataa 79
20.199   0.581 RR CELL 2 LABCELL_X88_Y11_N3 TDC6_inst|a|tdc|le|phase|d|inst8|combout 80
20.447   0.248 RR IC 1 LABCELL_X88_Y11_N0 TDC6_inst|a|tdc|le|phase|d|inst9|datac 81
20.847   0.000 RR IC 1 FF_X88_Y11_N2 TDC6_inst|a|tdc|le|phase|d|latch[9]|d 82
20.847   0.400 RR CELL 1 LABCELL_X88_Y11_N0 TDC6_inst|a|tdc|le|phase|d|inst9|combout 83
21.108   0.261 RR CELL 1 FF_X88_Y11_N2 TDC6:TDC6_inst|TDC2ef:a|TDC2e:tdc|TDC1:le|TDClcell40:phase|TDClcell10:d|latch[9] 84


tdc6g.pdf
== Secret Sauce ==


min bin: 0.021 0.016 0.031 0.030 ns, max bin: 0.484 0.612 0.872 1.171 ns, max phase 38 36 33 33
Yea, right. Ask me.
min bin: 0.016 0.074 0.009 0.130 ns, max bin: 0.857 0.727 0.622 0.782 ns, max phase 33 30 38 35
</pre>

Latest revision as of 19:44, 7 September 2024

DL-TDC DarkLight FPGA TDC

ODB settings

  • dl_enable - yes/no - enable or disable TDC readout in the midas frontend
  • dl_ctrl - 32 bits of general control
bit - quartus - description
  0 - dl_ctrl_gate   - jam TDC gate open, enable un-triggered free-running mode
  1 - dl_ctrl_gate_A - gate TDC from A-side trigger
  2 - dl_ctrl_gate_B - gate TDC from B-side trigger
  3 - dl_ctrl_gate_AB - gate TDC from A*B
  4 - dl_ctrl_gate_T - gate TDC from T trigger (T = A*B)
  5 - dl_ctrl_ena_A - enable TDC channel 32 (A)
  6 - dl_ctrl_ena_B - enable TDC channel 33 (B)
  7 - dl_ctrl_ena_T - enable TDC channel 34 (T)
15..8 - dl_ctrl_gate_w - TDC gate width in units of 8 ns
31..16 - not used
  • dl_trg_mask - 16 bits of trigger mask
bit - description
  0 - enable A pair 1-9
  1 - enable A pair 2-10
  2 - enable A pair 3-11
  3 - enable A pair 4-12
  4
  5
  6
  7
  8 - enable B pair 5-13
  9 - enable B pair 6-14
 10 - enable B pair 7-15
 11 - enable B pair 8-16
  • dl_tdc_mask - 32 bits to enable 32 TDC channels, in sequence

Channel map

// map TDC cable to SiPM channels
   
   assign ch[1]  = tdc[0];
   assign ch[2]  = tdc[1];
   assign ch[3]  = tdc[10];
   assign ch[4]  = tdc[11];
   assign ch[5]  = tdc[2];
   assign ch[6]  = tdc[3];
   assign ch[7]  = tdc[8];
   assign ch[8]  = tdc[9];

   assign ch[9]  = tdc[15];
   assign ch[10] = tdc[14];
   assign ch[11] = tdc[7];
   assign ch[12] = tdc[6];
   assign ch[13] = tdc[13];
   assign ch[14] = tdc[12];
   assign ch[15] = tdc[5];
   assign ch[16] = tdc[4];

   assign ch[16+1]  = tdc[16+0];  // 16
   assign ch[16+2]  = tdc[16+1];  // 17
   assign ch[16+3]  = tdc[16+10]; // 26
   assign ch[16+4]  = tdc[16+11]; // 27
   assign ch[16+5]  = tdc[16+2];  // 18
   assign ch[16+6]  = tdc[16+3];  // 19
   assign ch[16+7]  = tdc[16+8];  // 24
   assign ch[16+8]  = tdc[16+9];  // 25

   assign ch[16+9]  = tdc[16+15]; // 31
   assign ch[16+10] = tdc[16+14]; // 30
   assign ch[16+11] = tdc[16+7];  // 23
   assign ch[16+12] = tdc[16+6];  // 22
   assign ch[16+13] = tdc[16+13]; // 29
   assign ch[16+14] = tdc[16+12]; // 28
   assign ch[16+15] = tdc[16+5];  // 21
   assign ch[16+16] = tdc[16+4];  // 20

   // compute SiPM pair concindences
   
   assign A[0] = ch[1] & ch[9]  & enable_input[0]; //  0 * 15 -> pair1
   assign A[1] = ch[2] & ch[10] & enable_input[1]; //  1 * 14 -> pair2
   assign A[2] = ch[3] & ch[11] & enable_input[2]; // 10 *  7 -> pair3
   assign A[3] = ch[4] & ch[12] & enable_input[3]; // 11 *  6 -> pair4
   assign A[4] = ch[5] & ch[13] & enable_input[4];
   assign A[5] = ch[6] & ch[14] & enable_input[5];
   assign A[6] = ch[7] & ch[15] & enable_input[6];
   assign A[7] = ch[8] & ch[16] & enable_input[7];

   assign B[0] = ch[16+1] & ch[16+9]  & enable_input[8];  // 16 * 31
   assign B[1] = ch[16+2] & ch[16+10] & enable_input[9];  // 17 * 30
   assign B[2] = ch[16+3] & ch[16+11] & enable_input[10]; // 26 * 23
   assign B[3] = ch[16+4] & ch[16+12] & enable_input[11]; // 27 * 22
   assign B[4] = ch[16+5] & ch[16+13] & enable_input[12]; // 18 * 29 -> pair5
   assign B[5] = ch[16+6] & ch[16+14] & enable_input[13]; // 19 * 28 -> pair6
   assign B[6] = ch[16+7] & ch[16+15] & enable_input[14]; // 24 * 21 -> pair7
   assign B[7] = ch[16+8] & ch[16+16] & enable_input[15]; // 25 * 20 -> pair8

   wire        A_or = |A;
   wire        B_or = |B;

   //wire        A_or = A[0] | A{1] | A{2] | A[3] | A[4] | A{5] | A{6] | A[7];
   //wire        B_or = B[0] | B{1] | B{2] | B[3] | B[4] | B{5] | B{6] | B[7];

   wire        AB_and = A_or & B_or;

D3 delay tuning

  • quartus report "DL trigger GPIO to dlA", "to dlB" and "through dlT"
  • delay values are set in quartus assignements file. Delay values go from 0 to 7 in increments of about 0.5 ns.
dsdaqgw:chronobox_firmware$ grep D3_DELAY *.qsf
DE10_NANO_SoC_GHRD.qsf:set_instance_assignment -name D3_DELAY 5 -to GPIO_1_21
9.109	GPIO_1_20	dl|WideOr0|combout -> 1
9.025	GPIO_1_33	dl|WideOr0|combout -> 1
9.022	GPIO_1_26	dl|WideOr0|combout -> 0
8.966	GPIO_1_28	dl|WideOr0|combout -> 5            = 8.494 add 1
8.787	GPIO_1_22	dl|WideOr0|combout -> 0
8.714	GPIO_1_21	dl|WideOr0|combout -> 5
8.711	GPIO_1_34	dl|WideOr0|combout -> 0
8.597	GPIO_1_30	dl|WideOr0|combout -> 0            = 8.240 add 1 -> 1 = 9.733 sub 1
8.590	GPIO_1_29	dl|WideOr0|combout -> 1 add 1 -> 2 = 9.588 sub 1
8.506	GPIO_1_27	dl|WideOr0|combout -> 4 add 1 --------------------> 5 = 10.097 sub 1
8.453	GPIO_1_24	dl|WideOr0|combout -> 2 add 1 -> 3 = 9.588 sub 1
8.412	GPIO_1_35	dl|WideOr0|combout add 1
8.380	GPIO_1_31	dl|WideOr0|combout -> 4 add 1 -> 5 = 9.208 sub 1
8.312	GPIO_1_25	dl|WideOr0|combout -> 1 add 1 -> 2 = 8.555 add 1 -> 3 = 9.379
7.992	GPIO_1_32	dl|WideOr0|combout add 2
7.248	GPIO_1_23	dl|WideOr0|combout -> 2 add 3 -> 5 = 9.425 sub 1
9.339	GPIO_0_14	dl|WideOr1|combout -> 6 sub 1 -> 5 = 8.587
9.207	GPIO_0_2	dl|WideOr1|combout -> 7 sub 1 -> 6 = 8.360 add 1
9.174	GPIO_0_10	dl|WideOr1|combout -> 6
9.161	GPIO_0_6	dl|WideOr1|combout -> 7
9.105	GPIO_0_11	dl|WideOr1|combout -> 7
9.019	GPIO_0_7	dl|WideOr1|combout -> 7
8.731	GPIO_0_15	dl|WideOr1|combout add 0 -> 0 = 8.540 add 1
8.462	GPIO_0_12	dl|WideOr1|combout add 1 -> 1 = 9.189
8.256	GPIO_0_4	dl|WideOr1|combout add 2 -> 2 = 9.750 sub 1
8.214	GPIO_0_5	dl|WideOr1|combout add 2
8.182	GPIO_0_1	dl|WideOr1|combout add 2
7.328	GPIO_0_3	dl|WideOr1|combout add 3
6.584	GPIO_0_8	dl|WideOr1|combout add 5
6.409	GPIO_0_13	dl|WideOr1|combout add 5 -> 5 =  9.943 sub 2
6.009	GPIO_0_9	dl|WideOr1|combout add 6 -> 6 = 10.189 sub 2
5.917	GPIO_0_0	dl|WideOr1|combout add 6

Theory of operation

Why FPGA TDC?

  • combine trigger logic, hit recording and time measurement in one device
  • avoid having to split signals to FPGA trigger and to external TDC and to coordinate clocks and timestamps between them
  • ability to construct custom TDC with data paths tuned to experiment requirements, i.e. ultra high data rates. this avoids the well known problem with the CERN TDC ASIC (V1190) where high rate on one channel will cause data loss on other channels.
  • ability to get the data out at FPGA speeds, not limited to VME, USB or Ethernet speeds.
  • ability to "right-size" the TDC. ASIC TDCs come in fixed increments: 96 channels (Lecroy Fastbus TDC), 64 or 128 channels (CAEN V1190 VME TDC), 64 channels (PicoTDC), overkill of fewer channels are actually needed. Compared to FPGA TDC where size (cost) of FPGA can be selected according to need and where FPGAs of different sizes often are available as interchangeable plug-in modules.

Downsides:

  • ASIC TDC design can control internal timing much better than an FPGA TDC. as result per-time-bin and per-channel variations can be made much smaller.
  • ASIC TDC can run at much higher clock frequencies and have much smaller time bins.
  • ASIC TDC may have internal temperature compensation functions in order to avoid temperature drift of TDC calibration.

Types of FPGA TDC

FPGA TDC come in two basic types: based on delay lines and based on the Vernier method. Delay line TDC resolution is limited to size and number of delay line elements. Vernier TDCs requires precise clock generators (usually not available on standard FPGA devices). Delay line TDCs have several designs. Delay line captures phase of input signal relative to the clock. Delay line captures phase of the clock relative to the input signal. Delay line encoder looks for 1 edge transition, or looks for many edge transitions ("wavelet TDC").

Delay line FPGA TDC building blocks

  • signal capture and clock synchronizer - asynchronous input signal is latched and synchronized to the TDC clock. Per-hit dead time (LE to next pulse), minimum pulse width requirement (LE to TE), minimum time double-pulse resolution (TE to next LE) are created here.
  • tdc clock counter - latched and synchronized input signal records the hit coarse time (10 ns time bin)
  • delay line - tdc clock (50 MHz/20 ns) waveform travels throught the 60-element delay line (~25 ns) total delay), latched input signal captures this waveform in the phase latch register (60 bits). Typical bit pattern: "00...000111...11100..000"
  • "temperature encoder" - looks for the position of the first 0->1 or 1->0 transition and converts it into a time bin number 1..60 (for 0->1 transitions) and -1..-60 (for 1->0 transitions). This clock phase time bin number corresponds to the TDC fine time. After calibration that accounts for individual delay of each time bin.
  • per-channel input buffer - 64 hits per channel for LE and TE (32 LE+TE hits), to handle bursts of hits
  • main multiplexor - data from 32+3 TDC channels is funneled into 1 output stream
  • main data FIFO - "the bigger, the better" data buffer to hold the data before it is transmitted out of the TDC
  • data transmitter - DL-TDC uses a MIDAS frontend to read the main data FIFO via a 64-bit AXI bus, package data as MIDAS events and send them to the main computer via the Cyclone-5 SoC 1gige ethernet (data rate about 50 Mbytes/sec; at 8+8 bytes per TDC hit (LE+TE), about 3 Mhits/sec, sustained).

Implementation details

  • delay line element: use LCELL or cyclonev_lcell_comb (TDClcellff.sv), quartus fitter does not care which, does it's own thing regarding which LCELL input ports to use. Input "F" must be used for best timing (shortest delay): LUT mask: F0 = vcc 0xFFFF, F1 = vcc 0xFFFF, F2 = gnd 0x0000, F3 = gnd 0x0000, Combout equation: LCELL(F), File:TDC LCELL.pdf
  • delay line: in theory, 20 delay line elements can be packed in a 10-ALM block. In practice, to ensure routing uses LCELL input "F", TDC uses 8 delay elements per 10-ALM block. (quartus uses the "leftover" ALMs to implement the encoder and other logic). Typical timing reported by quartus is 0.087 ns transmit time through combinatorial logic from input F to COMBOUT output, 0.250 ns transit time to the next delay element inthe same 10-ALM block, 0.800 ns transmit time to the first delay element of the next 10-ALM block. File:TDC DELAY CHAIN1.pdf and File:TDC DELAY CHAIN2.pdf
  • timing of TDC delay chain for each TDC channel is shown in "Report DL-TDC-NN-{LE,TE}", use "Locate path" to "Locate path in chip planner", them zoom in and click in logic elements to examine the physical layout. Use "show routing" to see more detail of connection between logic elements.
  • layout of the 60-element TDC delay line is done manually using quartus qsf file dltdc.qsf. This file is generated by a perl script (dltdc_qsf.perl). Location of each TDC channel is selected manually and must be adjusted to have them close to the FPGA input pins and to spread things around to avoid FPGA resource congestion.
set_location_assignment LABCELL_X11_Y10_N6 -to "TDCn:tdcs|TDC2ef:tdc[17].tdc|TDC2e:tdc|TDC1:le|TDClcellN:phase|TDClcellff:e[0].c|lcell"
set_location_assignment FF_X11_Y10_N7 -to "TDCn:tdcs|TDC2ef:tdc[17].tdc|TDC2e:tdc|TDC1:le|TDClcellN:phase|TDClcellff:e[0].c|ff1"
set_location_assignment LABCELL_X11_Y10_N12 -to "TDCn:tdcs|TDC2ef:tdc[17].tdc|TDC2e:tdc|TDC1:le|TDClcellN:phase|TDClcellff:e[1].c|lcell"
set_location_assignment FF_X11_Y10_N13 -to "TDCn:tdcs|TDC2ef:tdc[17].tdc|TDC2e:tdc|TDC1:le|TDClcellN:phase|TDClcellff:e[1].c|ff1"
  • Cyclone-V SoC FPGA on the DE-10 evaluation board comfortably fits 32+3 TDC channels with room to spare: File:TDC LAYOUT.pdf (each TDC channel is shown in a different colour, explosion at the paint factory)

TDC calibration

  • the DL-TDC design uses the delay line for the clock and the latched hit signal to capture the clock phase. if TDC hits are uncorrelated with the TDC clock (i.e. cosmic rays or calibration pulser running from a different clock oscillator), we can assume a uniform distribution of TDC fine time (0 to 10 ns) and use the TDC fine time bin distribution to compute actual TDC delay line bin size and construct the mapping from TDC fine time bin (1..60) to TDC fine time (0..10 ns).
  • calibration pulser run 286, TDC firmware 0x66dbbf18
  • channel tdc00-LE fine time bin occupancy distribution: File:TDC TIME BIN OCCUPANCY.pdf
  • fine time bin size (actual bin size is smaller than bin size computed by quartus because quartus must assume the worst possible FPGA timing): File:TDC TIME BIN SIZE.pdf
  • typical TDC delay line size is 45-50 bins (out of 60 available), average time bins size 0.200..0.222 ns, actual computed typical bin size 0.180 ps (or so) with 5 or 6 extra-wide bins that correspond to TDC delay line transit from one block of logic elements to the next block of logic elements.
  • for each run the fine time distribution is computed, if distortion from uniform 0..10 ns becomes too big, fine time calibration must be redone. File:TDC FINE TIME.pdf
  • in addition to TDC delay line calibration, the TDC per-channel input delays must be calibrated. this is done by sending a common signal to all TDC inputs: File:TDC PULSER LE.pdf

Future improvement 1

FPGA TDCs that use LCELL delay lines are unusual. Most FPGA TDCs reported on the literature use CARRY-chain delay lines.

Typical LCELL delay is 0.200 ns, typical CARRY delay is .050 ns (even for very old Cyclone-I FPGAs) and TDCs with much higher nominal resolution can be built.

The trade-off between the two designs is the interplay between length of the delay line and frequency of the TDC fine clock. Slow clock and very fast delay line result in a very long delay line. Very long delay lines require edge ("temperature") encoders that use too many logic elements and this limits the number of channels that can be implemented in an FPGA of given size.

The DL-TDC uses a 100 MHz fine time clock which is typical of FPGA logic designs used at TRIUMF (i.e. state of the art DarkSide FPGA logic runs only just faster at 125 MHz). Coupled with 0.200 ns LCELL delay this yields 50-60 element delay lines that comfortably fit inside the FPGA and use encoders that need only 1 level of pipelining to meet the timing. FPGA compilation time is 20 minutes (AMD 7700 CPU with DDR5 memory). A well balanced design. The fairly low time resolution (0.2 ns time bin vs 0.1 ns time bin of very old V1190 TDC) is deemed adequate to resolve the 1.5 ns e-linac bunches.

For better time resolution a CARRY chain TDC must be developed:

  • faster TDC fine clock, 200-500 MHz
  • keep delay line length under 50-60 time bins
  • keep the TDC back-end (endoder, data buffers, multiplexors) on the TDC slow clock (100-125 MHz)

Future improvement 2

The Cyclone-V SoC FPGA is now very old and is no longer a flagship at Altera (now Intel). It is still available, but for how long? Better, bigger, faster FPGAs are now available.

Next step would be to finish converting the TDC design to system-verilog and to port it to the Xilinx FPGA architecture.

Secret Sauce

Yea, right. Ask me.