Line 49... |
Line 49... |
49 |
unsigned int16 phase_fire=0; |
49 |
unsigned int16 phase_fire=0; |
50 |
|
50 |
|
51 |
//}TDC_registers; |
51 |
//}TDC_registers; |
52 |
|
52 |
|
53 |
|
53 |
|
- |
|
54 |
/* |
- |
|
55 |
1 0 0 0 0 ADR2 ADR1 ADR0 Write into address ADR |
- |
|
56 |
1 0 1 1 0 ADR2 ADR1 ADR0 Read from address ADR |
- |
|
57 |
0 1 1 1 0 0 0 0 Init |
- |
|
58 |
0 1 0 1 0 0 0 0 Power On Reset |
- |
|
59 |
0 0 0 0 0 0 0 1 Start_Cycle |
- |
|
60 |
0 0 0 0 0 0 1 0 Start_Temp |
- |
|
61 |
0 0 0 0 0 0 1 1 Start_Cal_Resonator |
- |
|
62 |
0 0 0 0 0 1 0 0 Start_Cal_TDC |
- |
|
63 |
*/ |
- |
|
64 |
|
54 |
void TDC_init() |
65 |
void TDC_init() |
55 |
{ |
66 |
{ |
56 |
output_low(TDC_ENABLE); |
67 |
output_low(TDC_ENABLE); |
57 |
spi_xfer(TDC_stream,0x70,8); |
68 |
spi_xfer(TDC_stream,0x70,8); |
58 |
output_high(TDC_ENABLE); |
69 |
output_high(TDC_ENABLE); |
Line 222... |
Line 233... |
222 |
TDC_update_reg1(); // tell to ALU which shot period must be computed |
233 |
TDC_update_reg1(); // tell to ALU which shot period must be computed |
223 |
|
234 |
|
224 |
Delay_ms(50); // wait to computing of result |
235 |
Delay_ms(50); // wait to computing of result |
225 |
|
236 |
|
226 |
measurement=TDC_get_measurement(7&TDC_get_status()); // read computed value on pointer result register address |
237 |
measurement=TDC_get_measurement(7&TDC_get_status()); // read computed value on pointer result register address |
- |
|
238 |
|
- |
|
239 |
|
- |
|
240 |
switch (clkhsdiv) |
- |
|
241 |
{ |
- |
|
242 |
case TDC_CLKHSDIV_1: |
- |
|
243 |
time=(measurement/65536.0) * 1.0e6/TDC_CLKHS; |
- |
|
244 |
break; |
- |
|
245 |
|
- |
|
246 |
case TDC_CLKHSDIV_2: |
- |
|
247 |
time=(measurement/65536.0) * 1.0e6/TDC_CLKHS * 2.0; |
- |
|
248 |
break; |
- |
|
249 |
|
- |
|
250 |
case TDC_CLKHSDIV_4: |
- |
|
251 |
time=(measurement/65536.0) * 1.0e6/TDC_CLKHS * 4.0; |
- |
|
252 |
break; |
- |
|
253 |
case TDC_CLKHSDIV_8: |
- |
|
254 |
time=(measurement/65536.0) * 1.0e6/TDC_CLKHS * 8.0; |
- |
|
255 |
break; |
- |
|
256 |
} |
- |
|
257 |
return time; |
- |
|
258 |
} |
- |
|
259 |
|
- |
|
260 |
float TDC_mrange1_get_time(unsigned int channel1, unsigned int shot1, unsigned int channel2, unsigned int shot2) |
- |
|
261 |
{ |
- |
|
262 |
unsigned int32 measurement; |
- |
|
263 |
float time; |
- |
|
264 |
|
- |
|
265 |
switch (shot1) |
- |
|
266 |
{ |
- |
|
267 |
case 0: |
- |
|
268 |
hit1=TDC_MRANGE1_HIT1_START; |
- |
|
269 |
break; |
- |
|
270 |
case 1: |
- |
|
271 |
if (channel1 == 1) hit1=TDC_MRANGE1_HIT1_1CH1; else hit1=TDC_MRANGE1_HIT1_1CH2; |
- |
|
272 |
break; |
- |
|
273 |
|
- |
|
274 |
case 2: |
- |
|
275 |
if (channel1 == 1) hit1=TDC_MRANGE1_HIT1_2CH1; else hit1=TDC_MRANGE1_HIT1_2CH2; |
- |
|
276 |
break; |
- |
|
277 |
|
- |
|
278 |
case 3: |
- |
|
279 |
if (channel1 == 1) hit1=TDC_MRANGE1_HIT1_3CH1; else hit1=TDC_MRANGE1_HIT1_3CH2; |
- |
|
280 |
break; |
- |
|
281 |
|
- |
|
282 |
case 4: |
- |
|
283 |
if (channel1 == 1) hit1=TDC_MRANGE1_HIT1_4CH1; else hit1=TDC_MRANGE1_HIT1_4CH2; |
- |
|
284 |
break; |
- |
|
285 |
} |
- |
|
286 |
|
- |
|
287 |
switch (shot2) |
- |
|
288 |
{ |
- |
|
289 |
case 0: |
- |
|
290 |
hit2=TDC_MRANGE1_HIT2_START; |
- |
|
291 |
break; |
- |
|
292 |
|
- |
|
293 |
case 1: |
- |
|
294 |
if (channel2 == 1) hit2=TDC_MRANGE1_HIT2_1CH1; else hit2=TDC_MRANGE1_HIT2_1CH2; |
- |
|
295 |
break; |
- |
|
296 |
|
- |
|
297 |
case 2: |
- |
|
298 |
if (channel2 == 1) hit2=TDC_MRANGE1_HIT2_2CH1; else hit2=TDC_MRANGE1_HIT2_2CH2; |
- |
|
299 |
break; |
- |
|
300 |
|
- |
|
301 |
case 3: |
- |
|
302 |
if (channel2 == 1) hit2=TDC_MRANGE1_HIT2_3CH1; else hit2=TDC_MRANGE1_HIT2_3CH2; |
- |
|
303 |
break; |
- |
|
304 |
|
- |
|
305 |
case 4: |
- |
|
306 |
if (channel2 == 1) hit2=TDC_MRANGE1_HIT2_4CH1; else hit2=TDC_MRANGE1_HIT2_4CH2; |
- |
|
307 |
break; |
- |
|
308 |
} |
- |
|
309 |
|
- |
|
310 |
TDC_update_reg1(); // tell to ALU which shot period must be computed |
- |
|
311 |
|
- |
|
312 |
Delay_ms(50); // wait to computing of result |
- |
|
313 |
|
- |
|
314 |
measurement=TDC_get_measurement(7&TDC_get_status()); // read computed value on pointer result register address |
227 |
|
315 |
|
228 |
|
316 |
|
229 |
switch (clkhsdiv) |
317 |
switch (clkhsdiv) |
230 |
{ |
318 |
{ |
231 |
case TDC_CLKHSDIV_1: |
319 |
case TDC_CLKHSDIV_1: |