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