Rev 34 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 34 | Rev 90 | ||
|---|---|---|---|
| Line 32... | Line 32... | ||
| 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]; |
| Line 281... | Line 283... | ||
| 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 | //} |
| Line 299... | Line 302... | ||
| 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 |
| Line 327... | Line 333... | ||
| 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 |
| Line 463... | Line 470... | ||
| 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 | ||
| Line 489... | Line 497... | ||
| 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) { |
| Line 537... | Line 547... | ||
| 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; |
| Line 576... | Line 587... | ||
| 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); |