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