10Gbe, some functions in gotthard and eiger servers including mv in dacs, mv in dacs, changing settings file

This commit is contained in:
Maliakal Dhanya
2014-07-11 13:06:48 +02:00
parent 018b800117
commit 828a2dbd17
21 changed files with 867 additions and 863 deletions

View File

@ -500,47 +500,6 @@ int program_one_dac(int addr, int value, int imod) {
int set_one_dac(int imod) {
int control, ibit;
int bit, value;
control=13;
value=(DAC_REFOUT<<10) | (control<< 12);
#ifdef DEBUGOUT
fprintf(stdout,"value=%d\n",value);
#endif
for (ibit=0; ibit<6; ibit++) {
bit=value & (1<<(15-ibit));
if (bit) {
putout("0000010001000000",imod);
putout("0000011001000000",imod);
putout("0000010001000000",imod);
#ifdef DEBUGOUT
fprintf(stdout,"1");
#endif
} else {
putout("0000000001000000",imod);
putout("0000001001000000",imod);
putout("0000000001000000",imod);
#ifdef DEBUGOUT
fprintf(stdout,"0");
#endif
}
}
for (ibit=0; ibit<10; ibit++) {
putout("0000000001000000",imod);
putout("0000001001000000",imod);
putout("0000000001000000",imod);
#ifdef DEBUGOUT
fprintf(stdout,"0");
#endif
}
#ifdef DEBUGOUT
fprintf(stdout,"\n");
#endif
return OK;
}
int initDACbyIndex(int ind,int val, int imod) {
int v;
const int partref[NDAC]=PARTREF;
@ -550,15 +509,16 @@ int initDACbyIndex(int ind,int val, int imod) {
int ref=partref[ind];
int r1=partr1[ind];
int r2=partr2[ind];
int retval[2];
v=(val+(val-ref)*r1/r2)*DAC_DR/DAC_MAX;
v=initDACbyIndexDACU(ind,v,imod);
v=initDACbyIndexDACU(ind,v,imod,0,retval);
return (v*DAC_MAX/DAC_DR+ref*r1/r2)/(1+r1/r2);
}
int initDACbyIndexDACU(int ind, int val, int imod) {
int initDACbyIndexDACU(int ind, int val, int imod, int mV, int retval[]) {
// const double daccs[NDAC]=DACCS;
// const double dacaddr[NDAC]=DACADDR;
@ -567,6 +527,8 @@ int initDACbyIndexDACU(int ind, int val, int imod) {
// int addr=dacaddr[ind];
// int iv;
int im;
if(mV)
val = (val*4096)/2500;
if (val>=0)
initDAC(ind,val, imod);
@ -597,123 +559,12 @@ int initDACbyIndexDACU(int ind, int val, int imod) {
#ifdef VERBOSE
printf("returning %d\n",setDACRegister(ind, -1, 0));
#endif
return setDACRegister(ind, -1, 0);
retval[0] = setDACRegister(ind, -1, 0);
retval[1] = (retval[0]*2500)/4096;
return retval[0];
}
}
int getThresholdEnergy() {
double g[3]=DEFAULTGAIN;
double o[3]=DEFAULTOFFSET;
double myg=-1, myo=-1;
// int dacu;
int imod;
int ethr=-1;
int ret=FAIL;
if (detectorModules) {
// for (imod=0; imod<getNModBoard(); imod++) {
for (imod=0; imod<nModX; imod++) {
#ifdef VERBOSE
printf("module=%d settings=%d, gain=%f, offset=%f\n",imod,thisSettings, (detectorModules+imod)->gain,(detectorModules+imod)->offset);
#endif
if ((detectorModules+imod)->gain>0)
myg=(detectorModules+imod)->gain;
else {
if (thisSettings>=0 && thisSettings<3)
myg=g[thisSettings];
// else
//myg=-1;
}
if ((detectorModules+imod)->offset>0)
myo=(detectorModules+imod)->offset;
else {
if (thisSettings>=0 && thisSettings<3)
myo=o[thisSettings];
// else
//myo=-1;
}
if (myg>0 && myo>0) {
//ethr=(myo-detectorDacs[VTHRESH+imod*NDAC])*1000/myg;
ethr=(myo-setDACRegister(VREF_DS,-1,imod))*1000/myg;//edited by dhanya
// else
// ethr=-1;
}
#ifdef VERBOSE
//printf("module=%d gain=%f, offset=%f, dacu=%f\n",imod, myg, myo, detectorDacs[VTHRESH+imod*NDAC]);
printf("module=%d gain=%f, offset=%f, dacu=%d\n",imod, myg, myo,(int)(setDACRegister(VREF_DS,-1,imod)));//edited by dhanya
printf("Threshold energy of module %d is %d eV\n", imod, ethr);
#endif
if (imod==0)
ret=ethr;
else {
if (ethr>(ret+100) || ethr<(ret-100))
return FAIL;
}
}
}
return ret;
}
int setThresholdEnergy(int ethr) {
double g[3]=DEFAULTGAIN;
double o[3]=DEFAULTOFFSET;
double myg=-1, myo=-1;
int dacu;
int imod;
int ret=ethr;
setSettings(GET_SETTINGS,-1);//-1 added by dhanya
if (thisSettings>=0 || thisSettings<3){
myg=g[thisSettings];
myo=o[thisSettings];
}
for (imod=0; imod<nModX; imod++) {
if (detectorModules) {
if ((detectorModules+imod)->gain>0)
myg=(detectorModules+imod)->gain;
else
if (thisSettings>=0 && thisSettings<3)
myg=g[thisSettings];
else
myg=-1;
if ((detectorModules+imod)->offset>0)
myo=(detectorModules+imod)->offset;
else
if (thisSettings>=0 && thisSettings<3)
myo=o[thisSettings];
else
myo=-1;
} else {
if (thisSettings>=0 && thisSettings<3)
myo=o[thisSettings];
else
myo=-1;
if (thisSettings>=0 && thisSettings<3)
myg=g[thisSettings];
else
myg=-1;
}
if (myg>0 && myo>0) {
dacu=myo-myg*((double)ethr)/1000.;
#ifdef VERBOSE
printf("module %d (%x): gain %f, off %f, energy %d eV, dac %d\n",imod,(unsigned int)((detectorModules+imod)),(detectorModules+imod)->gain,(detectorModules+imod)->offset, ethr,dacu);
#endif
} else {
dacu=ethr;
#ifdef VERBOSE
printf("could not set threshold energy for module %d, settings %d (offset is %f; gain is %f)\n",imod,thisSettings,myo,myg);
#endif
}
initDACbyIndexDACU(VREF_DS, dacu, imod); ///needs to be fixed dhanya
}
return ret;
}
int getDACbyIndexDACU(int ind, int imod) {

View File

@ -109,10 +109,8 @@ int initDAC(int dac_addr, int value,int imod );
int initDACs(int* v,int imod );
int setSettings(int i,int imod);
int initDACbyIndex(int ind,int val, int imod);
int initDACbyIndexDACU(int ind,int val, int imod);
int initDACbyIndexDACU(int ind,int val, int imod, int mV, int retval[]);
int getDACbyIndexDACU(int ind, int imod);
int getThresholdEnergy();
int setThresholdEnergy(int ethr);
/* Other DAC index routines*/
int getTemperatureByModule(int tempSensor, int imod);

View File

@ -891,13 +891,15 @@ int read_register(int file_des) {
int set_dac(int file_des) {
//default:all mods
int retval;
int retval[2];retval[1]=-1;
int temp;
int ret=OK;
int arg[2];
int arg[3];
enum dacIndex ind;
int imod;
int n;
int val;
int mV;
int idac=0;
sprintf(mess,"Can't set DAC\n");
@ -909,6 +911,7 @@ int set_dac(int file_des) {
}
ind=arg[0];
imod=arg[1];
mV=arg[2];
n = receiveDataOnly(file_des,&val,sizeof(val));
if (n < 0) {
@ -967,33 +970,37 @@ int set_dac(int file_des) {
ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else{
if(idac==HIGH_VOLTAGE)
retval=initHighVoltageByModule(val,imod);
else
retval=initDACbyIndexDACU(idac,val,imod);
if(idac==HIGH_VOLTAGE){
retval[0]=initHighVoltageByModule(val,imod);
ret=FAIL;
if(retval[0]==-2)
strcpy(mess,"Invalid Voltage.Valid values are 0,90,110,120,150,180,200");
else if(retval[0]==-3)
strcpy(mess,"Weird value read back or it has not been set yet\n");
else
ret=OK;
}else{
initDACbyIndexDACU(idac,val,imod,mV,retval);
ret=FAIL;
if(mV)
temp = retval[1];
else
temp = retval[0];
if ((abs(temp-val)<=3) || val==-1) {
ret=OK;
#ifdef VERBOSE
printf("DAC set to %d in dac units and %d mV\n", retval[0],retval[1]);
#endif
}
}
}
}
if(ret==OK){
ret=FAIL;
if(idac==HIGH_VOLTAGE){
if(retval==-2)
strcpy(mess,"Invalid Voltage.Valid values are 0,90,110,120,150,180,200");
else if(retval==-3)
strcpy(mess,"Weird value read back or it has not been set yet\n");
else
ret=OK;
}//since v r saving only msb
else if ((retval-val)<=3 || val==-1)
ret=OK;
}
#endif
#ifdef VERBOSE
printf("DAC set to %d V\n", retval);
#endif
if(ret==FAIL)
printf("Setting dac %d of module %d: wrote %d but read %d\n", ind, imod, val, retval);
printf("Setting dac %d of module %d: wrote %d but read %d\n", ind, imod, val, temp);
else{
if (differentClients)
ret=FORCE_UPDATE;