Line 72... |
Line 72... |
72 |
void TDC_reset() |
72 |
void TDC_reset() |
73 |
{ |
73 |
{ |
74 |
output_low(TDC_ENABLE); |
74 |
output_low(TDC_ENABLE); |
75 |
spi_xfer(TDC_stream,0x50,8); |
75 |
spi_xfer(TDC_stream,0x50,8); |
76 |
output_high(TDC_ENABLE); |
76 |
output_high(TDC_ENABLE); |
- |
|
77 |
|
- |
|
78 |
//reset registers settings to default |
- |
|
79 |
|
- |
|
80 |
firenum=TDC_FIRENUM_0; |
- |
|
81 |
div_fire=TDC_DIV_FIRE_2; |
- |
|
82 |
calresnum=TDC_CALPERIODS_2; |
- |
|
83 |
clkhsdiv=TDC_CLKHSDIV_1; |
- |
|
84 |
start_clkhs=TDC_CLKHS_ON; |
- |
|
85 |
portnum=TDC_TPORTNUM_4; |
- |
|
86 |
Tcycle=TDC_TCYCLE_SHORT; |
- |
|
87 |
fakenum=TDC_TFAKENUM_2; |
- |
|
88 |
selclkT=TDC_TSELCLK_128HS; |
- |
|
89 |
calibrate=TDC_CALIBRATE_EN; |
- |
|
90 |
disautocal=TDC_AUTOCAL_EN; |
- |
|
91 |
MRange=TDC_MRANGE2; |
- |
|
92 |
neg_stop2=TDC_NEG_STOP2; |
- |
|
93 |
neg_stop1=TDC_NEG_STOP1; |
- |
|
94 |
neg_start=TDC_NEG_START; |
- |
|
95 |
hit2=TDC_MRANGE1_HIT2_NOAC; |
- |
|
96 |
hit1=TDC_MRANGE1_HIT1_NOAC; |
- |
|
97 |
fast_init=TDC_FAST_INIT_DIS; |
- |
|
98 |
hitin2=TDC_HITIN2_0; |
- |
|
99 |
hitin1=TDC_HITIN1_0; |
- |
|
100 |
en_int=TDC_INT_ALU; |
- |
|
101 |
rfedge2=TDC_CH2EDGE_RIS; |
- |
|
102 |
rfedge1=TDC_CH1EDGE_RIS; |
- |
|
103 |
en_err_val=TDC_ERRVAL_DIS; |
- |
|
104 |
tim0_mr2=TDC_TIM0MR2_16384CLKHS; |
- |
|
105 |
delval1=0; |
- |
|
106 |
delval2=0; |
- |
|
107 |
delval3=0; |
- |
|
108 |
conf_fire=0; |
- |
|
109 |
en_startnoise=TDC_STARTNOISE_DIS; |
- |
|
110 |
dis_phasenoise=TDC_PHASENOISE_DIS; |
- |
|
111 |
repeat_fire=TDC_REPEAT_FIRE_0; |
- |
|
112 |
phase_fire=0; |
77 |
} |
113 |
} |
78 |
|
114 |
|
79 |
void TDC_start_cycle() |
115 |
void TDC_start_cycle() |
80 |
{ |
116 |
{ |
81 |
output_low(TDC_ENABLE); |
117 |
output_low(TDC_ENABLE); |
Line 104... |
Line 140... |
104 |
output_high(TDC_ENABLE); |
140 |
output_high(TDC_ENABLE); |
105 |
} |
141 |
} |
106 |
|
142 |
|
107 |
unsigned int32 TDC_get_measurement(int num) |
143 |
unsigned int32 TDC_get_measurement(int num) |
108 |
{ |
144 |
{ |
109 |
unsigned int32 ret; |
145 |
unsigned int32 ret=0; |
110 |
|
146 |
|
111 |
output_low(TDC_ENABLE); |
147 |
output_low(TDC_ENABLE); |
112 |
spi_xfer(TDC_stream,0xB0 + num - 1, 8); |
148 |
spi_xfer(TDC_stream,0xB0 + num - 1, 8); |
113 |
ret=spi_xfer(TDC_stream,0,32); |
149 |
ret=spi_xfer(TDC_stream,0,32); |
114 |
output_high(TDC_ENABLE); |
150 |
output_high(TDC_ENABLE); |
Line 209... |
Line 245... |
209 |
spi_xfer(TDC_stream,repeat_fire,3); |
245 |
spi_xfer(TDC_stream,repeat_fire,3); |
210 |
spi_xfer(TDC_stream,phase_fire,16); |
246 |
spi_xfer(TDC_stream,phase_fire,16); |
211 |
output_high(TDC_ENABLE); |
247 |
output_high(TDC_ENABLE); |
212 |
} |
248 |
} |
213 |
|
249 |
|
214 |
float TDC_mrange2_get_time(unsigned int shot) |
250 |
float TDC_mrange2_get_time(unsigned int shot) // read start to stop time distance of desired shot |
215 |
{ |
251 |
{ |
216 |
unsigned int32 measurement; |
252 |
unsigned int32 measurement; |
217 |
float time; |
253 |
float time; |
218 |
|
254 |
|
219 |
switch (shot) |
255 |
switch (shot) // determine which shot is desired to compute |
220 |
{ |
256 |
{ |
221 |
case 1: |
257 |
case 1: |
222 |
hit2=TDC_MRANGE2_HIT2_1CH1; |
258 |
hit2=TDC_MRANGE2_HIT2_1CH1; |
223 |
break; |
259 |
break; |
224 |
|
260 |
|
Line 228... |
Line 264... |
228 |
|
264 |
|
229 |
case 3: |
265 |
case 3: |
230 |
hit2=TDC_MRANGE2_HIT2_3CH1; |
266 |
hit2=TDC_MRANGE2_HIT2_3CH1; |
231 |
break; |
267 |
break; |
232 |
} |
268 |
} |
233 |
TDC_update_reg1(); // tell to ALU which shot period must be computed |
269 |
TDC_update_reg1(); // tell ALU which shot period must be computed |
234 |
|
270 |
|
235 |
Delay_ms(50); // wait to computing of result |
271 |
Delay_ms(50); // wait to computing of result |
236 |
|
272 |
|
237 |
measurement=TDC_get_measurement(7&TDC_get_status()); // read computed value on pointer result register address |
273 |
measurement=TDC_get_measurement(7&TDC_get_status()); // read computed value on pointer result register address |
238 |
|
274 |
|
239 |
|
275 |
|
240 |
switch (clkhsdiv) |
276 |
switch (clkhsdiv) // calibrate measurement data to microseconds from known register setting |
241 |
{ |
277 |
{ |
242 |
case TDC_CLKHSDIV_1: |
278 |
case TDC_CLKHSDIV_1: |
243 |
time=(measurement/65536.0) * 1.0e6/TDC_CLKHS; |
279 |
time=(measurement/65536.0) * 1.0e6/TDC_CLKHS; |
244 |
break; |
280 |
break; |
245 |
|
281 |
|