Subversion Repositories f9daq

Compare Revisions

Ignore whitespace Rev 33 → Rev 34

/sipmScan/src/sipmBias.c
13,7 → 13,8
# include "wienvme_dll.h"
# endif
# include "CAENV673A.h"
# include "CAENV462.h"
# include "CAENV462.h"
 
#endif
 
#ifdef USE_MIKRO
30,8 → 31,10
#ifdef USE_DAQ
# define USE_CAMAC
# include "camac.h"
# define NDAC 1
 
# define NDAC 1 // CAEN C221
# define ASD8 0 // channels
# define AMPDISSH 1
# define SIPM 2
# define CAEN_V673A 0x22220000 // IJS
//#define CAEN_V673A 0x10110000 // FMF
# define CAEN_V462 0x100300
53,6 → 56,7
#define IWAIT 200
 
#define NCH 64
#define POWERSUPPLY 66 // Power supply voltage for SiPM bias
 
static int p1h, pID, rID, tfID;
static int ph_tdc, ph_adc;
138,15 → 142,18
unsigned long *pdata;
 
FILE *fp;
#define RUNREC_ID 1
#define ENDREC_ID 2
#define POSREC_ID 3
#define EVTREC_ID 4
#define THRREC_ID 5
#define RUNREC_ID 1
#define ENDREC_ID 2
#define POSREC_ID 3
#define EVTREC_ID 4
#define THRREC_ID 5
#define BIASREC_ID 6
 
typedef struct {
unsigned long id,len;
unsigned long fver,time;
unsigned long thLow, thUp, thStep;
unsigned long biasLow, biasUp, biasStep;
unsigned long nev,nch,ped,xy;
long nx,x0,dx,ny,y0,dy;
} RUNREC;
175,14 → 182,23
typedef struct {
unsigned long id;
unsigned long len;
unsigned long thLow, thUp, thStep;
unsigned long threshold;
} THRREC;
THRREC thrrec;
typedef struct {
unsigned long id;
unsigned long len;
unsigned long bias;
} BIASREC;
BIASREC biasrec;
double thresholdLow;
double thresholdUp;
double thresholdStep;
double biasLow;
double biasUp;
double biasStep;
 
#define BSIZE 20000
205,6 → 221,8
evtrec.len = sizeof(evtrec);
thrrec.id = THRREC_ID;
thrrec.len = sizeof(thrrec);
biasrec.id = BIASREC_ID;
biasrec.len = sizeof(biasrec);
cres = 0;
241,7 → 259,7
GetCtrlVal (p1h, P1_FRAC, &frac);
}
GetCtrlVal (p1h, P1_STHRLOW, &thresholdLow);
GetCtrlVal (p1h, P1_SASD8THR, &thresholdLow);
runrec.thLow = thresholdLow*1000; // mV
GetCtrlVal (p1h, P1_STHRUP, &thresholdUp);
runrec.thUp = thresholdUp*1000; // mV
248,6 → 266,12
GetCtrlVal (p1h, P1_STEP, &thresholdStep);
runrec.thStep = thresholdStep*1000; // mV
GetCtrlVal (p1h, P1_SBIAS, &biasLow);
GetCtrlVal (p1h, P1_SBIASUP, &biasUp);
GetCtrlVal (p1h, P1_SBIASSTEP, &biasStep);
runrec.biasLow = biasLow*1000;
runrec.biasUp = biasUp*1000;
runrec.biasStep = biasStep*1000;
 
#ifdef USE_DAQ
V673A_map(0,CAEN_V673A,0);
268,12 → 292,21
fseed = runrec.time & 0x7fffffff;
Uniform (1, fseed, &fracg);
}
 
// Set SiPM bias voltage
//SetDac(SIPM, 1.0);
biasrec.bias = runrec.biasLow;
while (biasrec.bias <= runrec.biasUp) {
SetDac(SIPM, biasrec.bias/1000.0 - POWERSUPPLY);
SetCtrlVal(p1h, P1_SBIAS, biasrec.bias/1000.0);
status = fwrite(&biasrec, 1, biasrec.len, fp);
if (print) printf("BIASREC status %d len %d bias %d\n", status, biasrec.len, biasrec.bias);
// Set ASD threshold voltage
thrrec.threshold = (unsigned long) ceil(thresholdLow*1000); // threshold in mV
while (thrrec.threshold <= thresholdUp*1000) {
SetDac(0, thrrec.threshold/1000.0);
SetCtrlVal(p1h, P1_STHRLOW, thrrec.threshold/1000.0);
//wait_loop(100000);
SetDac(ASD8, thrrec.threshold/1000.0);
SetCtrlVal(p1h, P1_SASD8THR, thrrec.threshold/1000.0);
status = fwrite(&thrrec, 1, thrrec.len, fp);
if (print) printf("THRREC status %d len %d threshold %d\n", status, thrrec.len, thrrec.threshold);
459,7 → 492,12
if (!daq_on) break;
thrrec.threshold += thresholdStep*1000;
} // threhsold loop
if (!daq_on) break;
biasrec.bias += runrec.biasStep;
} // bias loop
SetDac(SIPM, 0); // safety
//if (dsave) {
time (&endrec.time);
status = fwrite (&endrec, 1, endrec.len, fp);
547,6 → 585,7
QueueUserEvent (1000, p1h, P1_RESET);
//QueueUserEvent (1000, p1h, P1_ASD8THR);
QueueUserEvent (1000, p1h, P1_AMPDISSHTHR);
QueueUserEvent (1000, p1h, P1_BIAS);
do {
GetUserEvent (1, &pID, &rID);
switch (rID) {
650,19 → 689,27
SetCtrlAttribute (p1h, P1_ADC, ATTR_YMAP_MODE, status);
update_plots();
break;
/*case P1_ASD8THR:
case P1_ASD8THR:
{
double value;
GetCtrlVal (p1h, P1_SASD8THR, &value);
SetDac(0, value);
SetDac(ASD8, value);
}
break;*/
break;
case P1_BIAS:
{
double value;
GetCtrlVal (p1h, P1_SBIAS, &value);
value -= POWERSUPPLY;
SetDac(SIPM, value);
}
break;
case P1_AMPDISSHTHR:
{
double value;
GetCtrlVal (p1h, P1_SAMPDISSHTHR, &value);
SetDac(1, value);
SetDac(AMPDISSH, value);
 
}
break;