Rev 33 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 33 | Rev 34 | ||
---|---|---|---|
1 | #define USE_DAQ |
1 | #define USE_DAQ |
2 | #define USE_MIKRO |
2 | #define USE_MIKRO |
3 | 3 | ||
4 | // Izberi ustrezni interface v meniju projektnega okna |
4 | // Izberi ustrezni interface v meniju projektnega okna |
5 | // Options->CompilerDefines (dodaj /DSISVME ali /DWIENVME) |
5 | // Options->CompilerDefines (dodaj /DSISVME ali /DWIENVME) |
6 | #ifdef USE_DAQ |
6 | #ifdef USE_DAQ |
7 | # define USE_CAMAC |
7 | # define USE_CAMAC |
8 | #include "c:\HOME\dino\sipmScan\include\camac.h" |
8 | #include "c:\HOME\dino\sipmScan\include\camac.h" |
9 | # ifdef SISVME |
9 | # ifdef SISVME |
10 | # include "sisvme_dll.h" |
10 | # include "sisvme_dll.h" |
11 | # endif |
11 | # endif |
12 | # ifdef WIENVME |
12 | # ifdef WIENVME |
13 | # include "wienvme_dll.h" |
13 | # include "wienvme_dll.h" |
14 | # endif |
14 | # endif |
15 | # include "CAENV673A.h" |
15 | # include "CAENV673A.h" |
16 | # include "CAENV462.h" |
16 | # include "CAENV462.h" |
- | 17 | ||
17 | #endif |
18 | #endif |
18 | 19 | ||
19 | #ifdef USE_MIKRO |
20 | #ifdef USE_MIKRO |
20 | # include "MIKRO.h" |
21 | # include "MIKRO.h" |
21 | #endif |
22 | #endif |
22 | 23 | ||
23 | #include <userint.h> |
24 | #include <userint.h> |
24 | #include <ansi_c.h> |
25 | #include <ansi_c.h> |
25 | #include <utility.h> |
26 | #include <utility.h> |
26 | #include <analysis.h> |
27 | #include <analysis.h> |
27 | 28 | ||
28 | #include "c:\HOME\dino\sipmScan\include\sipmBias_ui.h" |
29 | #include "c:\HOME\dino\sipmScan\include\sipmBias_ui.h" |
29 | 30 | ||
30 | #ifdef USE_DAQ |
31 | #ifdef USE_DAQ |
31 | # define USE_CAMAC |
32 | # define USE_CAMAC |
32 | # include "camac.h" |
33 | # include "camac.h" |
- | 34 | # define NDAC 1 // CAEN C221 |
|
- | 35 | # define ASD8 0 // channels |
|
- | 36 | # define AMPDISSH 1 |
|
33 | # define |
37 | # define SIPM 2 |
34 | - | ||
35 | # define CAEN_V673A 0x22220000 // IJS |
38 | # define CAEN_V673A 0x22220000 // IJS |
36 | //#define CAEN_V673A 0x10110000 // FMF |
39 | //#define CAEN_V673A 0x10110000 // FMF |
37 | # define CAEN_V462 0x100300 |
40 | # define CAEN_V462 0x100300 |
38 | #endif |
41 | #endif |
39 | 42 | ||
40 | #ifdef USE_MIKRO |
43 | #ifdef USE_MIKRO |
41 | # define MIKRO_COM 5 |
44 | # define MIKRO_COM 5 |
42 | # define MIKRO_X 1 |
45 | # define MIKRO_X 1 |
43 | # define USE_MIKRO_Y |
46 | # define USE_MIKRO_Y |
44 | # define MIKRO_Y 2 |
47 | # define MIKRO_Y 2 |
45 | # define USE_MIKRO_Z |
48 | # define USE_MIKRO_Z |
46 | # define MIKRO_Z 3 |
49 | # define MIKRO_Z 3 |
47 | # define STEP_TOLERANCE 50 |
50 | # define STEP_TOLERANCE 50 |
48 | #endif |
51 | #endif |
49 | 52 | ||
50 | #define MAXCH 512 |
53 | #define MAXCH 512 |
51 | #define MAX_THREADS 10 |
54 | #define MAX_THREADS 10 |
52 | 55 | ||
53 | #define IWAIT 200 |
56 | #define IWAIT 200 |
54 | 57 | ||
55 | #define NCH 64 |
58 | #define NCH 64 |
- | 59 | #define POWERSUPPLY 66 // Power supply voltage for SiPM bias |
|
56 | 60 | ||
57 | static int p1h, pID, rID, tfID; |
61 | static int p1h, pID, rID, tfID; |
58 | static int ph_tdc, ph_adc; |
62 | static int ph_tdc, ph_adc; |
59 | static int dtdc[NCH][2][MAXCH]; |
63 | static int dtdc[NCH][2][MAXCH]; |
60 | static int something[NCH][2][MAXCH]; |
64 | static int something[NCH][2][MAXCH]; |
61 | 65 | ||
62 | static int daq_on; |
66 | static int daq_on; |
63 | static int poolHandle = 0; |
67 | static int poolHandle = 0; |
64 | static int ntics,dummy; |
68 | static int ntics,dummy; |
65 | 69 | ||
66 | /************************************************************/ |
70 | /************************************************************/ |
67 | void wait_loop(unsigned long iloop) |
71 | void wait_loop(unsigned long iloop) |
68 | 72 | ||
69 | { |
73 | { |
70 | int i; |
74 | int i; |
71 | 75 | ||
72 | for (i=0;i<iloop;i++); |
76 | for (i=0;i<iloop;i++); |
73 | return; |
77 | return; |
74 | } |
78 | } |
75 | 79 | ||
76 | int CVICALLBACK cb_timer (int panel, int control, int event, void *callbackData, |
80 | int CVICALLBACK cb_timer (int panel, int control, int event, void *callbackData, |
77 | int eventData1, int eventData2) |
81 | int eventData1, int eventData2) |
78 | { |
82 | { |
79 | QueueUserEvent (9000, p1h, P1_TIMER); |
83 | QueueUserEvent (9000, p1h, P1_TIMER); |
80 | return (0); |
84 | return (0); |
81 | } |
85 | } |
82 | 86 | ||
83 | int update_plots (void) |
87 | int update_plots (void) |
84 | { |
88 | { |
85 | int irange, ch; |
89 | int irange, ch; |
86 | 90 | ||
87 | GetCtrlVal (p1h, P1_PLCH, &ch); |
91 | GetCtrlVal (p1h, P1_PLCH, &ch); |
88 | 92 | ||
89 | if (ph_tdc>0) DeleteGraphPlot (p1h, P1_TDC, ph_tdc, VAL_DELAYED_DRAW); |
93 | if (ph_tdc>0) DeleteGraphPlot (p1h, P1_TDC, ph_tdc, VAL_DELAYED_DRAW); |
90 | GetCtrlVal (p1h, P1_TDCHL, &irange); |
94 | GetCtrlVal (p1h, P1_TDCHL, &irange); |
91 | ph_tdc = PlotY (p1h, P1_TDC, &dtdc[ch][irange], MAXCH, VAL_INTEGER, |
95 | ph_tdc = PlotY (p1h, P1_TDC, &dtdc[ch][irange], MAXCH, VAL_INTEGER, |
92 | VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED); |
96 | VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED); |
93 | 97 | ||
94 | if (ph_adc>0) DeleteGraphPlot (p1h, P1_ADC, ph_adc, VAL_DELAYED_DRAW); |
98 | if (ph_adc>0) DeleteGraphPlot (p1h, P1_ADC, ph_adc, VAL_DELAYED_DRAW); |
95 | GetCtrlVal (p1h, P1_ADCHL, &irange); |
99 | GetCtrlVal (p1h, P1_ADCHL, &irange); |
96 | ph_adc = PlotY (p1h, P1_ADC, &something[ch][irange], MAXCH, VAL_INTEGER, |
100 | ph_adc = PlotY (p1h, P1_ADC, &something[ch][irange], MAXCH, VAL_INTEGER, |
97 | VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE); |
101 | VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE); |
98 | return (0); |
102 | return (0); |
99 | } |
103 | } |
100 | 104 | ||
101 | 105 | ||
102 | int module_header(int recid,unsigned long *data,int len){ |
106 | int module_header(int recid,unsigned long *data,int len){ |
103 | data[0] = recid; |
107 | data[0] = recid; |
104 | data[1] = (len >0)? len : 0 ; |
108 | data[1] = (len >0)? len : 0 ; |
105 | return data[1]+2; |
109 | return data[1]+2; |
106 | } |
110 | } |
107 | 111 | ||
108 | int SetDac(int, double); |
112 | int SetDac(int, double); |
109 | 113 | ||
110 | int CVICALLBACK daq_run(void *functionData) |
114 | int CVICALLBACK daq_run(void *functionData) |
111 | { |
115 | { |
112 | // *** |
116 | // *** |
113 | // variable declarations |
117 | // variable declarations |
114 | int i,j; |
118 | int i,j; |
115 | int dtype,ch,rg,adc,cres,bsr; |
119 | int dtype,ch,rg,adc,cres,bsr; |
116 | 120 | ||
117 | //unsigned short aa[NCH][4]; |
121 | //unsigned short aa[NCH][4]; |
118 | unsigned long tdc[NCH]; |
122 | unsigned long tdc[NCH]; |
119 | unsigned long step_minutes, end_time_s, cur_time_s; |
123 | unsigned long step_minutes, end_time_s, cur_time_s; |
120 | int start_hours, start_minutes, start_seconds; |
124 | int start_hours, start_minutes, start_seconds; |
121 | 125 | ||
122 | int status,fmax,fcount,fev; |
126 | int status,fmax,fcount,fev; |
123 | int popupret; |
127 | int popupret; |
124 | int mikroX; // check the position |
128 | int mikroX; // check the position |
125 | int mikroY; // check the position |
129 | int mikroY; // check the position |
126 | 130 | ||
127 | char dfile[MAX_PATHNAME_LEN],dfile0[MAX_PATHNAME_LEN]; |
131 | char dfile[MAX_PATHNAME_LEN],dfile0[MAX_PATHNAME_LEN]; |
128 | int supr0,tdcmin,fseed; |
132 | int supr0,tdcmin,fseed; |
129 | float frac; |
133 | float frac; |
130 | double fracg; |
134 | double fracg; |
131 | unsigned short dum16; |
135 | unsigned short dum16; |
132 | int count; |
136 | int count; |
133 | int print = 0; |
137 | int print = 0; |
134 | int timer_out = 0; |
138 | int timer_out = 0; |
135 | //time_t t,told, tstart; |
139 | //time_t t,told, tstart; |
136 | int ntrig; |
140 | int ntrig; |
137 | int chip, len; |
141 | int chip, len; |
138 | unsigned long *pdata; |
142 | unsigned long *pdata; |
139 | 143 | ||
140 | FILE *fp; |
144 | FILE *fp; |
141 | #define RUNREC_ID 1 |
145 | #define RUNREC_ID 1 |
142 | #define ENDREC_ID 2 |
146 | #define ENDREC_ID 2 |
143 | #define POSREC_ID 3 |
147 | #define POSREC_ID 3 |
144 | #define EVTREC_ID 4 |
148 | #define EVTREC_ID 4 |
145 | #define THRREC_ID 5 |
149 | #define THRREC_ID 5 |
- | 150 | #define BIASREC_ID 6 |
|
146 | 151 | ||
147 | typedef struct { |
152 | typedef struct { |
148 | unsigned long id,len; |
153 | unsigned long id,len; |
149 | unsigned long fver,time; |
154 | unsigned long fver,time; |
- | 155 | unsigned long thLow, thUp, thStep; |
|
- | 156 | unsigned long biasLow, biasUp, biasStep; |
|
150 | unsigned long nev,nch,ped,xy; |
157 | unsigned long nev,nch,ped,xy; |
151 | long nx,x0,dx,ny,y0,dy; |
158 | long nx,x0,dx,ny,y0,dy; |
152 | } RUNREC; |
159 | } RUNREC; |
153 | RUNREC runrec; |
160 | RUNREC runrec; |
154 | 161 | ||
155 | typedef struct { |
162 | typedef struct { |
156 | unsigned long id,len; |
163 | unsigned long id,len; |
157 | unsigned long time; |
164 | unsigned long time; |
158 | } ENDREC; |
165 | } ENDREC; |
159 | ENDREC endrec; |
166 | ENDREC endrec; |
160 | 167 | ||
161 | typedef struct { |
168 | typedef struct { |
162 | unsigned long id,len; |
169 | unsigned long id,len; |
163 | unsigned long time; |
170 | unsigned long time; |
164 | long ix,x,xset,iy,y,yset; |
171 | long ix,x,xset,iy,y,yset; |
165 | } POSREC; |
172 | } POSREC; |
166 | POSREC posrec; |
173 | POSREC posrec; |
167 | 174 | ||
168 | typedef struct { |
175 | typedef struct { |
169 | unsigned long id,len; |
176 | unsigned long id,len; |
170 | unsigned long nev; |
177 | unsigned long nev; |
171 | //unsigned short data[NCH]; |
178 | //unsigned short data[NCH]; |
172 | } EVTREC; |
179 | } EVTREC; |
173 | EVTREC evtrec; |
180 | EVTREC evtrec; |
174 | 181 | ||
175 | typedef struct { |
182 | typedef struct { |
176 | unsigned long id; |
183 | unsigned long id; |
177 | unsigned long len; |
184 | unsigned long len; |
178 | unsigned long thLow, thUp, thStep; |
- | |
179 | unsigned long threshold; |
185 | unsigned long threshold; |
180 | } THRREC; |
186 | } THRREC; |
181 | THRREC thrrec; |
187 | THRREC thrrec; |
- | 188 | ||
- | 189 | typedef struct { |
|
- | 190 | unsigned long id; |
|
- | 191 | unsigned long len; |
|
- | 192 | unsigned long bias; |
|
- | 193 | } BIASREC; |
|
- | 194 | BIASREC biasrec; |
|
182 | 195 | ||
183 | double thresholdLow; |
196 | double thresholdLow; |
184 | double thresholdUp; |
197 | double thresholdUp; |
185 | double thresholdStep; |
198 | double thresholdStep; |
- | 199 | double biasLow; |
|
- | 200 | double biasUp; |
|
- | 201 | double biasStep; |
|
186 | 202 | ||
187 | #define BSIZE 20000 |
203 | #define BSIZE 20000 |
188 | 204 | ||
189 | int maxn = BSIZE-4; // 2 words x 2 headers |
205 | int maxn = BSIZE-4; // 2 words x 2 headers |
190 | int tdcdata, edge_type, overflow, tdc_num, channel, ev_dat, last_dat, nval_dat; |
206 | int tdcdata, edge_type, overflow, tdc_num, channel, ev_dat, last_dat, nval_dat; |
191 | // end of declarations |
207 | // end of declarations |
192 | // *** |
208 | // *** |
193 | 209 | ||
194 | runrec.id = RUNREC_ID; |
210 | runrec.id = RUNREC_ID; |
195 | runrec.len = sizeof(runrec); |
211 | runrec.len = sizeof(runrec); |
196 | //runrec.fver = 0x10000; |
212 | //runrec.fver = 0x10000; |
197 | runrec.nch = NCH; |
213 | runrec.nch = NCH; |
198 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy);//runrec.xy = 1; |
214 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy);//runrec.xy = 1; |
199 | GetCtrlVal(p1h, P1_DEBUG, &print); |
215 | GetCtrlVal(p1h, P1_DEBUG, &print); |
200 | endrec.id = ENDREC_ID; |
216 | endrec.id = ENDREC_ID; |
201 | endrec.len = sizeof(endrec); |
217 | endrec.len = sizeof(endrec); |
202 | posrec.id = POSREC_ID; |
218 | posrec.id = POSREC_ID; |
203 | posrec.len = sizeof(posrec); |
219 | posrec.len = sizeof(posrec); |
204 | evtrec.id = EVTREC_ID; |
220 | evtrec.id = EVTREC_ID; |
205 | evtrec.len = sizeof(evtrec); |
221 | evtrec.len = sizeof(evtrec); |
206 | thrrec.id = THRREC_ID; |
222 | thrrec.id = THRREC_ID; |
207 | thrrec.len = sizeof(thrrec); |
223 | thrrec.len = sizeof(thrrec); |
- | 224 | biasrec.id = BIASREC_ID; |
|
- | 225 | biasrec.len = sizeof(biasrec); |
|
208 | 226 | ||
209 | 227 | ||
210 | cres = 0; |
228 | cres = 0; |
211 | 229 | ||
212 | GetCtrlVal (p1h, P1_NEVE, &runrec.nev); |
230 | GetCtrlVal (p1h, P1_NEVE, &runrec.nev); |
213 | GetCtrlVal (p1h, P1_PEDESTAL, &runrec.ped); |
231 | GetCtrlVal (p1h, P1_PEDESTAL, &runrec.ped); |
214 | 232 | ||
215 | GetCtrlVal (p1h, P1_NX, &runrec.nx); |
233 | GetCtrlVal (p1h, P1_NX, &runrec.nx); |
216 | GetCtrlVal (p1h, P1_XSTEP, &runrec.dx); |
234 | GetCtrlVal (p1h, P1_XSTEP, &runrec.dx); |
217 | GetCtrlVal (p1h, P1_XMIN, &runrec.x0); |
235 | GetCtrlVal (p1h, P1_XMIN, &runrec.x0); |
218 | GetCtrlVal (p1h, P1_NY, &runrec.ny); |
236 | GetCtrlVal (p1h, P1_NY, &runrec.ny); |
219 | GetCtrlVal (p1h, P1_YSTEP, &runrec.dy); |
237 | GetCtrlVal (p1h, P1_YSTEP, &runrec.dy); |
220 | GetCtrlVal (p1h, P1_YMIN, &runrec.y0); |
238 | GetCtrlVal (p1h, P1_YMIN, &runrec.y0); |
221 | 239 | ||
222 | GetCtrlVal (p1h, P1_NMIN, &step_minutes); |
240 | GetCtrlVal (p1h, P1_NMIN, &step_minutes); |
223 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
241 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
224 | //cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds; |
242 | //cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds; |
225 | time(&cur_time_s); |
243 | time(&cur_time_s); |
226 | end_time_s = cur_time_s + step_minutes*60; |
244 | end_time_s = cur_time_s + step_minutes*60; |
227 | 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); |
245 | 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); |
228 | 246 | ||
229 | //GetCtrlVal (p1h, P1_DSAVE, &dsave); |
247 | //GetCtrlVal (p1h, P1_DSAVE, &dsave); |
230 | //if (dsave) { |
248 | //if (dsave) { |
231 | GetCtrlVal (p1h, P1_DFILE, dfile0); |
249 | GetCtrlVal (p1h, P1_DFILE, dfile0); |
232 | 250 | ||
233 | fev=0; |
251 | fev=0; |
234 | fcount=1; |
252 | fcount=1; |
235 | GetCtrlVal (p1h, P1_NEWF, &fmax); |
253 | GetCtrlVal (p1h, P1_NEWF, &fmax); |
236 | fmax*=1000000;//fmax in Mega Bytes |
254 | fmax*=1000000;//fmax in Mega Bytes |
237 | //} |
255 | //} |
238 | GetCtrlVal (p1h, P1_SUPR, &supr0); |
256 | GetCtrlVal (p1h, P1_SUPR, &supr0); |
239 | if (supr0) { |
257 | if (supr0) { |
240 | GetCtrlVal (p1h, P1_TDCMIN, &tdcmin); |
258 | GetCtrlVal (p1h, P1_TDCMIN, &tdcmin); |
241 | GetCtrlVal (p1h, P1_FRAC, &frac); |
259 | GetCtrlVal (p1h, P1_FRAC, &frac); |
242 | } |
260 | } |
243 | 261 | ||
244 | GetCtrlVal (p1h, |
262 | GetCtrlVal (p1h, P1_SASD8THR, &thresholdLow); |
245 | runrec.thLow = thresholdLow*1000; // mV |
263 | runrec.thLow = thresholdLow*1000; // mV |
246 | GetCtrlVal (p1h, P1_STHRUP, &thresholdUp); |
264 | GetCtrlVal (p1h, P1_STHRUP, &thresholdUp); |
247 | runrec.thUp = thresholdUp*1000; // mV |
265 | runrec.thUp = thresholdUp*1000; // mV |
248 | GetCtrlVal (p1h, P1_STEP, &thresholdStep); |
266 | GetCtrlVal (p1h, P1_STEP, &thresholdStep); |
249 | runrec.thStep = thresholdStep*1000; // mV |
267 | runrec.thStep = thresholdStep*1000; // mV |
250 | 268 | ||
- | 269 | GetCtrlVal (p1h, P1_SBIAS, &biasLow); |
|
- | 270 | GetCtrlVal (p1h, P1_SBIASUP, &biasUp); |
|
- | 271 | GetCtrlVal (p1h, P1_SBIASSTEP, &biasStep); |
|
- | 272 | runrec.biasLow = biasLow*1000; |
|
- | 273 | runrec.biasUp = biasUp*1000; |
|
- | 274 | runrec.biasStep = biasStep*1000; |
|
251 | 275 | ||
252 | #ifdef USE_DAQ |
276 | #ifdef USE_DAQ |
253 | V673A_map(0,CAEN_V673A,0); |
277 | V673A_map(0,CAEN_V673A,0); |
254 | V673A_init(0); |
278 | V673A_init(0); |
255 | 279 | ||
256 | V462_map(0,CAEN_V462,0); |
280 | V462_map(0,CAEN_V462,0); |
257 | V462_set0(0,1); |
281 | V462_set0(0,1); |
258 | #endif |
282 | #endif |
259 | 283 | ||
260 | //if (dsave) { |
284 | //if (dsave) { |
261 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
285 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
262 | 286 | ||
263 | fp = fopen (dfile, "wb"); |
287 | fp = fopen (dfile, "wb"); |
264 | time (&runrec.time); |
288 | time (&runrec.time); |
265 | status = fwrite (&runrec, 1, runrec.len, fp); |
289 | status = fwrite (&runrec, 1, runrec.len, fp); |
266 | //} |
290 | //} |
267 | if (supr0) { |
291 | if (supr0) { |
268 | fseed = runrec.time & 0x7fffffff; |
292 | fseed = runrec.time & 0x7fffffff; |
269 | Uniform (1, fseed, &fracg); |
293 | Uniform (1, fseed, &fracg); |
270 | } |
294 | } |
271 | 295 | ||
- | 296 | // Set SiPM bias voltage |
|
- | 297 | //SetDac(SIPM, 1.0); |
|
- | 298 | biasrec.bias = runrec.biasLow; |
|
- | 299 | while (biasrec.bias <= runrec.biasUp) { |
|
- | 300 | SetDac(SIPM, biasrec.bias/1000.0 - POWERSUPPLY); |
|
- | 301 | SetCtrlVal(p1h, P1_SBIAS, biasrec.bias/1000.0); |
|
- | 302 | status = fwrite(&biasrec, 1, biasrec.len, fp); |
|
- | 303 | if (print) printf("BIASREC status %d len %d bias %d\n", status, biasrec.len, biasrec.bias); |
|
- | 304 | ||
- | 305 | // Set ASD threshold voltage |
|
272 | thrrec.threshold = (unsigned long) ceil(thresholdLow*1000); // threshold in mV |
306 | thrrec.threshold = (unsigned long) ceil(thresholdLow*1000); // threshold in mV |
273 | while (thrrec.threshold <= thresholdUp*1000) { |
307 | while (thrrec.threshold <= thresholdUp*1000) { |
274 | SetDac( |
308 | SetDac(ASD8, thrrec.threshold/1000.0); |
275 | SetCtrlVal(p1h, |
309 | SetCtrlVal(p1h, P1_SASD8THR, thrrec.threshold/1000.0); |
276 | //wait_loop(100000); |
- | |
277 | status = fwrite(&thrrec, 1, thrrec.len, fp); |
310 | status = fwrite(&thrrec, 1, thrrec.len, fp); |
278 | if (print) printf("THRREC status %d len %d threshold %d\n", status, thrrec.len, thrrec.threshold); |
311 | if (print) printf("THRREC status %d len %d threshold %d\n", status, thrrec.len, thrrec.threshold); |
279 | 312 | ||
280 | for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) { |
313 | for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) { |
281 | posrec.xset = runrec.x0 + posrec.ix*runrec.dx; |
314 | posrec.xset = runrec.x0 + posrec.ix*runrec.dx; |
282 | #ifdef USE_MIKRO |
315 | #ifdef USE_MIKRO |
283 | //printf("MIKRO_MoveTo (1, x);%d\n",posrec.x); |
316 | //printf("MIKRO_MoveTo (1, x);%d\n",posrec.x); |
284 | do { |
317 | do { |
285 | MIKRO_MoveTo (MIKRO_X, posrec.xset); |
318 | MIKRO_MoveTo (MIKRO_X, posrec.xset); |
286 | MIKRO_GetPosition(MIKRO_X, &mikroX); |
319 | MIKRO_GetPosition(MIKRO_X, &mikroX); |
287 | } while (abs(posrec.xset - mikroX) > STEP_TOLERANCE); |
320 | } while (abs(posrec.xset - mikroX) > STEP_TOLERANCE); |
288 | //printf("->MIKRO_MoveTo (1, x);%d\n",posrec.xset); |
321 | //printf("->MIKRO_MoveTo (1, x);%d\n",posrec.xset); |
289 | #endif |
322 | #endif |
290 | //SetCtrlVal (p1h, P1_X, posrec.xset); |
323 | //SetCtrlVal (p1h, P1_X, posrec.xset); |
291 | posrec.xset = mikroX; // set the true value |
324 | posrec.xset = mikroX; // set the true value |
292 | SetCtrlVal(p1h, P1_X, mikroX); |
325 | SetCtrlVal(p1h, P1_X, mikroX); |
293 | SetCtrlVal (p1h, P1_IX, posrec.ix); |
326 | SetCtrlVal (p1h, P1_IX, posrec.ix); |
294 | for (posrec.iy=0; posrec.iy<runrec.ny; posrec.iy++) { |
327 | for (posrec.iy=0; posrec.iy<runrec.ny; posrec.iy++) { |
295 | posrec.yset = runrec.y0 + posrec.iy*runrec.dy; |
328 | posrec.yset = runrec.y0 + posrec.iy*runrec.dy; |
296 | #ifdef USE_MIKRO_Y |
329 | #ifdef USE_MIKRO_Y |
297 | //printf("MIKRO_MoveTo (2, y);%d\n",y); |
330 | //printf("MIKRO_MoveTo (2, y);%d\n",y); |
298 | do { |
331 | do { |
299 | MIKRO_MoveTo (MIKRO_Y, posrec.yset); |
332 | MIKRO_MoveTo (MIKRO_Y, posrec.yset); |
300 | MIKRO_GetPosition(MIKRO_Y, &mikroY); |
333 | MIKRO_GetPosition(MIKRO_Y, &mikroY); |
301 | } while (abs(posrec.yset - mikroY) > STEP_TOLERANCE); |
334 | } while (abs(posrec.yset - mikroY) > STEP_TOLERANCE); |
302 | //printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
335 | //printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
303 | #endif |
336 | #endif |
304 | //SetCtrlVal (p1h, P1_Y, posrec.yset); |
337 | //SetCtrlVal (p1h, P1_Y, posrec.yset); |
305 | posrec.yset = mikroY; // set the true value |
338 | posrec.yset = mikroY; // set the true value |
306 | SetCtrlVal (p1h, P1_Y, mikroY); |
339 | SetCtrlVal (p1h, P1_Y, mikroY); |
307 | SetCtrlVal (p1h, P1_IY, posrec.iy); |
340 | SetCtrlVal (p1h, P1_IY, posrec.iy); |
308 | //if (dsave) { |
341 | //if (dsave) { |
309 | if (fmax && (ftell(fp) > fmax)) { |
342 | if (fmax && (ftell(fp) > fmax)) { |
310 | fcount+=1; |
343 | fcount+=1; |
311 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
344 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
312 | fclose(fp); |
345 | fclose(fp); |
313 | fp = fopen (dfile, "wb"); |
346 | fp = fopen (dfile, "wb"); |
314 | } |
347 | } |
315 | 348 | ||
316 | time (&posrec.time); |
349 | time (&posrec.time); |
317 | status = fwrite (&posrec, 1, posrec.len, fp); |
350 | status = fwrite (&posrec, 1, posrec.len, fp); |
318 | if (print) printf("POSREC status %d len %d\n", status, posrec.len); |
351 | if (print) printf("POSREC status %d len %d\n", status, posrec.len); |
319 | //} |
352 | //} |
320 | 353 | ||
321 | // clear the plots |
354 | // clear the plots |
322 | for (j=0;j<NCH;j++) { |
355 | for (j=0;j<NCH;j++) { |
323 | for (i=0;i<MAXCH;i++){ |
356 | for (i=0;i<MAXCH;i++){ |
324 | dtdc[j][0][i]=0; |
357 | dtdc[j][0][i]=0; |
325 | dtdc[j][1][i]=0; |
358 | dtdc[j][1][i]=0; |
326 | } |
359 | } |
327 | } |
360 | } |
328 | 361 | ||
329 | evtrec.nev=1; |
362 | evtrec.nev=1; |
330 | //time(&t); |
363 | //time(&t); |
331 | //tstart=t; |
364 | //tstart=t; |
332 | if (print) printf("RUN START.\n"); |
365 | if (print) printf("RUN START.\n"); |
333 | 366 | ||
334 | do { |
367 | do { |
335 | unsigned long word[BSIZE]; |
368 | unsigned long word[BSIZE]; |
336 | count=0; |
369 | count=0; |
337 | ntics=0; |
370 | ntics=0; |
338 | if (print) printf("Event counter: %d\n", evtrec.nev); |
371 | if (print) printf("Event counter: %d\n", evtrec.nev); |
339 | 372 | ||
340 | //if (t!=told ) printf("%d in %2.2f min daq::event() %s\n",i, (double)(t-tstart)/60., ctime(&t)); |
373 | //if (t!=told ) printf("%d in %2.2f min daq::event() %s\n",i, (double)(t-tstart)/60., ctime(&t)); |
341 | 374 | ||
342 | #ifdef USE_DAQ |
375 | #ifdef USE_DAQ |
343 | #ifdef CAEN_V673A |
376 | #ifdef CAEN_V673A |
344 | 377 | ||
345 | 378 | ||
346 | V462_start0(0); |
379 | V462_start0(0); |
347 | //tmlnk (tout); |
380 | //tmlnk (tout); |
348 | do { |
381 | do { |
349 | ntrig = V673A_ntrig(0); |
382 | ntrig = V673A_ntrig(0); |
350 | } while (ntrig==0 &&(ntics<2)); |
383 | } while (ntrig==0 &&(ntics<2)); |
351 | //tmulk(); |
384 | //tmulk(); |
352 | //if (timer_out) { |
385 | //if (timer_out) { |
353 | // fprintf(stderr,"-----------------> V673a timeout !!!\n"); |
386 | // fprintf(stderr,"-----------------> V673a timeout !!!\n"); |
354 | // V673A_clallb(0); |
387 | // V673A_clallb(0); |
355 | // continue; |
388 | // continue; |
356 | //} |
389 | //} |
357 | 390 | ||
358 | if (ntics>=2) { |
391 | if (ntics>=2) { |
359 | fprintf(stderr,"-----------------> V673a timeout !!!\n"); |
392 | fprintf(stderr,"-----------------> V673a timeout !!!\n"); |
360 | printf("Timer tics %d\n", ntics); |
393 | printf("Timer tics %d\n", ntics); |
361 | ntics = 0; |
394 | ntics = 0; |
362 | evtrec.nev--; |
395 | evtrec.nev--; |
363 | V673A_clallb(0); |
396 | V673A_clallb(0); |
364 | continue; |
397 | continue; |
365 | } |
398 | } |
366 | 399 | ||
367 | if (ntrig>0){ |
400 | if (ntrig>0){ |
368 | // chip readout |
401 | // chip readout |
369 | for (chip=0;chip<2;chip++){ |
402 | for (chip=0;chip<2;chip++){ |
370 | if (chip) len = V673A_read1 (0, &word[count+2],maxn-count-2); |
403 | if (chip) len = V673A_read1 (0, &word[count+2],maxn-count-2); |
371 | else len = V673A_read0 (0, &word[count+2],maxn-count-2); |
404 | else len = V673A_read0 (0, &word[count+2],maxn-count-2); |
372 | 405 | ||
373 | if (len>16*32*4){ |
406 | if (len>16*32*4){ |
374 | if (print) printf("Length > 2048 per chip!\n"); |
407 | if (print) printf("Length > 2048 per chip!\n"); |
375 | chip=2; |
408 | chip=2; |
376 | V673A_clallb(0); |
409 | V673A_clallb(0); |
377 | evtrec.nev--; |
410 | evtrec.nev--; |
378 | continue; |
411 | continue; |
379 | } |
412 | } |
380 | pdata=&word[count+2]; |
413 | pdata=&word[count+2]; |
381 | for(i=0;i< len;i++){ |
414 | for(i=0;i< len;i++){ |
382 | tdcdata = pdata[i] & 0xFFFF ; |
415 | tdcdata = pdata[i] & 0xFFFF ; |
383 | edge_type = (pdata[i]>>16)&0x1 ; |
416 | edge_type = (pdata[i]>>16)&0x1 ; |
384 | overflow = (pdata[i]>>17)&0x1 ; |
417 | overflow = (pdata[i]>>17)&0x1 ; |
385 | tdc_num = (pdata[i]>>25)&0x1 ; |
418 | tdc_num = (pdata[i]>>25)&0x1 ; |
386 | channel = ((pdata[i]>>18)&0x1F) |tdc_num<<5 ; |
419 | channel = ((pdata[i]>>18)&0x1F) |tdc_num<<5 ; |
387 | ev_dat = (pdata[i]>>23)&0x1 ; |
420 | ev_dat = (pdata[i]>>23)&0x1 ; |
388 | last_dat = (pdata[i]>>30)&0x1 ; |
421 | last_dat = (pdata[i]>>30)&0x1 ; |
389 | nval_dat = (pdata[i]>>31)&0x1 ; |
422 | nval_dat = (pdata[i]>>31)&0x1 ; |
390 | if (ev_dat) { |
423 | if (ev_dat) { |
391 | if(print) printf("Event %d\n",tdcdata); |
424 | if(print) printf("Event %d\n",tdcdata); |
392 | } else { |
425 | } else { |
393 | dtdc[channel][edge_type][tdcdata]++; |
426 | dtdc[channel][edge_type][tdcdata]++; |
394 | 427 | ||
395 | if (print) printf |
428 | if (print) printf |
396 | ("ch=%d edge=%d ev=%d data=%d last=%d nval=%d\n",channel, edge_type,ev_dat,tdcdata,last_dat,nval_dat); |
429 | ("ch=%d edge=%d ev=%d data=%d last=%d nval=%d\n",channel, edge_type,ev_dat,tdcdata,last_dat,nval_dat); |
397 | } |
430 | } |
398 | } |
431 | } |
399 | if (count+2 < maxn) count+=module_header(0x140+chip,&word[count],len); |
432 | if (count+2 < maxn) count+=module_header(0x140+chip,&word[count],len); |
400 | } |
433 | } |
401 | if (print) printf("Received triggers: %d \n", ntrig); |
434 | if (print) printf("Received triggers: %d \n", ntrig); |
402 | } else { |
435 | } else { |
403 | if (ntrig==0) { |
436 | if (ntrig==0) { |
404 | fprintf(stderr,"-----------------> no trigger"); |
437 | fprintf(stderr,"-----------------> no trigger"); |
405 | break; |
438 | break; |
406 | } else { |
439 | } else { |
407 | if (print) fprintf(stderr,"-----------------> wrong number of triggers in chips V673a !!!\n"); |
440 | if (print) fprintf(stderr,"-----------------> wrong number of triggers in chips V673a !!!\n"); |
408 | } |
441 | } |
409 | V673A_clallb(0); |
442 | V673A_clallb(0); |
410 | evtrec.nev--; |
443 | evtrec.nev--; |
411 | continue; |
444 | continue; |
412 | } |
445 | } |
413 | 446 | ||
414 | V673A_clallb(0); |
447 | V673A_clallb(0); |
415 | #endif |
448 | #endif |
416 | #endif |
449 | #endif |
417 | 450 | ||
418 | 451 | ||
419 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy); |
452 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy); |
420 | evtrec.len = count*sizeof(unsigned long) + sizeof(evtrec); |
453 | evtrec.len = count*sizeof(unsigned long) + sizeof(evtrec); |
421 | if (print) printf("EVTREC.len = %d bytes.\n", evtrec.len); |
454 | if (print) printf("EVTREC.len = %d bytes.\n", evtrec.len); |
422 | 455 | ||
423 | status = fwrite (&evtrec, 1, sizeof(evtrec), fp); |
456 | status = fwrite (&evtrec, 1, sizeof(evtrec), fp); |
424 | status = fwrite (&word, 1, count*sizeof(unsigned long), fp); |
457 | status = fwrite (&word, 1, count*sizeof(unsigned long), fp); |
425 | 458 | ||
426 | 459 | ||
427 | if (!(evtrec.nev%1000)) SetCtrlVal (p1h, P1_CEVE, evtrec.nev); |
460 | if (!(evtrec.nev%1000)) SetCtrlVal (p1h, P1_CEVE, evtrec.nev); |
428 | 461 | ||
429 | if (!((evtrec.nev+1)%1000)) { |
462 | if (!((evtrec.nev+1)%1000)) { |
430 | if (fmax && (ftell(fp) > fmax)) { |
463 | if (fmax && (ftell(fp) > fmax)) { |
431 | time (&endrec.time); |
464 | time (&endrec.time); |
432 | status = fwrite (&endrec, 1, endrec.len, fp); |
465 | status = fwrite (&endrec, 1, endrec.len, fp); |
433 | fcount+=1; |
466 | fcount+=1; |
434 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
467 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
435 | fclose(fp); |
468 | fclose(fp); |
436 | fp = fopen (dfile, "wb"); |
469 | fp = fopen (dfile, "wb"); |
437 | } |
470 | } |
438 | } |
471 | } |
439 | 472 | ||
440 | if(step_minutes > 0) { |
473 | if(step_minutes > 0) { |
441 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
474 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
442 | //cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds; |
475 | //cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds; |
443 | time(&cur_time_s); |
476 | time(&cur_time_s); |
444 | if(cur_time_s >= end_time_s) { |
477 | if(cur_time_s >= end_time_s) { |
445 | end_time_s = cur_time_s + step_minutes*60; |
478 | end_time_s = cur_time_s + step_minutes*60; |
446 | printf("STEP (nev):%2d-%2d-%2d @ %d\n", start_hours, start_minutes, start_seconds, posrec.xset); |
479 | printf("STEP (nev):%2d-%2d-%2d @ %d\n", start_hours, start_minutes, start_seconds, posrec.xset); |
447 | break; |
480 | break; |
448 | } |
481 | } |
449 | } |
482 | } |
450 | //told=t; |
483 | //told=t; |
451 | 484 | ||
452 | GetCtrlVal(p1h, P1_DAQ, &daq_on); |
485 | GetCtrlVal(p1h, P1_DAQ, &daq_on); |
453 | 486 | ||
454 | } while (evtrec.nev++<runrec.nev && daq_on); |
487 | } while (evtrec.nev++<runrec.nev && daq_on); |
455 | if (!daq_on) break; |
488 | if (!daq_on) break; |
456 | } // x loop |
489 | } // x loop |
457 | if (!daq_on) break; |
490 | if (!daq_on) break; |
458 | } // y loop |
491 | } // y loop |
459 | if (!daq_on) break; |
492 | if (!daq_on) break; |
460 | thrrec.threshold += thresholdStep*1000; |
493 | thrrec.threshold += thresholdStep*1000; |
461 | } // threhsold loop |
494 | } // threhsold loop |
- | 495 | if (!daq_on) break; |
|
- | 496 | biasrec.bias += runrec.biasStep; |
|
- | 497 | } // bias loop |
|
- | 498 | ||
- | 499 | SetDac(SIPM, 0); // safety |
|
462 | 500 | ||
463 | //if (dsave) { |
501 | //if (dsave) { |
464 | time (&endrec.time); |
502 | time (&endrec.time); |
465 | status = fwrite (&endrec, 1, endrec.len, fp); |
503 | status = fwrite (&endrec, 1, endrec.len, fp); |
466 | if (print) printf("ENDREC status %d len %d\n", status, endrec.len); |
504 | if (print) printf("ENDREC status %d len %d\n", status, endrec.len); |
467 | fclose(fp); |
505 | fclose(fp); |
468 | //} |
506 | //} |
469 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
507 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
470 | printf("STOP:%2d-%2d-%2d (start_time = %u s, end_time = %u s)\n", start_hours, start_minutes, start_seconds, runrec.time, endrec.time); |
508 | printf("STOP:%2d-%2d-%2d (start_time = %u s, end_time = %u s)\n", start_hours, start_minutes, start_seconds, runrec.time, endrec.time); |
471 | printf("Elapsed time: %u s.\n", endrec.time-runrec.time); |
509 | printf("Elapsed time: %u s.\n", endrec.time-runrec.time); |
472 | 510 | ||
473 | daq_on=0; |
511 | daq_on=0; |
474 | SetCtrlVal (p1h, P1_DAQ, daq_on); |
512 | SetCtrlVal (p1h, P1_DAQ, daq_on); |
475 | SetCtrlVal (p1h, P1_CEVE, evtrec.nev); |
513 | SetCtrlVal (p1h, P1_CEVE, evtrec.nev); |
476 | if (print) printf("RUN END. \n\n"); |
514 | if (print) printf("RUN END. \n\n"); |
477 | 515 | ||
478 | return 0; |
516 | return 0; |
479 | } |
517 | } |
480 | 518 | ||
481 | 519 | ||
482 | int SetDac(int ch, double val){ |
520 | int SetDac(int ch, double val){ |
483 | 521 | ||
484 | const unsigned int maxdac=0xFFF; |
522 | const unsigned int maxdac=0xFFF; |
485 | const double RANGE = +9.9976; //V |
523 | const double RANGE = +9.9976; //V |
486 | unsigned int dac; |
524 | unsigned int dac; |
487 | 525 | ||
488 | if ((val > RANGE) || (val < 0)) { |
526 | if ((val > RANGE) || (val < 0)) { |
489 | printf("DAC value OUT OF RANGE!!!\n"); |
527 | printf("DAC value OUT OF RANGE!!!\n"); |
490 | return(-1); |
528 | return(-1); |
491 | } |
529 | } |
492 | 530 | ||
493 | dac = (val/RANGE)*maxdac; |
531 | dac = (val/RANGE)*maxdac; |
494 | CSSA_W(NDAC,ch,16,&dac); |
532 | CSSA_W(NDAC,ch,16,&dac); |
495 | printf("DAC ch %d set to %f V dac=%d\n", ch, val, dac); |
533 | printf("DAC ch %d set to %f V dac=%d\n", ch, val, dac); |
496 | return 0; |
534 | return 0; |
497 | } |
535 | } |
498 | 536 | ||
499 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
537 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
500 | LPSTR lpszCmdLine, int nCmdShow) |
538 | LPSTR lpszCmdLine, int nCmdShow) |
501 | { |
539 | { |
502 | int i,j,status,refon; |
540 | int i,j,status,refon; |
503 | long int xpos, ypos, zpos; |
541 | long int xpos, ypos, zpos; |
504 | char dfile[300]; |
542 | char dfile[300]; |
505 | FILE *fp; |
543 | FILE *fp; |
506 | 544 | ||
507 | typedef struct { |
545 | typedef struct { |
508 | unsigned long id,len; |
546 | unsigned long id,len; |
509 | unsigned long fver,time; |
547 | unsigned long fver,time; |
510 | unsigned long nev,nch,ped,xy; |
548 | unsigned long nev,nch,ped,xy; |
511 | long nx,x0,dx,ny,y0,dy; |
549 | long nx,x0,dx,ny,y0,dy; |
512 | } RUNREC; |
550 | } RUNREC; |
513 | RUNREC runrec; |
551 | RUNREC runrec; |
514 | 552 | ||
515 | if (InitCVIRTE (hInstance, 0, 0) == 0) |
553 | if (InitCVIRTE (hInstance, 0, 0) == 0) |
516 | return -1; /* out of memory */ |
554 | return -1; /* out of memory */ |
517 | 555 | ||
518 | SetSleepPolicy(VAL_SLEEP_MORE); |
556 | SetSleepPolicy(VAL_SLEEP_MORE); |
519 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
557 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
520 | 558 | ||
521 | SetStdioWindowOptions (1000, 0, 0); |
559 | SetStdioWindowOptions (1000, 0, 0); |
522 | SetStdioWindowSize (200, 560); |
560 | SetStdioWindowSize (200, 560); |
523 | SetStdioWindowPosition (825, 250); |
561 | SetStdioWindowPosition (825, 250); |
524 | 562 | ||
525 | #ifdef USE_DAQ |
563 | #ifdef USE_DAQ |
526 | VME_START(NULL); |
564 | VME_START(NULL); |
527 | #endif |
565 | #endif |
528 | 566 | ||
529 | #ifdef USE_MIKRO |
567 | #ifdef USE_MIKRO |
530 | MIKRO_Open (MIKRO_COM); |
568 | MIKRO_Open (MIKRO_COM); |
531 | MIKRO_Init (MIKRO_X,0); |
569 | MIKRO_Init (MIKRO_X,0); |
532 | #ifdef USE_MIKRO_Y |
570 | #ifdef USE_MIKRO_Y |
533 | MIKRO_Init (MIKRO_Y,0); |
571 | MIKRO_Init (MIKRO_Y,0); |
534 | #endif |
572 | #endif |
535 | #ifdef USE_MIKRO_Z |
573 | #ifdef USE_MIKRO_Z |
536 | MIKRO_Init (MIKRO_Z,0); |
574 | MIKRO_Init (MIKRO_Z,0); |
537 | #endif |
575 | #endif |
538 | #endif |
576 | #endif |
539 | 577 | ||
540 | if ((p1h = LoadPanel (0, "include/sipmBias_ui.uir", P1)) < 0) return -1; |
578 | if ((p1h = LoadPanel (0, "include/sipmBias_ui.uir", P1)) < 0) return -1; |
541 | DisplayPanel (p1h); |
579 | DisplayPanel (p1h); |
542 | SetCtrlAttribute (p1h, P1_PLCH, ATTR_MAX_VALUE, NCH-1); |
580 | SetCtrlAttribute (p1h, P1_PLCH, ATTR_MAX_VALUE, NCH-1); |
543 | 581 | ||
544 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy); |
582 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy); |
545 | SetCtrlVal(p1h, P1_ADCHL, runrec.xy-2); |
583 | SetCtrlVal(p1h, P1_ADCHL, runrec.xy-2); |
546 | 584 | ||
547 | QueueUserEvent (1000, p1h, P1_RESET); |
585 | QueueUserEvent (1000, p1h, P1_RESET); |
548 | //QueueUserEvent (1000, p1h, P1_ASD8THR); |
586 | //QueueUserEvent (1000, p1h, P1_ASD8THR); |
549 | QueueUserEvent (1000, p1h, P1_AMPDISSHTHR); |
587 | QueueUserEvent (1000, p1h, P1_AMPDISSHTHR); |
- | 588 | QueueUserEvent (1000, p1h, P1_BIAS); |
|
550 | do { |
589 | do { |
551 | GetUserEvent (1, &pID, &rID); |
590 | GetUserEvent (1, &pID, &rID); |
552 | switch (rID) { |
591 | switch (rID) { |
553 | case P1_TIMER: |
592 | case P1_TIMER: |
554 | ntics+=1; |
593 | ntics+=1; |
555 | GetCtrlVal (p1h, P1_REFON, &refon); |
594 | GetCtrlVal (p1h, P1_REFON, &refon); |
556 | if (refon) update_plots(); |
595 | if (refon) update_plots(); |
557 | break; |
596 | break; |
558 | case P1_REFRESH: |
597 | case P1_REFRESH: |
559 | update_plots(); |
598 | update_plots(); |
560 | break; |
599 | break; |
561 | case P1_DAQ: |
600 | case P1_DAQ: |
562 | GetCtrlVal (p1h, P1_DAQ, &daq_on); |
601 | GetCtrlVal (p1h, P1_DAQ, &daq_on); |
563 | if (daq_on) { |
602 | if (daq_on) { |
564 | CmtScheduleThreadPoolFunction (poolHandle, daq_run, (void *)&dummy, &tfID); |
603 | CmtScheduleThreadPoolFunction (poolHandle, daq_run, (void *)&dummy, &tfID); |
565 | } else { |
604 | } else { |
566 | CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID, |
605 | CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID, |
567 | OPT_TP_PROCESS_EVENTS_WHILE_WAITING); |
606 | OPT_TP_PROCESS_EVENTS_WHILE_WAITING); |
568 | CmtReleaseThreadPoolFunctionID (poolHandle, tfID); |
607 | CmtReleaseThreadPoolFunctionID (poolHandle, tfID); |
569 | } |
608 | } |
570 | break; |
609 | break; |
571 | 610 | ||
572 | case P1_ZSET: |
611 | case P1_ZSET: |
573 | if (!daq_on) { |
612 | if (!daq_on) { |
574 | GetCtrlVal (p1h, P1_ZSET, &zpos); |
613 | GetCtrlVal (p1h, P1_ZSET, &zpos); |
575 | #ifdef USE_MIKRO_Z |
614 | #ifdef USE_MIKRO_Z |
576 | MIKRO_MoveTo (MIKRO_Z, zpos); |
615 | MIKRO_MoveTo (MIKRO_Z, zpos); |
577 | #endif |
616 | #endif |
578 | } |
617 | } |
579 | break; |
618 | break; |
580 | case P1_REREAD: |
619 | case P1_REREAD: |
581 | if (!daq_on) { |
620 | if (!daq_on) { |
582 | status = FileSelectPopup ("", "*.dat", ".dat", |
621 | status = FileSelectPopup ("", "*.dat", ".dat", |
583 | "Choose the previous file", |
622 | "Choose the previous file", |
584 | VAL_LOAD_BUTTON, 0, 0, 1, 0, dfile); |
623 | VAL_LOAD_BUTTON, 0, 0, 1, 0, dfile); |
585 | if (status==1) { |
624 | if (status==1) { |
586 | fp = fopen (dfile, "rb"); |
625 | fp = fopen (dfile, "rb"); |
587 | status = fread (&runrec, 1, sizeof(runrec), fp); |
626 | status = fread (&runrec, 1, sizeof(runrec), fp); |
588 | fclose(fp); |
627 | fclose(fp); |
589 | if (runrec.id==1) { |
628 | if (runrec.id==1) { |
590 | SetCtrlVal (p1h, P1_NX, runrec.nx); |
629 | SetCtrlVal (p1h, P1_NX, runrec.nx); |
591 | SetCtrlVal (p1h, P1_XSTEP, runrec.dx); |
630 | SetCtrlVal (p1h, P1_XSTEP, runrec.dx); |
592 | SetCtrlVal (p1h, P1_XMIN, runrec.x0); |
631 | SetCtrlVal (p1h, P1_XMIN, runrec.x0); |
593 | SetCtrlVal (p1h, P1_NY, runrec.ny); |
632 | SetCtrlVal (p1h, P1_NY, runrec.ny); |
594 | SetCtrlVal (p1h, P1_YSTEP, runrec.dy); |
633 | SetCtrlVal (p1h, P1_YSTEP, runrec.dy); |
595 | SetCtrlVal (p1h, P1_YMIN, runrec.y0); |
634 | SetCtrlVal (p1h, P1_YMIN, runrec.y0); |
596 | SetCtrlVal (p1h, P1_NEVE, runrec.nev); |
635 | SetCtrlVal (p1h, P1_NEVE, runrec.nev); |
597 | } |
636 | } |
598 | } |
637 | } |
599 | } |
638 | } |
600 | break; |
639 | break; |
601 | case P1_MGET: |
640 | case P1_MGET: |
602 | #ifdef USE_MIKRO |
641 | #ifdef USE_MIKRO |
603 | MIKRO_GetPosition(MIKRO_X,&xpos); |
642 | MIKRO_GetPosition(MIKRO_X,&xpos); |
604 | Delay(0.01); |
643 | Delay(0.01); |
605 | SetCtrlVal (p1h, P1_X, xpos); |
644 | SetCtrlVal (p1h, P1_X, xpos); |
606 | #ifdef USE_MIKRO_Y |
645 | #ifdef USE_MIKRO_Y |
607 | MIKRO_GetPosition(MIKRO_Y,&ypos); |
646 | MIKRO_GetPosition(MIKRO_Y,&ypos); |
608 | Delay(0.01); |
647 | Delay(0.01); |
609 | SetCtrlVal (p1h, P1_Y, ypos); |
648 | SetCtrlVal (p1h, P1_Y, ypos); |
610 | #endif |
649 | #endif |
611 | #ifdef USE_MIKRO_Z |
650 | #ifdef USE_MIKRO_Z |
612 | MIKRO_GetPosition(MIKRO_Z,&zpos); |
651 | MIKRO_GetPosition(MIKRO_Z,&zpos); |
613 | Delay(0.01); |
652 | Delay(0.01); |
614 | SetCtrlVal (p1h, P1_Z, zpos); |
653 | SetCtrlVal (p1h, P1_Z, zpos); |
615 | #endif |
654 | #endif |
616 | #endif |
655 | #endif |
617 | break; |
656 | break; |
618 | case P1_HO: |
657 | case P1_HO: |
619 | if (!daq_on) { |
658 | if (!daq_on) { |
620 | SetWaitCursor (1); |
659 | SetWaitCursor (1); |
621 | #ifdef USE_MIKRO |
660 | #ifdef USE_MIKRO |
622 | MIKRO_ReferenceMove (MIKRO_X); |
661 | MIKRO_ReferenceMove (MIKRO_X); |
623 | #ifdef USE_MIKRO_Y |
662 | #ifdef USE_MIKRO_Y |
624 | MIKRO_ReferenceMove (MIKRO_Y); |
663 | MIKRO_ReferenceMove (MIKRO_Y); |
625 | #endif |
664 | #endif |
626 | #ifdef USE_MIKRO_Z |
665 | #ifdef USE_MIKRO_Z |
627 | MIKRO_ReferenceMove (MIKRO_Z); |
666 | MIKRO_ReferenceMove (MIKRO_Z); |
628 | #endif |
667 | #endif |
629 | #endif |
668 | #endif |
630 | SetWaitCursor (0); |
669 | SetWaitCursor (0); |
631 | } |
670 | } |
632 | break; |
671 | break; |
633 | case P1_RESET: |
672 | case P1_RESET: |
634 | for (j=0;j<NCH;j++) { |
673 | for (j=0;j<NCH;j++) { |
635 | for (i=0;i<MAXCH;i++){ |
674 | for (i=0;i<MAXCH;i++){ |
636 | dtdc[j][0][i]=0; |
675 | dtdc[j][0][i]=0; |
637 | dtdc[j][1][i]=0; |
676 | dtdc[j][1][i]=0; |
638 | 677 | ||
639 | } |
678 | } |
640 | } |
679 | } |
641 | update_plots(); |
680 | update_plots(); |
642 | break; |
681 | break; |
643 | case P1_TDCLOG: |
682 | case P1_TDCLOG: |
644 | GetCtrlVal (p1h, P1_TDCLOG, &status); |
683 | GetCtrlVal (p1h, P1_TDCLOG, &status); |
645 | SetCtrlAttribute (p1h, P1_TDC, ATTR_YMAP_MODE, status); |
684 | SetCtrlAttribute (p1h, P1_TDC, ATTR_YMAP_MODE, status); |
646 | update_plots(); |
685 | update_plots(); |
647 | break; |
686 | break; |
648 | case P1_ADCLOG: |
687 | case P1_ADCLOG: |
649 | GetCtrlVal (p1h, P1_ADCLOG, &status); |
688 | GetCtrlVal (p1h, P1_ADCLOG, &status); |
650 | SetCtrlAttribute (p1h, P1_ADC, ATTR_YMAP_MODE, status); |
689 | SetCtrlAttribute (p1h, P1_ADC, ATTR_YMAP_MODE, status); |
651 | update_plots(); |
690 | update_plots(); |
652 | break; |
691 | break; |
653 |
|
692 | case P1_ASD8THR: |
654 | { |
693 | { |
655 | double value; |
694 | double value; |
656 | GetCtrlVal (p1h, P1_SASD8THR, &value); |
695 | GetCtrlVal (p1h, P1_SASD8THR, &value); |
657 |
|
696 | SetDac(ASD8, value); |
658 | |
697 | |
659 | } |
698 | } |
660 |
|
699 | break; |
- | 700 | case P1_BIAS: |
|
- | 701 | { |
|
- | 702 | double value; |
|
- | 703 | GetCtrlVal (p1h, P1_SBIAS, &value); |
|
- | 704 | value -= POWERSUPPLY; |
|
- | 705 | SetDac(SIPM, value); |
|
- | 706 | } |
|
- | 707 | break; |
|
661 | case P1_AMPDISSHTHR: |
708 | case P1_AMPDISSHTHR: |
662 | { |
709 | { |
663 | double value; |
710 | double value; |
664 | GetCtrlVal (p1h, P1_SAMPDISSHTHR, &value); |
711 | GetCtrlVal (p1h, P1_SAMPDISSHTHR, &value); |
665 | SetDac( |
712 | SetDac(AMPDISSH, value); |
666 | 713 | ||
667 | } |
714 | } |
668 | break; |
715 | break; |
669 | 716 | ||
670 | } |
717 | } |
671 | 718 | ||
672 | } while ((rID != P1_EXIT)||daq_on); |
719 | } while ((rID != P1_EXIT)||daq_on); |
673 | 720 | ||
674 | CmtDiscardThreadPool (poolHandle); |
721 | CmtDiscardThreadPool (poolHandle); |
675 | DiscardPanel (p1h); |
722 | DiscardPanel (p1h); |
676 | 723 | ||
677 | #ifdef USE_MIKRO |
724 | #ifdef USE_MIKRO |
678 | MIKRO_Close (); |
725 | MIKRO_Close (); |
679 | #endif |
726 | #endif |
680 | 727 | ||
681 | #ifdef USE_DAQ |
728 | #ifdef USE_DAQ |
682 | VME_STOP(); |
729 | VME_STOP(); |
683 | #endif |
730 | #endif |
684 | return 0; |
731 | return 0; |
685 | 732 | ||
686 | } |
733 | } |
687 | 734 |