Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
291 | f9daq | 1 | //#define USE_DAQ |
2 | //#define USE_MIKRO |
||
3 | #define USE_EASIROC |
||
4 | #define USE_UDPCONTROL |
||
5 | |||
6 | #ifdef USE_EASIROC |
||
7 | #include "easiroc.h" |
||
8 | |||
9 | #define erIpAddr "192.168.10.16" |
||
10 | #define erDAQmode 3 |
||
11 | #endif |
||
12 | |||
13 | #ifdef USE_UDPCONTROL |
||
14 | #include "SiTCP.h" |
||
15 | #include "sender.h" |
||
16 | |||
17 | #define IpAddr "192.168.10.16" |
||
18 | #define tcpport 24 |
||
19 | #define udpport 4660 |
||
20 | |||
21 | int HVDAC = 0; |
||
22 | int MADC = 0; |
||
23 | int MUX = 0; |
||
24 | double HV = 0; |
||
25 | double rd_data = 0; |
||
26 | float DACdata[63]; |
||
27 | |||
28 | float HVC_1 = 483.183; |
||
29 | float HVC_2 = 780; |
||
30 | // HVDAC =HVC_1 * HV + HVC_2; convert HV to DAC bit |
||
31 | |||
32 | float ADC2HV = 0.00208; |
||
33 | // rd_data = ADC2HV * rd_data; convert ADC bit to HV |
||
34 | |||
35 | float ADC2uA = 0.034; |
||
36 | // rd_data = ADC2uA * rd_data; convert ADC bit to HVcurrent |
||
37 | |||
38 | float ADC2V = 0.0000685; |
||
39 | //rd_data = ADC2V * rd_data; convert ADC bit to inputDAC Voltage |
||
40 | |||
41 | float ADC2K = 4500; |
||
42 | // rd_data = ADC2K * rd_data/65535/2.4; convert ADC bit to TEMP(K) |
||
43 | #endif |
||
44 | |||
45 | |||
46 | // Izberi ustrezni interface v meniju projektnega okna |
||
47 | // Options->CompilerDefines (dodaj /DSISVME ali /DWIENVME) |
||
48 | #ifdef USE_DAQ |
||
49 | # define USE_CAMAC |
||
50 | # include "camac.h" |
||
51 | # ifdef SISVME |
||
52 | # include "sisWIENVME_VME_dll.h" |
||
53 | # endif |
||
54 | # ifdef WIENVME |
||
55 | //# include "wienWIENVME_VME_dll.h" |
||
56 | # include "wienvme_dll.h" |
||
57 | # endif |
||
58 | # include "CAENV965.h" |
||
59 | #endif |
||
60 | |||
61 | #ifdef USE_MIKRO |
||
62 | # include "MIKRO.h" |
||
63 | #endif |
||
64 | |||
65 | #include <userint.h> |
||
66 | #include <ansi_c.h> |
||
67 | #include <utility.h> |
||
68 | #include <analysis.h> |
||
69 | |||
70 | #include "l2d_ui.h" |
||
71 | |||
72 | #ifdef USE_DAQ |
||
73 | # define VADC_ADDR1 0x55550000 |
||
74 | # define VADC1 1 |
||
75 | //# define VADC_ADDR2 0x550000 |
||
76 | # define VADC2 2 |
||
77 | //# define NTDCJ1 17 |
||
78 | //# define NTDCJ2 18 |
||
79 | //# define NGL 23 |
||
80 | # define NPIO 23 |
||
81 | #define USE_CAEN_TDC |
||
82 | //CAEN V1290A TDC |
||
83 | #define TDC_ADDR 0x44440000 |
||
84 | #define NCH_TDC 32 |
||
85 | #define EVMAX 4 //how many of the multihit to save |
||
86 | // 0 1 2 3 4 5 6 7 8 9 A B C D E F |
||
87 | static int tdcmap[32]={ 0, 1,2, 3,4, 5,6, 7,8,9,10,11,12,13,14,15, |
||
88 | // 16 19 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
||
89 | 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}; |
||
90 | #endif |
||
91 | |||
92 | #ifdef USE_CAEN_TDC |
||
93 | // CAEN V1290 TDC |
||
94 | int V1290_writeOC(int *write_buffer); |
||
95 | int V1290_readOC(int *write_buffer); |
||
96 | void V1290_init(); |
||
97 | #endif |
||
98 | // Pomozne funkcije |
||
99 | int max_from(int* array, int ifrom, int ito); |
||
100 | |||
101 | #ifdef USE_MIKRO |
||
102 | # define MIKRO_COM 5 |
||
103 | # define MIKRO_X 1 |
||
104 | #define USE_MIKRO_Y |
||
105 | # define MIKRO_Y 2 |
||
106 | #define USE_MIKRO_Z |
||
107 | # define MIKRO_Z 3 |
||
108 | #endif |
||
109 | |||
110 | #define MAXCH_TDC 65536 |
||
111 | #define MAXCH_QDC 0x1000 |
||
112 | #define MAX_THREADS 10 |
||
113 | |||
114 | #define IWAIT 200 |
||
115 | |||
116 | # define NCH 32 |
||
117 | static int p1h, pID, rID, tfID; |
||
118 | static int ph_tdc, ph_adc; |
||
119 | static int dtdc[NCH][2][MAXCH_TDC]; |
||
120 | static int dadc[NCH][2][MAXCH_QDC]; |
||
121 | static int daq_on; |
||
122 | static int poolHandle = 0; |
||
123 | static int ntics,dummy; |
||
124 | // <- NTDCJ1 ->|<- NTDCJ2 -> |
||
125 | // 0 1 2 3 4 5 6 7 8 9 A B C D E F |
||
126 | //static int tdcmap[NCH]= { 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7 ,99,99,99,99}; |
||
127 | //static int adcmap[NCH*2]={ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15, 99,99,99,99, |
||
128 | //99,99,99,9999,99,99,9999,99,99,9999,99,99,99,99, 99,99,99,99}; |
||
129 | static int adcmap[32]={ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15, |
||
130 | 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}; |
||
131 | |||
132 | |||
133 | //static int adcmap[16]={99,99,99,99,99,99,99,99, 0, 1, 2, 3, 4, 5, 6, 7}; |
||
134 | //static int adcmap[16]={ 0, 1, 2, 3, 4, 5,99, 7, 6,99,99,99,99,99,99,99}; |
||
135 | //static int adcmap[16]={ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15}; |
||
136 | /************************************************************/ |
||
137 | void wait_loop(unsigned long iloop) |
||
138 | |||
139 | { |
||
140 | int i; |
||
141 | |||
142 | for (i=0;i<iloop;i++); |
||
143 | return; |
||
144 | } |
||
145 | |||
146 | int CVICALLBACK cb_timer (int panel, int control, int event, void *callbackData, |
||
147 | int eventData1, int eventData2) |
||
148 | { |
||
149 | QueueUserEvent (9000, p1h, P1_TIMER); |
||
150 | return (0); |
||
151 | } |
||
152 | |||
153 | int update_plots (void) |
||
154 | { |
||
155 | int irange, ch; |
||
156 | |||
157 | GetCtrlVal (p1h, P1_PLCH, &ch); |
||
158 | |||
159 | if (ph_tdc>0) DeleteGraphPlot (p1h, P1_TDC, ph_tdc, VAL_DELAYED_DRAW); |
||
160 | GetCtrlVal (p1h, P1_TDCHL, &irange); |
||
161 | ph_tdc = PlotY (p1h, P1_TDC, &dtdc[ch][irange], MAXCH_TDC, VAL_INTEGER, |
||
162 | VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED); |
||
163 | |||
164 | if (ph_adc>0) DeleteGraphPlot (p1h, P1_ADC, ph_adc, VAL_DELAYED_DRAW); |
||
165 | GetCtrlVal (p1h, P1_ADCHL, &irange); |
||
166 | ph_adc = PlotY (p1h, P1_ADC, &dadc[ch][irange], MAXCH_QDC, VAL_INTEGER, |
||
167 | VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE); |
||
168 | return (0); |
||
169 | } |
||
170 | |||
171 | int CVICALLBACK daq_run(void *functionData) |
||
172 | { |
||
173 | int i,j; |
||
174 | int ndat,dtype,ch,rg,adc,cres; |
||
175 | unsigned long a,b,ec1,ec2; |
||
176 | unsigned long data[100], data2[100]; |
||
177 | unsigned long aa[NCH][4]; |
||
178 | unsigned long step_minutes, end_time_s, cur_time_s; |
||
179 | int start_hours, start_minutes, start_seconds; |
||
180 | |||
181 | unsigned short tdcneve; |
||
182 | #ifdef USE_DAQ |
||
183 | unsigned long tdc_ev_c[NCH_TDC]; |
||
184 | #endif |
||
185 | int abstime, num_hits, tdcch; |
||
186 | int tdcbuff; |
||
187 | |||
188 | int dsave,status,fmax,fcount,fev; |
||
189 | int popupret; |
||
190 | char dfile[MAX_PATHNAME_LEN],dfile0[MAX_PATHNAME_LEN]; |
||
191 | int supr0,tdcmin,fseed,esave; |
||
192 | float frac; |
||
193 | double fracg; |
||
194 | int dum; |
||
195 | unsigned short dum16; |
||
196 | unsigned long dum32; |
||
197 | |||
198 | FILE *fp; |
||
199 | #define RUNREC_ID 1 |
||
200 | #define ENDREC_ID 2 |
||
201 | #define POSREC_ID 3 |
||
202 | #define EVTREC_ID 4 |
||
203 | |||
204 | typedef struct { |
||
205 | unsigned long id,len; |
||
206 | unsigned long fver,time; |
||
207 | unsigned long nev,nch,ped,xy; |
||
208 | long nx,x0,dx,ny,y0,dy; |
||
209 | } RUNREC; |
||
210 | RUNREC runrec; |
||
211 | |||
212 | typedef struct { |
||
213 | unsigned long id,len; |
||
214 | unsigned long time; |
||
215 | } ENDREC; |
||
216 | ENDREC endrec; |
||
217 | |||
218 | typedef struct { |
||
219 | unsigned long id,len; |
||
220 | unsigned long time; |
||
221 | long ix,x,xset,iy,y,yset; |
||
222 | } POSREC; |
||
223 | POSREC posrec; |
||
224 | |||
225 | typedef struct { |
||
226 | unsigned long id,len; |
||
227 | unsigned long nev; |
||
228 | unsigned short data[NCH*2]; |
||
229 | } EVTREC; |
||
230 | EVTREC evtrec; |
||
231 | |||
232 | runrec.id = RUNREC_ID; |
||
233 | runrec.len = sizeof(runrec); |
||
234 | runrec.fver = 0x10000; |
||
235 | runrec.nch = NCH; |
||
236 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy);//runrec.xy = 1; |
||
237 | endrec.id = ENDREC_ID; |
||
238 | endrec.len = sizeof(endrec); |
||
239 | posrec.id = POSREC_ID; |
||
240 | posrec.len = sizeof(posrec); |
||
241 | evtrec.id = EVTREC_ID; |
||
242 | evtrec.len = sizeof(evtrec); |
||
243 | /* |
||
244 | printf("<<<<<<<<<<<runrec.len %d\n",runrec.len); |
||
245 | printf("<<<<<<<<<<<endrec.len %d\n",endrec.len); |
||
246 | printf("<<<<<<<<<<<posrec.len %d\n",posrec.len); |
||
247 | printf("<<<<<<<<<<<evtrec.len %d\n",evtrec.len); |
||
248 | printf("<<<<<<<<<<<siye evtrec.len %d\n",sizeof(evtrec.len)); |
||
249 | printf("<<<<<<<<<<<siye evtrec.id %d\n",sizeof(evtrec.id)); |
||
250 | printf("<<<<<<<<<<<siye evtrec.nev %d\n",sizeof(evtrec.nev)); |
||
251 | printf("<<<<<<<<<<<siye evtrec.data %d\n",sizeof(evtrec.data)); */ |
||
252 | cres = 0; |
||
253 | |||
254 | GetCtrlVal (p1h, P1_NEVE, &runrec.nev); |
||
255 | GetCtrlVal (p1h, P1_PEDESTAL, &runrec.ped); |
||
256 | |||
257 | GetCtrlVal (p1h, P1_NX, &runrec.nx); |
||
258 | GetCtrlVal (p1h, P1_XSTEP, &runrec.dx); |
||
259 | GetCtrlVal (p1h, P1_XMIN, &runrec.x0); |
||
260 | GetCtrlVal (p1h, P1_NY, &runrec.ny); |
||
261 | GetCtrlVal (p1h, P1_YSTEP, &runrec.dy); |
||
262 | GetCtrlVal (p1h, P1_YMIN, &runrec.y0); |
||
263 | |||
264 | GetCtrlVal (p1h, P1_NMIN, &step_minutes); |
||
265 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
||
266 | //cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds; |
||
267 | time(&cur_time_s); |
||
268 | end_time_s = cur_time_s + step_minutes*60; |
||
269 | printf("START:%2d-%2d-%2d (cur_time = %u s, end_time = %u s)\n", start_hours, start_minutes, start_seconds, cur_time_s, end_time_s); |
||
270 | |||
271 | GetCtrlVal (p1h, P1_DSAVE, &dsave); |
||
272 | if (dsave) { |
||
273 | GetCtrlVal (p1h, P1_DFILE, dfile0); |
||
274 | |||
275 | fev=0; |
||
276 | fcount=1; |
||
277 | GetCtrlVal (p1h, P1_NEWF, &fmax); |
||
278 | fmax*=1000000;//fmax in Mega Bytes |
||
279 | } |
||
280 | GetCtrlVal (p1h, P1_SUPR, &supr0); |
||
281 | if (supr0) { |
||
282 | GetCtrlVal (p1h, P1_TDCMIN, &tdcmin); |
||
283 | GetCtrlVal (p1h, P1_FRAC, &frac); |
||
284 | } |
||
285 | |||
286 | #ifdef USE_DAQ |
||
287 | #ifdef VADC_ADDR1 |
||
288 | V965_map (VADC1, VADC_ADDR1, 1); |
||
289 | V965_init (VADC1, runrec.ped); |
||
290 | for(i=0;i<2*16;i++) { |
||
291 | dum16=0; |
||
292 | WIENVME_VME_A24D16_W(VADC_ADDR1 + 0x1080 + i*2, &dum16); |
||
293 | //printf("writing threshold to addr = 0x%X\n", 0x1080 + i*2); |
||
294 | } |
||
295 | #endif |
||
296 | #ifdef VADC_ADDR2 |
||
297 | V965_map (VADC2, VADC_ADDR2, 1); |
||
298 | V965_init (VADC2, runrec.ped); |
||
299 | for(i=0;i<2*16;i++) { |
||
300 | dum16=0; |
||
301 | WIENVME_VME_A24D16_W(VADC_ADDR2 + 0x1080 + i*2, &dum16); |
||
302 | //printf("writing threshold to addr = 0x%X\n", 0x1080 + i*2); |
||
303 | } |
||
304 | #endif |
||
305 | #ifdef USE_CAEN_TDC |
||
306 | dum=0; WIENVME_VME_A24D16_W(TDC_ADDR+0x1016, &dum); Delay(0.01); |
||
307 | |||
308 | |||
309 | //pair(00)/trailing(01)/leading(10)/both(11) edge |
||
310 | dum=0x2200; V1290_writeOC(&dum); |
||
311 | GetCtrlVal (p1h, P1_TDC_EDGE, &dum); |
||
312 | V1290_writeOC(&dum); |
||
313 | #endif |
||
314 | |||
315 | #ifdef USE_CAMAC |
||
316 | BZ(&cres); |
||
317 | CAMAC_cccz(&cres); |
||
318 | CAMAC_cccc(&cres); |
||
319 | CREM_I(&cres); |
||
320 | //CSSA_R(NGL,0,25,&cres); |
||
321 | #ifdef NPIO |
||
322 | //CAEN C 219 Progammable I/O |
||
323 | CSSA_R(NPIO, 0, 9, &dum);//init |
||
324 | //dum=6; //(OUTPUT, POSITIVE, NORMAL, TRANSPARENT) |
||
325 | dum=2; //(OUTPUT, NEGATIVE, NORMAL, TRANSPARENT) |
||
326 | CSSA_W(NPIO, 0, 17, &dum); |
||
327 | Delay(0.01); |
||
328 | #endif |
||
329 | Delay(0.01); |
||
330 | #ifdef NTDCJ1 |
||
331 | CSSA_R(NTDCJ1,0,9,&cres); |
||
332 | printf("CSSA_R(NTDCJ1,0,9,&cres)=0x%0x\n", cres); |
||
333 | CSSA_R(NTDCJ1,0,26,&cres); |
||
334 | CSSA_R(NTDCJ1,1,26,&cres); |
||
335 | printf("CSSA_R(NTDCJ1,0,26,&cres)=0x%0x\n", cres); |
||
336 | #endif |
||
337 | #ifdef NTDCJ2 |
||
338 | CSSA_R(NTDCJ2,0,9,&cres); |
||
339 | printf("CSSA_R(NTDCJ2,0,9,&cres)=0x%0x\n", cres); |
||
340 | CSSA_R(NTDCJ2,0,26,&cres); |
||
341 | printf("CSSA_R(NTDCJ2,0,26,&cres)=0x%0x\n", cres); |
||
342 | #endif |
||
343 | #endif |
||
344 | #endif |
||
345 | |||
346 | if (dsave) { |
||
347 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
||
348 | /* |
||
349 | // checks if file already exists and prompts user for action |
||
350 | if( fopen(dfile, "r") != NULL ) { |
||
351 | popupret = GenericMessagePopup("Warrning!", "File already exists!", |
||
352 | "New file", "Overwrite", "Cancel", 0, 1, 0, |
||
353 | VAL_GENERIC_POPUP_BTN1, VAL_GENERIC_POPUP_BTN1, VAL_GENERIC_POPUP_BTN3); |
||
354 | |||
355 | //printf("GenericMessagePopup return val = %d\n", popupret); |
||
356 | switch( popupret ) { |
||
357 | case 1: // "New file" |
||
358 | printf("last char = %c\n", dfile[strlen(dfile0)-1]); |
||
359 | break; |
||
360 | case 2: // "Overwrite" |
||
361 | break; |
||
362 | default: // "Cancel" |
||
363 | daq_on=0; |
||
364 | SetCtrlVal (p1h, P1_DAQ, daq_on); |
||
365 | return 0; |
||
366 | |||
367 | |||
368 | } |
||
369 | } |
||
370 | */ |
||
371 | fp = fopen (dfile, "wb"); |
||
372 | time (&runrec.time); |
||
373 | status = fwrite (&runrec, 1, runrec.len, fp); |
||
374 | } |
||
375 | if (supr0) { |
||
376 | fseed = runrec.time & 0x7fffffff; |
||
377 | Uniform (1, fseed, &fracg); |
||
378 | } |
||
379 | |||
380 | |||
381 | for (posrec.iy=0;posrec.iy<runrec.ny;posrec.iy++) { |
||
382 | posrec.yset=runrec.y0+posrec.iy*runrec.dy; |
||
383 | #ifdef USE_MIKRO_Y |
||
384 | // printf("MIKRO_MoveTo (2, y);%d\n",y); |
||
385 | MIKRO_MoveTo (MIKRO_Y, posrec.yset); |
||
386 | // printf("->MIKRO_MoveTo (2, y);%d\n",y); |
||
387 | #endif |
||
388 | |||
389 | SetCtrlVal (p1h, P1_Y, posrec.yset); |
||
390 | SetCtrlVal (p1h, P1_IY, posrec.iy); |
||
391 | |||
392 | |||
393 | for (posrec.ix=0;posrec.ix<runrec.nx;posrec.ix++) { |
||
394 | posrec.xset=runrec.x0+posrec.ix*runrec.dx; |
||
395 | #ifdef USE_MIKRO |
||
396 | // printf("MIKRO_MoveTo (1, x);%d\n",x); |
||
397 | MIKRO_MoveTo (MIKRO_X, posrec.xset); |
||
398 | // printf("->MIKRO_MoveTo (1, x);%d\n",x); |
||
399 | #endif |
||
400 | |||
401 | SetCtrlVal (p1h, P1_X, posrec.xset); |
||
402 | SetCtrlVal (p1h, P1_IX, posrec.ix); |
||
403 | |||
404 | |||
405 | if (dsave) { |
||
406 | /*if (fmax && (ftell(fp) > fmax)) { |
||
407 | fcount+=1; |
||
408 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
||
409 | fclose(fp); |
||
410 | fp = fopen (dfile, "wb"); |
||
411 | } */ |
||
412 | |||
413 | time (&posrec.time); |
||
414 | status = fwrite (&posrec, 1, posrec.len, fp); |
||
415 | } |
||
416 | |||
417 | // clear the plots |
||
418 | for (j=0;j<NCH;j++) { |
||
419 | for (i=0;i<MAXCH_TDC;i++){ |
||
420 | dtdc[j][0][i]=0; |
||
421 | dtdc[j][1][i]=0; |
||
422 | } |
||
423 | for (i=0;i<MAXCH_QDC;i++){ |
||
424 | dadc[j][0][i]=0; |
||
425 | dadc[j][1][i]=0; |
||
426 | } |
||
427 | } |
||
428 | |||
429 | evtrec.nev=1; |
||
430 | do { |
||
431 | for (j=0;j<NCH;j++) |
||
432 | for (i=0;i<4;i++) |
||
433 | aa[j][i]=0; |
||
434 | // if((neve%1000)==0) printf("Events %ld\n",neve); |
||
435 | |||
436 | #ifdef USE_DAQ |
||
437 | ndat = 0; |
||
438 | # ifdef VADC_ADDR1 |
||
439 | ndat=V965_clear(VADC1); |
||
440 | # endif |
||
441 | # ifdef VADC_ADDR2 |
||
442 | ndat=V965_clear(VADC2); |
||
443 | # endif |
||
444 | # ifdef USE_CAMAC |
||
445 | wait_loop(IWAIT); |
||
446 | # ifdef NTDCJ1 |
||
447 | CSSA_R(NTDCJ1,0,9,&cres); |
||
448 | # endif |
||
449 | # ifdef NTDCJ2 |
||
450 | CSSA_R(NTDCJ2,0,9,&cres); |
||
451 | # endif |
||
452 | #ifdef USE_CAEN_TDC |
||
453 | dum=0; WIENVME_VME_A24D16_W(TDC_ADDR+0x1016, &dum); //Delay(0.01); |
||
454 | #endif |
||
455 | |||
456 | // Delay(0.001); |
||
457 | wait_loop(IWAIT); |
||
458 | //CSSA_R(NGL,0,10,&cres); |
||
459 | |||
460 | |||
461 | |||
462 | # ifdef NPIO |
||
463 | dum=0x0; |
||
464 | CSSA_W(NPIO, 0, 16, &dum); |
||
465 | //printf("PIO VETO OFF\n"); |
||
466 | # endif |
||
467 | # endif |
||
468 | |||
469 | // Waiting for LAM |
||
470 | |||
471 | ntics=0; |
||
472 | |||
473 | |||
474 | //while( (!(V965_status(VADC1)&0x1)) && (ntics<2) && daq_on ); |
||
475 | |||
476 | /* |
||
477 | //tdcbuff=1; |
||
478 | #ifdef USE_CAEN_TDC |
||
479 | //dum=0x0; PCIWIENVME_VME_read16(hHandle24, 1, TDC_ADDR+0x1002, &dum);//Status Word |
||
480 | do { |
||
481 | dum16=0x0; WIENVME_VME_A24D16_R(TDC_ADDR+0x1002, &dum16); Delay(0.01); |
||
482 | //printf("tdc [%d] dum16 = %d | dum & 0x1 = %d | daq_on = %d\n", evtrec.nev, dum16, dum16 & 0x1, daq_on); |
||
483 | //tdcbuff=dum16 & 0x1;//LAM = last bit |
||
484 | } while( (!(dum16 & 0x1)) && daq_on ); |
||
485 | |||
486 | |||
487 | #endif |
||
488 | do { |
||
489 | //dum16=0x0; WIENVME_VME_A24D16_R(VADC_ADDR1+0x100E, &dum16); Delay(0.01); |
||
490 | //printf("adc [%d] dum16 = %d | dum & 0x1 = %d | VADC_ADDR1 = %x\n", evtrec.nev, dum16, dum16 & 0x1, VADC_ADDR1); |
||
491 | }while( (!(V965_status(VADC1)&0x1)) && daq_on ); |
||
492 | */ |
||
493 | //kobayashi |
||
494 | |||
495 | int tdc_lam, adc_lam; |
||
496 | #ifdef USE_CAEN_TDC |
||
497 | tdc_lam = 0; |
||
498 | #else |
||
499 | tdc_lam = 1; |
||
500 | #endif |
||
501 | #ifdef VADC_ADDR1 |
||
502 | adc_lam = 0; |
||
503 | #else |
||
504 | adc_lam = 1; |
||
505 | #endif |
||
506 | |||
507 | //printf(">>>> LAM: "); |
||
508 | #ifdef USE_CAEN_TDC |
||
509 | do { |
||
510 | dum16=0x0; WIENVME_VME_A24D16_R(TDC_ADDR+0x1002, &dum16); //Delay(0.01); |
||
511 | tdc_lam = dum16 & 0x1; |
||
512 | } while( (!tdc_lam) && daq_on ); |
||
513 | //printf("tdc_lam = %d | ", tdc_lam); |
||
514 | #endif |
||
515 | #ifdef VADC_ADDR1 |
||
516 | do { |
||
517 | adc_lam = V965_status(VADC1)&0x1; |
||
518 | } while( (!adc_lam) && daq_on ); |
||
519 | //printf("adc_lam = %d", adc_lam); |
||
520 | #endif |
||
521 | //printf("\n"); |
||
522 | |||
523 | |||
524 | # ifdef NPIO |
||
525 | dum=0x1; |
||
526 | CSSA_W(NPIO, 0, 16, &dum); |
||
527 | //printf("PIO VETO ON\n"); |
||
528 | # endif |
||
529 | |||
530 | wait_loop(2000); |
||
531 | if (!daq_on) break; |
||
532 | |||
533 | if (ntics>=2) { |
||
534 | # ifdef VADC_ADDR1 |
||
535 | ndat=V965_read (VADC1, &data[0]); |
||
536 | # endif |
||
537 | # ifdef VADC_ADDR2 |
||
538 | ndat=V965_read (VADC2, &data2[0]); |
||
539 | # endif |
||
540 | |||
541 | if(step_minutes > 0) { |
||
542 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
||
543 | //cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds; |
||
544 | time(&cur_time_s); |
||
545 | if(cur_time_s >= end_time_s) { |
||
546 | end_time_s = cur_time_s + step_minutes*60; |
||
547 | printf("STEP (lam):%2d-%2d-%2d @ %d\n", start_hours, start_minutes, start_seconds, posrec.xset); |
||
548 | break; |
||
549 | } |
||
550 | } |
||
551 | |||
552 | continue; |
||
553 | } |
||
554 | |||
555 | for (i=0; i<NCH; i++) { |
||
556 | adc=0; |
||
557 | wait_loop(IWAIT); |
||
558 | # ifdef USE_CAMAC |
||
559 | # ifdef NTDCJ1 |
||
560 | if(i<8) { |
||
561 | CSSA_R(NTDCJ1,tdcmap[i],0,&adc); |
||
562 | //printf("TDC=0x%04X\n",adc); |
||
563 | adc=adc&0xfff; |
||
564 | aa[i][0]=adc; |
||
565 | dtdc[i][0][adc]+=1; |
||
566 | } |
||
567 | # endif |
||
568 | # ifdef NTDCJ2 |
||
569 | if(8<=i && i<16) { |
||
570 | CSSA_R(NTDCJ2,tdcmap[i],0,&adc); |
||
571 | //printf("TDC=0x%04X\n",adc); |
||
572 | adc=adc&0xfff; |
||
573 | //offset for channel mapping (0-9 = MCPPMT5, 0-7 = tdc, 8,9=adc only) |
||
574 | aa[i+2][0]=adc; |
||
575 | dtdc[i+2][0][adc]+=1; |
||
576 | } |
||
577 | # endif |
||
578 | # endif |
||
579 | } |
||
580 | |||
581 | |||
582 | // TDC |
||
583 | #ifdef USE_CAEN_TDC |
||
584 | |||
585 | int dbg_tdc_t = 0; |
||
586 | int dbg_tdc_f = 0; |
||
587 | FILE *fpout=NULL; |
||
588 | if(dbg_tdc_f) fpout=fopen("TDCout.txt", "at"); |
||
589 | |||
590 | |||
591 | |||
592 | //number of events |
||
593 | //tdcneve=0; PCIWIENVME_VME_read16(hHandle24, 1, TDC_ADDR+0x1020, &tdcneve); |
||
594 | tdcneve=0; WIENVME_VME_A24D16_R(TDC_ADDR+0x1020, &tdcneve); |
||
595 | unsigned long triggneve=0; WIENVME_VME_A24D32_R(TDC_ADDR+0x101C, &triggneve); |
||
596 | if(dbg_tdc_t) printf("\n [%d] tdcneve = %u | triggneve = %u\n", evtrec.nev, tdcneve, triggneve); |
||
597 | if(dbg_tdc_f) fprintf(fpout, "\n [%d] tdcneve = %u | triggneve = %u\n", evtrec.nev, tdcneve, triggneve); |
||
598 | |||
599 | int tdcchhit[32]; |
||
600 | |||
601 | unsigned short l=0; |
||
602 | for (i=0;i<NCH_TDC;i++) |
||
603 | tdc_ev_c[i]=0; |
||
604 | while(l < tdcneve) |
||
605 | { |
||
606 | //dum=0x0; PCIWIENVME_VME_read32(hHandle24, 1, TDC_ADDR+0x0, &dum);//read |
||
607 | dum32=0x0; WIENVME_VME_A24D32_R(TDC_ADDR+0x0, &dum32); |
||
608 | |||
609 | if(dbg_tdc_t) printf(">>>>>>>>>>>>> l = %d | %x\n", l, dum32); |
||
610 | if(dbg_tdc_f) fprintf(fpout, ">>>>>>>>>>>>> l = %d | %x\n", l, dum32); |
||
611 | |||
612 | switch(dum32 & 0xf8000000) |
||
613 | { |
||
614 | case 0x40000000://01000 = Global Header |
||
615 | for (int k=0;k<32;k++) tdcchhit[k]=0; |
||
616 | if(dbg_tdc_t) printf(">>> GLOBAL HEADER | event count = %d\n", (dum32 & 0x7FFFFFF) >> 5); |
||
617 | if(dbg_tdc_f) fprintf(fpout, ">>> GLOBAL HEADER | event count = %d\n", (dum32 & 0x7FFFFFF) >> 5); |
||
618 | break; |
||
619 | case 0x8000000://00001 = TDC Header |
||
620 | if(dbg_tdc_t) printf(">>> TDC HEADER | Event ID =%d | Bunch ID = %d\n", (dum32 & 0xFFFFFF) >> 12, (dum32 & 0xFFF)); |
||
621 | if(dbg_tdc_f) fprintf(fpout, ">>> TDC HEADER | Event ID =%d | Bunch ID = %d\n", (dum32 & 0xFFFFFF) >> 12, (dum32 & 0xFFF)); |
||
622 | break; |
||
623 | case 0x00000000://00000 = TDC Measurement |
||
624 | if(dbg_tdc_t) printf(">>> TDC Measurement !!!!!!!! >>> CH = %d | edge = %d | ev = %d\n", (dum32 & 0x3FFFFFF) >> 21, (dum32 & 0x7FFFFFF) >> 26, dum32 & 0x1FFFFF); |
||
625 | if(dbg_tdc_f) fprintf(fpout, ">>> TDC Measurement !!!!!!!! >>> CH = %d | edge = %d | ev = %d\n", (dum32 & 0x3FFFFFF) >> 21, (dum32 & 0x7FFFFFF) >> 26, dum32 & 0x1FFFFF); |
||
626 | |||
627 | //TDC Channel = 0000 0x<...Channel...>x 20*x |
||
628 | tdcch = tdcmap[(dum32 & 0x3FFFFFF) >> 21]; |
||
629 | |||
630 | |||
631 | //TDC Measurement = 0000 0xxx xxx<...TDC...> |
||
632 | unsigned long tdc_ev = dum32 & 0x1FFFFF; |
||
633 | |||
634 | int tdc_edge = (dum32 & 0x1) >> 26; |
||
635 | |||
636 | /* |
||
637 | adc = (int)(tdc_ev/4.0); // 21 bit -> 16 bit ??? |
||
638 | int adcs = (int)(adc/16.0); |
||
639 | */ |
||
640 | /* |
||
641 | int tdc_ev_offset = 31000; |
||
642 | adc = tdc_ev - tdc_ev_offset; |
||
643 | int adcs = 0; |
||
644 | if(0 < adc) adcs = adc; |
||
645 | if(4095 < adc) adcs = 4095; |
||
646 | */ |
||
647 | |||
648 | if(dbg_tdc_t) printf(">>> tdcch = %d | tdc_ev = %d | raw = %d\n", tdcch, tdc_ev, dum32); |
||
649 | if(dbg_tdc_f) fprintf(fpout, ">>> tdcch = %d | tdc_ev = %d | raw = %d\n", tdcch, tdc_ev, dum32); |
||
650 | |||
651 | if(l==0) |
||
652 | if(tdcchhit[tdcch]==0) |
||
653 | if(tdc_edge==0) { |
||
654 | if(tdcch < NCH_TDC) { |
||
655 | aa[tdcch][0]=tdc_ev; |
||
656 | if(tdcch < MAXCH_TDC) { |
||
657 | dtdc[tdcch][0][tdc_ev]+=1; |
||
658 | } |
||
659 | } |
||
660 | } |
||
661 | tdcchhit[tdcch]=1; |
||
662 | |||
663 | break; |
||
664 | case 0x18000000://00011 = TDC Trailer |
||
665 | if(dbg_tdc_t) printf(">>> TDC Trailer | Event ID =%d\n", (dum32 & 0xFFFFFF) >> 12); |
||
666 | if(dbg_tdc_f) fprintf(fpout, ">>> TDC Trailer | Event ID =%d\n", (dum32 & 0xFFFFFF) >> 12); |
||
667 | break; |
||
668 | case 0x20000000://00100 = TDC Error |
||
669 | if(dbg_tdc_t) printf(">>> TDC Error = %d\n", dum32 & 0x7FFF); |
||
670 | if(dbg_tdc_f) fprintf(fpout, ">>> TDC Error = %d\n", dum32 & 0x7FFF); |
||
671 | break; |
||
672 | case 0x88000000://10001 = Extended Trigger Time Tag |
||
673 | if(dbg_tdc_t) printf(">>> Extended Trigger Time Tag \n"); |
||
674 | if(dbg_tdc_f) fprintf(fpout, ">>> Extended Trigger Time Tag \n"); |
||
675 | break; |
||
676 | case 0xC0000000://11000 = Filler |
||
677 | if(dbg_tdc_t) printf(">>> Filler \n"); |
||
678 | if(dbg_tdc_f) fprintf(fpout, ">>> Filler \n"); |
||
679 | break; |
||
680 | case 0x80000000://10000 = The Trailer |
||
681 | num_hits=((dum32 & 0x1FFFFF) >> 5) - 2; |
||
682 | l++; |
||
683 | if(dbg_tdc_t) printf(">>> The Trailer | status bits: %d%d%d | num_hits = %d\n", (dum32 >> 26) % 0x1, (dum32 >> 25) % 0x1, (dum32 >> 24) % 0x1, num_hits); |
||
684 | if(dbg_tdc_f) fprintf(fpout, ">>> The Trailer | num_hits = %d\n", num_hits); |
||
685 | break; |
||
686 | /* |
||
687 | case 0x00000000://00000 = TDC Measurement |
||
688 | //TDC Channel = 0000 0x<...Channel...>x 20*x |
||
689 | tdcch = tdcmap[(dum32 & 0x3FFFFFF) >> 21]; |
||
690 | //TDC Measurement = 0000 0xxx xxx<...TDC...> |
||
691 | tdc_ev = dum32 & 0x1FFFFF; |
||
692 | if((tdcch < NCH_TDC)&&(tdc_ev < MAXCH_TDC)&&(tdc_ev_c[tdcch] < EVMAX)) |
||
693 | { |
||
694 | dtdc[tdcch][tdc_ev_c[tdcch]][tdc_ev]++; |
||
695 | //atdc[tdcch][tdc_ev_c[tdcch]++] = tdc_ev; |
||
696 | } |
||
697 | |||
698 | //#define CH_TRG 0 |
||
699 | //#define CH_SIPM 1 |
||
700 | //#define CH_PMT 2 |
||
701 | |||
702 | //for(i=1;i<NCH_TDC;i++) |
||
703 | // if(tdc_ev_c[CH_TRG] && tdc_ev_c[i]) |
||
704 | // { |
||
705 | // abstime=atdc[i][tdc_ev_c[i]-1] - atdc[CH_TRG][tdc_ev_c[CH_TRG]-1] + 30000; |
||
706 | // if((0 <= abstime) && (abstime < MAXCH_TDC)) |
||
707 | // dtdc2[i][tdc_ev_c[i]-1][abstime]++; |
||
708 | // } |
||
709 | |||
710 | break; |
||
711 | case 0x80000000://10000 = Global Trailer |
||
712 | //Word Count = bit 31...21< Word Count: 20 ... 5 > 4...0 |
||
713 | num_hits=((dum32 & 0x1FFFFF) >> 5) - 2; |
||
714 | l++; |
||
715 | break; |
||
716 | case 0xC0000000://11000 = Filler |
||
717 | l=tdcneve;//exit while loop |
||
718 | break; */ |
||
719 | default: |
||
720 | break; |
||
721 | } |
||
722 | } |
||
723 | |||
724 | if(dbg_tdc_f) fclose(fpout); |
||
725 | #endif |
||
726 | |||
727 | # ifdef VADC_ADDR1 |
||
728 | ndat=V965_read (VADC1, &data[0]); |
||
729 | //printf("<<<<<ndat %d\n",ndat); |
||
730 | for (i=0; i<ndat; i++) { |
||
731 | dtype=(data[i]>>25)&0x3; |
||
732 | if (dtype==0) { |
||
733 | ch=adcmap[(data[i]>>17)&0xf]; |
||
734 | if (ch<NCH) { |
||
735 | rg=(data[i]>>16)&0x1; |
||
736 | adc=data[i]&0xfff; |
||
737 | aa[ch][rg+2]=adc; |
||
738 | dadc[ch][rg][adc]+=1; |
||
739 | //printf("<<<<<ch %d rg %d adc %d map %d\n",ch,rg,adc, (data[i]>>17)&0xf); |
||
740 | } |
||
741 | } |
||
742 | } |
||
743 | //printf("VADC_ADDR1 READ\n"); |
||
744 | # endif |
||
745 | // printf("======================================\n"); |
||
746 | # ifdef VADC_ADDR2 |
||
747 | ndat=V965_read (VADC2, &data2[0]); |
||
748 | for (i=0; i<ndat; i++) { |
||
749 | dtype=(data2[i]>>25)&0x3; |
||
750 | if (dtype==0) { |
||
751 | ch=adcmap[NCH + ((data2[i]>>17)&0xf)]; |
||
752 | |||
753 | //printf("ADCCH = %2d , adcmap[ADCCH] = %2d , ADC = %d\n", NCH + ((data2[i]>>17)&0xf), ch, data2[i]&0xfff); |
||
754 | |||
755 | if (ch<NCH) { |
||
756 | rg=(data2[i]>>16)&0x1; |
||
757 | adc=data2[i]&0xfff; |
||
758 | aa[ch][rg+2]=adc; |
||
759 | dadc[ch][rg][adc]+=1; |
||
760 | } |
||
761 | } |
||
762 | } |
||
763 | # endif |
||
764 | |||
765 | #else /* generate test data */ |
||
766 | if (!daq_on) break; |
||
767 | for (i=0;i<NCH;i++) { |
||
768 | adc=100+evtrec.nev%200; |
||
769 | dtdc[i][1][adc]+=1; |
||
770 | dadc[i][1][adc]+=1; |
||
771 | aa[i][0]=adc; |
||
772 | aa[i][2]=adc; |
||
773 | adc=200+evtrec.nev%400; |
||
774 | dtdc[i][0][adc]+=1; |
||
775 | dadc[i][0][adc]+=1; |
||
776 | aa[i][1]=adc; |
||
777 | aa[i][3]=adc; |
||
778 | } |
||
779 | #endif |
||
780 | esave=dsave; |
||
781 | if (supr0 && esave) { |
||
782 | Uniform (1, -1, &fracg); |
||
783 | if (fracg > frac) { |
||
784 | esave=0; |
||
785 | for (i=0;i<NCH;i++) { |
||
786 | if (aa[i][0] >= tdcmin) esave=1; |
||
787 | } |
||
788 | } |
||
789 | } |
||
790 | if (esave) { |
||
791 | // time (&evtrec.time); |
||
792 | //GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy); |
||
793 | for (i=0;i<NCH;i++) { |
||
794 | evtrec.data[i] = aa[i][0]; //TDC |
||
795 | //printf(">>> TDC Measurement !!!!!!!! >>> CH = %d | ev = %d\n", i, evtrec.data[i]); |
||
796 | //if(i==0) |
||
797 | // evtrec.data[i+NCH] = aa[i][2]; //ADC High Range = 2 , low = 3 |
||
798 | //else |
||
799 | evtrec.data[i+NCH] = aa[i][2]; //ADC High Range = 2 , low = 3 |
||
800 | // printf(">>> ADC Measurement !!!!!!!! >>> CH = %d | ev = %d \n", i, evtrec.data[i+NCH]); |
||
801 | //printf("<<<<<<<<<<<evtrec.len %d\n",evtrec.len); |
||
802 | } |
||
803 | status = fwrite (&evtrec, 1, evtrec.len, fp); |
||
804 | } |
||
805 | |||
806 | //if (!(evtrec.nev%1000)) |
||
807 | SetCtrlVal (p1h, P1_CEVE, evtrec.nev); |
||
808 | |||
809 | if (dsave&&(!(evtrec.nev%1000))) { |
||
810 | if (fmax && (ftell(fp) > fmax)) { |
||
811 | time (&endrec.time); |
||
812 | status = fwrite (&endrec, 1, endrec.len, fp); |
||
813 | fcount+=1; |
||
814 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
||
815 | fclose(fp); |
||
816 | fp = fopen (dfile, "wb"); |
||
817 | printf(" Opened file %s\n", dfile); |
||
818 | } |
||
819 | } |
||
820 | |||
821 | if(step_minutes > 0) { |
||
822 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
||
823 | //cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds; |
||
824 | time(&cur_time_s); |
||
825 | if(cur_time_s >= end_time_s) { |
||
826 | end_time_s = cur_time_s + step_minutes*60; |
||
827 | printf("STEP (nev):%2d-%2d-%2d @ %d\n", start_hours, start_minutes, start_seconds, posrec.xset); |
||
828 | break; |
||
829 | } |
||
830 | } |
||
831 | |||
832 | |||
833 | } while (evtrec.nev++<runrec.nev); |
||
834 | if (!daq_on) break; |
||
835 | } |
||
836 | if (!daq_on) break; |
||
837 | } |
||
838 | |||
839 | if (dsave) { |
||
840 | time (&endrec.time); |
||
841 | status = fwrite (&endrec, 1, endrec.len, fp); |
||
842 | fclose(fp); |
||
843 | } |
||
844 | |||
845 | daq_on=0; |
||
846 | SetCtrlVal (p1h, P1_DAQ, daq_on); |
||
847 | SetCtrlVal (p1h, P1_CEVE, evtrec.nev); |
||
848 | |||
849 | return 0; |
||
850 | } |
||
851 | |||
852 | //================================================================================= |
||
853 | //================================================================================= |
||
854 | //================================================================================= |
||
855 | |||
856 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
||
857 | LPSTR lpszCmdLine, int nCmdShow) |
||
858 | { |
||
859 | int i,j,status,refon; |
||
860 | long int xpos, ypos, zpos; |
||
861 | char dfile[300]; |
||
862 | FILE *fp; |
||
863 | int dum; |
||
864 | unsigned short dum16; |
||
865 | |||
866 | typedef struct { |
||
867 | unsigned long id,len; |
||
868 | unsigned long fver,time; |
||
869 | unsigned long nev,nch,ped,xy; |
||
870 | long nx,x0,dx,ny,y0,dy; |
||
871 | } RUNREC; |
||
872 | RUNREC runrec; |
||
873 | |||
874 | if (InitCVIRTE (hInstance, 0, 0) == 0) |
||
875 | return -1; /* out of memory */ |
||
876 | |||
877 | SetSleepPolicy(VAL_SLEEP_MORE); |
||
878 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
||
879 | |||
880 | SetStdioWindowOptions (1000, 0, 0); |
||
881 | //SetStdioWindowSize (150, 600); |
||
882 | //SetStdioWindowPosition (825, 250); |
||
883 | SetStdioWindowSize (900, 600); |
||
884 | //SetStdioWindowPosition (20, 800); |
||
885 | SetStdioWindowPosition (20, 1100); |
||
886 | |||
887 | #ifdef USE_DAQ |
||
888 | WIENVME_VME_START(NULL); |
||
889 | #endif |
||
890 | |||
891 | #ifdef USE_CAEN_TDC |
||
892 | V1290_init(); |
||
893 | #endif |
||
894 | |||
895 | #ifdef USE_MIKRO |
||
896 | MIKRO_Open (MIKRO_COM); |
||
897 | MIKRO_Init (MIKRO_X,0); |
||
898 | #ifdef USE_MIKRO_Y |
||
899 | MIKRO_Init (MIKRO_Y,0); |
||
900 | #endif |
||
901 | #ifdef USE_MIKRO_Z |
||
902 | MIKRO_Init (MIKRO_Z,0); |
||
903 | #endif |
||
904 | #endif |
||
905 | |||
906 | if ((p1h = LoadPanel (0, "l2d_ui.uir", P1)) < 0) return -1; |
||
907 | DisplayPanel (p1h); |
||
908 | SetCtrlAttribute (p1h, P1_PLCH, ATTR_MAX_VALUE, NCH-1); |
||
909 | |||
910 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy); |
||
911 | SetCtrlVal(p1h, P1_ADCHL, runrec.xy-2); |
||
912 | |||
913 | QueueUserEvent (1000, p1h, P1_RESET); |
||
914 | |||
915 | do { |
||
916 | GetUserEvent (1, &pID, &rID); |
||
917 | switch (rID) { |
||
918 | case P1_TIMER: |
||
919 | ntics+=1; |
||
920 | GetCtrlVal (p1h, P1_REFON, &refon); |
||
921 | if (refon) update_plots(); |
||
922 | break; |
||
923 | case P1_REFRESH: |
||
924 | update_plots(); |
||
925 | break; |
||
926 | case P1_DAQ: |
||
927 | GetCtrlVal (p1h, P1_DAQ, &daq_on); |
||
928 | if (daq_on) { |
||
929 | CmtScheduleThreadPoolFunction (poolHandle, daq_run, (void *)&dummy, &tfID); |
||
930 | } else { |
||
931 | CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID, |
||
932 | OPT_TP_PROCESS_EVENTS_WHILE_WAITING); |
||
933 | CmtReleaseThreadPoolFunctionID (poolHandle, tfID); |
||
934 | # ifdef NPIO |
||
935 | dum=0x0; |
||
936 | CSSA_W(NPIO, 0, 16, &dum); |
||
937 | //printf("PIO VETO OFF\n"); |
||
938 | # endif |
||
939 | } |
||
940 | break; |
||
941 | case P1_ZSET: |
||
942 | if (!daq_on) { |
||
943 | GetCtrlVal (p1h, P1_ZSET, &zpos); |
||
944 | #ifdef USE_MIKRO_Z |
||
945 | MIKRO_MoveTo (MIKRO_Z, zpos); |
||
946 | #endif |
||
947 | } |
||
948 | break; |
||
949 | case P1_REREAD: |
||
950 | if (!daq_on) { |
||
951 | status = FileSelectPopup ("", "*.dat", ".dat", |
||
952 | "Izberi datoteko s podatki", |
||
953 | VAL_LOAD_BUTTON, 0, 0, 1, 0, dfile); |
||
954 | if (status==1) { |
||
955 | fp = fopen (dfile, "rb"); |
||
956 | status = fread (&runrec, 1, sizeof(runrec), fp); |
||
957 | fclose(fp); |
||
958 | if (runrec.id==1) { |
||
959 | SetCtrlVal (p1h, P1_NX, runrec.nx); |
||
960 | SetCtrlVal (p1h, P1_XSTEP, runrec.dx); |
||
961 | SetCtrlVal (p1h, P1_XMIN, runrec.x0); |
||
962 | SetCtrlVal (p1h, P1_NY, runrec.ny); |
||
963 | SetCtrlVal (p1h, P1_YSTEP, runrec.dy); |
||
964 | SetCtrlVal (p1h, P1_YMIN, runrec.y0); |
||
965 | SetCtrlVal (p1h, P1_NEVE, runrec.nev); |
||
966 | } |
||
967 | } |
||
968 | } |
||
969 | break; |
||
970 | case P1_MGET: |
||
971 | #ifdef USE_MIKRO |
||
972 | MIKRO_GetPosition(MIKRO_X,&xpos); |
||
973 | Delay(0.01); |
||
974 | SetCtrlVal (p1h, P1_X, xpos); |
||
975 | #ifdef USE_MIKRO_Y |
||
976 | MIKRO_GetPosition(MIKRO_Y,&ypos); |
||
977 | Delay(0.01); |
||
978 | SetCtrlVal (p1h, P1_Y, ypos); |
||
979 | #endif |
||
980 | #ifdef USE_MIKRO_Z |
||
981 | MIKRO_GetPosition(MIKRO_Z,&zpos); |
||
982 | Delay(0.01); |
||
983 | SetCtrlVal (p1h, P1_Z, zpos); |
||
984 | #endif |
||
985 | #endif |
||
986 | break; |
||
987 | case P1_HO: |
||
988 | if (!daq_on) { |
||
989 | SetWaitCursor (1); |
||
990 | #ifdef USE_MIKRO |
||
991 | MIKRO_ReferenceMove (MIKRO_X); |
||
992 | #ifdef USE_MIKRO_Y |
||
993 | MIKRO_ReferenceMove (MIKRO_Y); |
||
994 | #endif |
||
995 | #ifdef USE_MIKRO_Z |
||
996 | MIKRO_ReferenceMove (MIKRO_Z); |
||
997 | #endif |
||
998 | #endif |
||
999 | SetWaitCursor (0); |
||
1000 | } |
||
1001 | break; |
||
1002 | case P1_RESET: |
||
1003 | for (j=0;j<NCH;j++) { |
||
1004 | for (i=0;i<MAXCH_TDC;i++){ |
||
1005 | dtdc[j][0][i]=0; |
||
1006 | dtdc[j][1][i]=0; |
||
1007 | } |
||
1008 | for (i=0;i<MAXCH_QDC;i++){ |
||
1009 | dadc[j][0][i]=0; |
||
1010 | dadc[j][1][i]=0; |
||
1011 | } |
||
1012 | } |
||
1013 | update_plots(); |
||
1014 | break; |
||
1015 | case P1_TDCLOG: |
||
1016 | GetCtrlVal (p1h, P1_TDCLOG, &status); |
||
1017 | SetCtrlAttribute (p1h, P1_TDC, ATTR_YMAP_MODE, status); |
||
1018 | update_plots(); |
||
1019 | break; |
||
1020 | case P1_ADCLOG: |
||
1021 | GetCtrlVal (p1h, P1_ADCLOG, &status); |
||
1022 | SetCtrlAttribute (p1h, P1_ADC, ATTR_YMAP_MODE, status); |
||
1023 | update_plots(); |
||
1024 | break; |
||
1025 | case P1_PIO_ON: |
||
1026 | # ifdef NPIO |
||
1027 | dum=0x1; |
||
1028 | CSSA_W(NPIO, 0, 16, &dum); |
||
1029 | printf("PIO VETO ON\n"); |
||
1030 | # endif |
||
1031 | break; |
||
1032 | case P1_PIO_OFF: |
||
1033 | # ifdef NPIO |
||
1034 | dum=0x0; |
||
1035 | CSSA_W(NPIO, 0, 16, &dum); |
||
1036 | printf("PIO VETO OFF\n"); |
||
1037 | # endif |
||
1038 | break; |
||
1039 | case P1_TDCCLEAR: |
||
1040 | #ifdef USE_CAEN_TDC |
||
1041 | dum16=0x0; WIENVME_VME_A24D16_W(TDC_ADDR+0x1014, &dum16); Delay(0.1); |
||
1042 | dum16=0x0; WIENVME_VME_A24D16_W(TDC_ADDR+0x1016, &dum16); Delay(0.1); |
||
1043 | dum16=0x0; WIENVME_VME_A24D16_W(TDC_ADDR+0x1018, &dum16); Delay(0.1); |
||
1044 | #endif |
||
1045 | break; |
||
1046 | case P1_TDCMIKRO: |
||
1047 | #ifdef USE_CAEN_TDC |
||
1048 | dum=0x0000; WIENVME_VME_A24D16_R(TDC_ADDR + 0x1030, &dum); Delay(0.01); printf("Micro handshake = %x\n", dum); |
||
1049 | #endif |
||
1050 | break; |
||
1051 | case P1_TDCINIT: |
||
1052 | |||
1053 | #ifdef USE_CAEN_TDC |
||
1054 | //V1290_init() ; |
||
1055 | |||
1056 | ////Maximum number of hits per event |
||
1057 | printf("V1290_writeOC(0x3300)\n"); |
||
1058 | dum=0x3300; V1290_writeOC(&dum); Delay(0.1); |
||
1059 | //dum=0x0001; V1290_writeOC(&dum); Delay(0.1); |
||
1060 | printf("V1290_writeOC(0x1000)\n"); |
||
1061 | dum=0x1000; V1290_writeOC(&dum); Delay(0.1); |
||
1062 | printf("V1290_writeOC(0x3400)\n"); |
||
1063 | dum=0x3400; V1290_writeOC(&dum); Delay(0.1); |
||
1064 | dum=0x0; |
||
1065 | printf("V1290_readOC()\n"); |
||
1066 | if(V1290_readOC(&dum) == -1) |
||
1067 | printf("V1290_readOC timeout!!!\n"); |
||
1068 | else { |
||
1069 | Delay(0.1); |
||
1070 | printf("TDC Maximum number of hits per event = %d\n", dum); |
||
1071 | } |
||
1072 | |||
1073 | #endif |
||
1074 | break; |
||
1075 | case P1_TDCTEST: |
||
1076 | |||
1077 | #ifdef USE_CAEN_TDC |
||
1078 | /* |
||
1079 | for (i=0x4000;i<0x4050;i+=4) { |
||
1080 | dum=0; |
||
1081 | WIENVME_VME_A24D16_R(TDC_ADDR+i, &dum); |
||
1082 | printf("0x%04X -> 0x%04X\n",i,dum); |
||
1083 | } |
||
1084 | for (i=0x4080;i<0x4088;i+=4) { |
||
1085 | dum=0; |
||
1086 | WIENVME_VME_A24D16_R(TDC_ADDR+i, &dum); |
||
1087 | printf("0x%04X -> 0x%04X\n",i,dum); |
||
1088 | } |
||
1089 | dum=0;i=0x1026; |
||
1090 | WIENVME_VME_A24D16_R(TDC_ADDR+i, &dum); |
||
1091 | printf("0x%04X -> 0x%04X\n",i,dum); |
||
1092 | |||
1093 | |||
1094 | dum=0x0200; V1290_writeOC(&dum); |
||
1095 | dum=0x0; V1290_readOC(&dum); printf("dum = %04X\n", dum&0xFFFF); |
||
1096 | */ |
||
1097 | |||
1098 | dum=0x4500; V1290_writeOC(&dum); |
||
1099 | dum=0x0; V1290_readOC(&dum); printf("Ch Enable 1 = %04X\n", dum&0xFFFF); |
||
1100 | dum=0x0; V1290_readOC(&dum); printf("Ch Enable 2 = %04X\n", dum&0xFFFF); |
||
1101 | |||
1102 | |||
1103 | dum=0x1600; V1290_writeOC(&dum); |
||
1104 | dum=0x0000; V1290_readOC(&dum); printf("Match window Width = %d\n", dum&0xFFFF); |
||
1105 | dum=0x0000; V1290_readOC(&dum); printf("Window Offset = %d\n", dum&0xFFFF); |
||
1106 | dum=0x0000; V1290_readOC(&dum); printf("Extra Search Window = %d\n", dum&0xFFFF); |
||
1107 | dum=0x0000; V1290_readOC(&dum); printf("Reject Margin = %d\n", dum&0xFFFF); |
||
1108 | dum=0x0000; V1290_readOC(&dum); printf("Trigger Subtraction = %d\n", dum&0xFFFF); |
||
1109 | |||
1110 | |||
1111 | dum=0x3400; V1290_writeOC(&dum); |
||
1112 | dum=0x0000; V1290_readOC(&dum); printf("TDC Maximum number of hits per event = %d\n", dum); |
||
1113 | |||
1114 | |||
1115 | /* |
||
1116 | // test |
||
1117 | |||
1118 | dum16=0x0; WIENVME_VME_A24D16_R(TDC_ADDR+0x1026, &dum16); Delay(0.1); |
||
1119 | printf("WIENVME_VME_A24D16_R(TDC_ADDR+0x1026, dum16) -> %d\n", dum16); |
||
1120 | |||
1121 | //dum=0x20; WIENVME_VME_A24D16_W(TDC_ADDR+0x1000, &dum); Delay(0.1); |
||
1122 | |||
1123 | dum=0x0; WIENVME_VME_A24D16_R(TDC_ADDR+0x1000, &dum); Delay(0.1); |
||
1124 | printf("WIENVME_VME_A24D16_R(TDC_ADDR+0x1000, dum) -> %d\n", dum); |
||
1125 | |||
1126 | dum=0x0; WIENVME_VME_A24D16_R(TDC_ADDR+0x1002, &dum); Delay(0.1); |
||
1127 | printf("WIENVME_VME_A24D16_R(TDC_ADDR+0x1002, dum) -> %d\n", dum); |
||
1128 | |||
1129 | int tdcneve=0; WIENVME_VME_A24D16_R(TDC_ADDR+0x1020, &tdcneve); |
||
1130 | unsigned long triggneve=0; WIENVME_VME_A24D32_R(TDC_ADDR+0x101C, &triggneve); |
||
1131 | printf("tdcneve = %d | triggneve = %u\n", tdcneve, triggneve); |
||
1132 | |||
1133 | dum=0x4500; V1290_writeOC(&dum); |
||
1134 | dum=0x0; V1290_readOC(&dum); printf("Channel enable mask word 1 = %x\n", dum); |
||
1135 | dum=0x0; V1290_readOC(&dum); printf("Channel enable mask word 2 = %x\n", dum); |
||
1136 | |||
1137 | //dum=0x4500; WIENVME_VME_A24D16_W(TDC_ADDR+0x102E, &dum); Delay(0.1); |
||
1138 | //dum=0x0000; WIENVME_VME_A24D16_R(TDC_ADDR+0x102E, &dum); Delay(0.1); printf("Channel enable mask word 1 = %x\n", dum); |
||
1139 | //dum=0x0000; WIENVME_VME_A24D16_R(TDC_ADDR+0x102E, &dum); Delay(0.1); printf("Channel enable mask word 2 = %x\n", dum); |
||
1140 | |||
1141 | */ |
||
1142 | |||
1143 | //dum16=0x0; WIENVME_VME_A24D16_R(VADC_ADDR1+0x1000, &dum16); Delay(0.1); |
||
1144 | //printf("WIENVME_VME_A24D16_R(VADC_ADDR1+0x1000, dum16) -> %x\n", dum16); |
||
1145 | /* |
||
1146 | dum=0xC200; V1290_writeOC(&dum); printf("V1290_writeOC(&dum) -> %d\n", dum); |
||
1147 | dum=0x0; V1290_readOC(&dum); printf("1. V1290_readOC(&dum) -> %d\n", dum); |
||
1148 | dum=0x0; V1290_readOC(&dum); printf("2. V1290_readOC(&dum) -> %d\n", dum); |
||
1149 | dum=0x0; V1290_readOC(&dum); printf("3. V1290_readOC(&dum) -> %d\n", dum); |
||
1150 | dum=0x0; V1290_readOC(&dum); printf("4. V1290_readOC(&dum) -> %d\n", dum); |
||
1151 | |||
1152 | dum16=0xC200; WIENVME_VME_A24D16_W(TDC_ADDR+0xC200, &dum16); Delay(0.1); |
||
1153 | printf("WIENVME_VME_A24D16_W(TDC_ADDR+0xC200, dum) -> %x\n", dum16); |
||
1154 | dum16=0x0; WIENVME_VME_A24D16_R(TDC_ADDR+0xC200, &dum16); Delay(0.1); |
||
1155 | printf("1. WIENVME_VME_A24D16_R(TDC_ADDR+0xC200, dum) -> %x\n", dum16); |
||
1156 | dum16=0x0; WIENVME_VME_A24D16_R(TDC_ADDR+0xC200, &dum16); Delay(0.1); |
||
1157 | printf("2. WIENVME_VME_A24D16_R(TDC_ADDR+0xC200, dum16) -> %x\n", dum16); |
||
1158 | dum16=0x0; WIENVME_VME_A24D16_R(TDC_ADDR+0xC200, &dum16); Delay(0.1); |
||
1159 | printf("3. WIENVME_VME_A24D16_R(TDC_ADDR+0xC200, dum16) -> %x\n", dum16); |
||
1160 | dum16=0x0; WIENVME_VME_A24D16_R(TDC_ADDR+0xC200, &dum16); Delay(0.1); |
||
1161 | printf("4. WIENVME_VME_A24D16_R(TDC_ADDR+0xC200, dum16) -> %x\n", dum16); */ |
||
1162 | |||
1163 | #endif |
||
1164 | break; |
||
1165 | #ifdef USE_EASIROC |
||
1166 | case P1_ESRC_INIT: |
||
1167 | easiroc_Init(erIpAddr, erDAQmode); |
||
1168 | break; |
||
1169 | |||
1170 | case P1_ESRC_F1: |
||
1171 | easiroc_fTransmitSC(); |
||
1172 | break; |
||
1173 | |||
1174 | case P1_ESRC_F2: |
||
1175 | easiroc_fTransmitReadSC(); |
||
1176 | break; |
||
1177 | |||
1178 | case P1_ESRC_F3: |
||
1179 | easiroc_fAsicInitialize(); |
||
1180 | break; |
||
1181 | |||
1182 | case P1_ESRC_F4: |
||
1183 | int transmitProbeCh = 0; |
||
1184 | GetCtrlVal (p1h, P1_ESRC_PROBE_CH, &transmitProbeCh); |
||
1185 | int transmitProbeType = 0; |
||
1186 | GetCtrlVal (p1h, P1_ESRC_PROBE_TYPE, &transmitProbeType); |
||
1187 | |||
1188 | printf("transmitProbeCh = %d | transmitProbeType = %d\n", transmitProbeCh, transmitProbeType); |
||
1189 | if(easiroc_fTransmitProbe(transmitProbeCh, transmitProbeType) == 0) |
||
1190 | printf("\nTransmit Probe SUCESS\n"); |
||
1191 | break; |
||
1192 | |||
1193 | case P1_ESRC_DAQ: |
||
1194 | char esrcDaqFile[256]; |
||
1195 | GetCtrlVal (p1h, P1_DFILE, esrcDaqFile); |
||
1196 | int esrcDaqNeve = 0; |
||
1197 | GetCtrlVal (p1h, P1_NEVE, &esrcDaqNeve); |
||
1198 | |||
1199 | if(easiroc_fDAQ(esrcDaqFile, esrcDaqNeve) == 0) |
||
1200 | printf("\nEASIROC DAQ SUCESS\n"); |
||
1201 | break; |
||
1202 | |||
1203 | case P1_ESRC_CLOSE: |
||
1204 | easiroc_Close(); |
||
1205 | break; |
||
1206 | #endif |
||
1207 | #ifdef USE_UDPCONTROL |
||
1208 | case P1_ER_INIT: |
||
1209 | SiTCPinit(); |
||
1210 | SiTCPSetIPPort(IpAddr, tcpport, udpport); |
||
1211 | // SiTCPCreateTCPSock(); |
||
1212 | SiTCPCreateUDPSock(); |
||
1213 | |||
1214 | SenderInit(); |
||
1215 | Senderudp_send(0x00000012,248); //Set ADC rate to 50Hz |
||
1216 | Senderudp_send(0x0000001f,0); |
||
1217 | break; |
||
1218 | case P1_ER_CLOSE: |
||
1219 | SiTCPclose(); |
||
1220 | SenderClose(); |
||
1221 | break; |
||
1222 | case P1_ER_HV_CONTROL: |
||
1223 | GetCtrlVal (p1h, P1_ER_HV_CONTROL_IN, &HV); |
||
1224 | |||
1225 | HVDAC = HVC_1 * HV + HVC_2; //change HV to DAC bit |
||
1226 | |||
1227 | printf("P1_ER_HV_CONTROL: HV = %lf | HVDAC = %d\n", HV, HVDAC); |
||
1228 | |||
1229 | Senderudp_send(0x00000010,HVDAC/256);//Set higher 8bit to FPGA reg |
||
1230 | Senderudp_send(0x00000011,HVDAC%256);//lower 8bit |
||
1231 | Senderudp_send(0x0000001e,1); //Start DAC control |
||
1232 | break; |
||
1233 | case P1_ER_HV_STATUS: |
||
1234 | rd_data = Senderread_madc(3);//Read ADC data |
||
1235 | // std::cout <<"MADC_data = "<< rd_data; |
||
1236 | rd_data = ADC2HV * rd_data; //convert ADC bit to HV |
||
1237 | printf("Bias voltage : %.2lfV\n",rd_data); |
||
1238 | |||
1239 | rd_data = Senderread_madc(4);//Read ADC data |
||
1240 | //std::cout <<"MADC_data = "<< rd_data; |
||
1241 | rd_data = ADC2uA * rd_data; //convert ADC bit to HVcurrent |
||
1242 | printf("Bias current : %.2lfuA\n",rd_data); |
||
1243 | break; |
||
1244 | #endif |
||
1245 | |||
1246 | } |
||
1247 | |||
1248 | } while ((rID != P1_EXIT)||daq_on); |
||
1249 | |||
1250 | CmtDiscardThreadPool (poolHandle); |
||
1251 | DiscardPanel (p1h); |
||
1252 | |||
1253 | #ifdef USE_MIKRO |
||
1254 | MIKRO_Close (); |
||
1255 | #endif |
||
1256 | |||
1257 | #ifdef USE_DAQ |
||
1258 | WIENVME_VME_STOP(); |
||
1259 | #endif |
||
1260 | return 0; |
||
1261 | |||
1262 | } |
||
1263 | |||
1264 | #ifdef USE_CAEN_TDC |
||
1265 | /* ****************** CAEN V1290 TDC Write OPCODE****************** */ |
||
1266 | int V1290_writeOC(int *write_buffer) |
||
1267 | { |
||
1268 | //printf(">>> Writing %d\n", *write_buffer); |
||
1269 | int wait_count = 0; |
||
1270 | int read_buffer = 0; |
||
1271 | do |
||
1272 | { |
||
1273 | // Micro Handshake Register |
||
1274 | WIENVME_VME_A24D16_R(TDC_ADDR + 0x1030, &read_buffer); Delay(0.01); |
||
1275 | //printf("V1290_writeOC wait_count = %d | read_buffer = %x\n", wait_count, read_buffer); |
||
1276 | if(100 < wait_count++) |
||
1277 | return -1; |
||
1278 | |||
1279 | } while (!(read_buffer & 0x1)); |
||
1280 | |||
1281 | // Micro Register |
||
1282 | WIENVME_VME_A24D16_W(TDC_ADDR + 0x102E, write_buffer); |
||
1283 | |||
1284 | return 0; |
||
1285 | } |
||
1286 | /* ****************** CAEN V1290 TDC Read OPCODE ****************** */ |
||
1287 | int V1290_readOC(int *return_buffer) |
||
1288 | { |
||
1289 | int wait_count = 0; |
||
1290 | int read_buffer = 0; |
||
1291 | do |
||
1292 | { |
||
1293 | // Micro Handshake Register |
||
1294 | WIENVME_VME_A24D16_R(TDC_ADDR + 0x1030, &read_buffer); Delay(0.01); |
||
1295 | //printf("V1290_readOC wait_count = %d | read_buffer = %x\n", wait_count, read_buffer); |
||
1296 | if(100 < wait_count++) |
||
1297 | return -1; |
||
1298 | |||
1299 | } while (!(read_buffer&0x2)); |
||
1300 | |||
1301 | // Micro Register |
||
1302 | WIENVME_VME_A24D16_R(TDC_ADDR + 0x102E, return_buffer); |
||
1303 | |||
1304 | //printf(">>> Returning %d\n", *return_buffer); |
||
1305 | return 0; |
||
1306 | } |
||
1307 | /* ****************** ******************************************* */ |
||
1308 | void V1290_init() |
||
1309 | { |
||
1310 | int dum; |
||
1311 | // intialization |
||
1312 | |||
1313 | dum=0x0; WIENVME_VME_A24D16_W(TDC_ADDR+0x1014, &dum); Delay(0.1); |
||
1314 | dum=0x0; WIENVME_VME_A24D16_W(TDC_ADDR+0x1016, &dum); Delay(0.1); |
||
1315 | dum=0x0; WIENVME_VME_A24D16_W(TDC_ADDR+0x1018, &dum); Delay(0.1); |
||
1316 | |||
1317 | //Trigger matching |
||
1318 | dum=0x0000; V1290_writeOC(&dum); |
||
1319 | |||
1320 | // Constraints: tdc_window < tdc_offset <= 4095 |
||
1321 | // Largest window: 4095-margin; |
||
1322 | // units: clock cycles = 25 ns |
||
1323 | int tdc_margin = 0; |
||
1324 | int tdc_offset = 40; |
||
1325 | int tdc_window = tdc_offset - tdc_margin; |
||
1326 | |||
1327 | //set window width |
||
1328 | dum=0x1000; V1290_writeOC(&dum); |
||
1329 | dum=tdc_window; V1290_writeOC(&dum); |
||
1330 | //set window offset |
||
1331 | dum=0x1100; V1290_writeOC(&dum); |
||
1332 | dum=-tdc_offset; V1290_writeOC(&dum); |
||
1333 | //set extra search margin |
||
1334 | dum=0x1200; V1290_writeOC(&dum); |
||
1335 | dum=tdc_margin; V1290_writeOC(&dum); |
||
1336 | |||
1337 | //enable all channels |
||
1338 | dum=0x4200; V1290_writeOC(&dum); |
||
1339 | //disable all channels |
||
1340 | //dum=0x4300; V1290_writeOC(&dum); |
||
1341 | //enable first NCH_TDC channels |
||
1342 | //for(i=0;i<NCH_TDC;i++) |
||
1343 | //{ |
||
1344 | // dum=0x4000 + i; |
||
1345 | // V1290_writeOC(&dum); |
||
1346 | //} |
||
1347 | //enable used channels |
||
1348 | //for(i=0;i<32;i++) |
||
1349 | // if(tdcmap[i]<32) |
||
1350 | // { |
||
1351 | // dum=0x4000 + i; |
||
1352 | // V1290_writeOC(&dum); |
||
1353 | // } |
||
1354 | |||
1355 | //enable(0x30xx)/disable(0x31xx) TDC Header and Trailer |
||
1356 | dum=0x3100; V1290_writeOC(&dum); |
||
1357 | /* |
||
1358 | ////Maximum number of hits per event (does not work for unknown reason, sets to 0!) |
||
1359 | dum=0x3300; V1290_writeOC(&dum); |
||
1360 | //dum=0x0001; V1290_writeOC(&dum); |
||
1361 | dum=0x1000; V1290_writeOC(&dum); |
||
1362 | */ |
||
1363 | dum=0x3400; V1290_writeOC(&dum); |
||
1364 | dum=0x0000; V1290_readOC(&dum); |
||
1365 | printf("TDC Maximum number of hits per event = %d\n", dum); |
||
1366 | |||
1367 | //pair(00)/trailing(01)/leading(10)/both(11) edge |
||
1368 | dum=0x2200; V1290_writeOC(&dum); |
||
1369 | dum=0x1; V1290_writeOC(&dum); |
||
1370 | |||
1371 | //enable(0x14xx)/disable(0x15xx) substraction of trigger time |
||
1372 | dum=0x1400; V1290_writeOC(&dum); |
||
1373 | } |
||
1374 | #endif |
||
1375 | /* ****** vrne (INT!) max vrednost iz arraya od elementa do elementa ****** */ |
||
1376 | int max_from(int* array, int ifrom, int ito) |
||
1377 | { |
||
1378 | int i; |
||
1379 | int vmax; |
||
1380 | |||
1381 | vmax = array[ifrom]; |
||
1382 | for(i=ifrom+1; i<=ito; i++) |
||
1383 | if(vmax < array[i]) |
||
1384 | vmax = array[i]; |
||
1385 | |||
1386 | return vmax; |
||
1387 | } |