temp, confgain and hv works well, temp is alternate though

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@61 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2011-11-24 15:54:26 +00:00
parent 9f85175dce
commit 05aaefb8f0
5 changed files with 150 additions and 68 deletions

View File

@ -856,28 +856,29 @@ float getTemperature(int tempSensor, int imod){
float val; float val;
char cTempSensor[2][100]={"ADCs/ASICs","VRs/FPGAs"}; char cTempSensor[2][100]={"ADCs/ASICs","VRs/FPGAs"};
imod=0;//ignoring more than 1 mod for now imod=0;//ignoring more than 1 mod for now
int i,j,k,repeats=6,times=11; int i,j,k,repeats=6;
u_int32_t tempVal=0; u_int32_t tempVal=0,tempVal2=0;
#ifdef VERBOSE #ifdef VERBOSE
printf("Getting Temperature of module:%d for the %s\n",imod,cTempSensor[tempSensor]); printf("Getting Temperature of module:%d for the %s for tempsensor:%d\n",imod,cTempSensor[tempSensor],tempSensor);
#endif #endif
bus_w(TEMP_IN_REG,(T1_CLK_BIT)|(T1_CS_BIT)|(T2_CLK_BIT)|(T2_CS_BIT));//standby bus_w(TEMP_IN_REG,(T1_CLK_BIT)|(T1_CS_BIT)|(T2_CLK_BIT)|(T2_CS_BIT));//standby
bus_w(TEMP_IN_REG,(T1_CLK_BIT)&~(T1_CS_BIT)|(T2_CLK_BIT));//high clk low cs bus_w(TEMP_IN_REG,(T1_CLK_BIT)&~(T1_CS_BIT)|(T2_CLK_BIT));//high clk low cs
for(k=0;k<2;k++){ for(i=0;i<20;i++) {
for(i=0;i<times;i++) { //repeats is number of register writes for delay
//repeats is number of register writes for delay for(j=0;j<repeats;j++)
for(j=0;j<repeats;j++) bus_w(TEMP_IN_REG,~(T1_CLK_BIT)&~(T1_CS_BIT)&~(T2_CLK_BIT)&~(T2_CS_BIT));//low clk low cs
bus_w(TEMP_IN_REG,~(T1_CLK_BIT)&~(T1_CS_BIT)&~(T2_CLK_BIT)&~(T2_CS_BIT));//low clk low cs for(j=0;j<repeats;j++)
for(j=0;j<repeats;j++) bus_w(TEMP_IN_REG,(T1_CLK_BIT)&~(T1_CS_BIT)|(T2_CLK_BIT));//high clk low cs
bus_w(TEMP_IN_REG,(T1_CLK_BIT)&~(T1_CS_BIT)|(T2_CLK_BIT));//high clk low cs
if(times==11)//only the first time if(i<=10){//only the first time
tempVal= (tempVal<<1) + (bus_r(TEMP_OUT_REG) & (1<<tempSensor)); if(!tempSensor)
tempVal= (tempVal<<1) + (bus_r(TEMP_OUT_REG) & (1));//adc
else
tempVal= (tempVal<<1) + ((bus_r(TEMP_OUT_REG) & (2))>>1);//fpga
} }
times=8;
} }
bus_w(TEMP_IN_REG,(T1_CLK_BIT)|(T1_CS_BIT)|(T2_CLK_BIT)|(T2_CS_BIT));//standby bus_w(TEMP_IN_REG,(T1_CLK_BIT)|(T1_CS_BIT)|(T2_CLK_BIT)|(T2_CS_BIT));//standby
val=((float)tempVal)/4.0; val=((float)tempVal)/4.0;
@ -887,46 +888,96 @@ float getTemperature(int tempSensor, int imod){
return val; return val;
} }
int getHighVoltage(int val, int imod){
int initHighVoltage(int val, int imod){
#ifdef VERBOSE #ifdef VERBOSE
printf("Setting/Getting High Voltage of module:%d with val:%d\n",imod,val); printf("Setting/Getting High Voltage of module:%d with val:%d\n",imod,val);
#endif #endif
volatile u_int32_t addr=HV_REG; volatile u_int32_t addr=HV_REG;
int loop; int writeVal,writeVal2;
int found=0; switch(val){
int input []={ 0, 90,110,120,150,180,200}; case -1: break;
int value1[]={0x0,0x0,0x2,0x4,0x6,0x8,0xA}; case 0: writeVal=0x0; writeVal2=0x0; break;
int value2[]={0x0,0x1,0x3,0x5,0x7,0x9,0xB}; case 90: writeVal=0x0; writeVal2=0x1; break;
if(val!=-1) case 110:writeVal=0x2; writeVal2=0x3; break;
{ case 120:writeVal=0x4; writeVal2=0x5; break;
for(loop=0;loop<7;loop++) case 150:writeVal=0x6; writeVal2=0x7; break;
if(val==input[loop]) { case 180:writeVal=0x8; writeVal2=0x9; break;
found=1; case 200:writeVal=0xA; writeVal2=0xB; break;
default :printf("Invalid voltage\n");return -2;break;
}
//to set value
if(val!=-1){
//set value to converted value
bus_w(addr,writeVal);
bus_w(addr,writeVal2);
#ifdef VERBOSE #ifdef VERBOSE
printf("Value sent for val:%d is %d and then %d\n",val,value1[loop],value2[loop]); printf("Value sent is %d and then %d\n",writeVal,writeVal2);
#endif #endif
bus_w(addr,value1[loop]); }
bus_w(addr,value2[loop]); //read value and return the converted value
val=bus_r(addr);
if(val!=value2[loop])
{
printf("Error setting high voltage:Value read is %d\n",val);
return -1;
}
}
if(!found){
printf("Not a valid voltage\n");
return -1;
}
}
val=bus_r(addr); val=bus_r(addr);
#ifdef VERBOSE #ifdef VERBOSE
printf("High Voltage of module:%d is %d\n",imod,val); printf("Value read from reg is %d\n",val);
#endif #endif
return val; switch(val){
case 0x0:val=0;break;
case 0x1:val=90;break;
case 0x3:val=110;break;
case 0x5:val=120;break;
case 0x7:val=150;break;
case 0x9:val=180;break;
case 0xB:val=200;break;
default:printf("Weird value read:%d\n",val);return -3;break;
}
#ifdef VERBOSE
printf("High voltage of module:%d is %d\n",imod,val);
#endif
return val;
} }
int initConfGain(int val, int imod){
#ifdef VERBOSE
printf("Setting/Getting confgain of module:%d with val:%d\n",imod,val);
#endif
volatile u_int32_t addr=GAIN_REG;
int writeVals[]={6,2,0,1};
char cGainVal[][100]={"lower","medium","high","very high"};
//to set value
if(val!=-1){
//default value
if((val>4)||(val<1))
val=3;
//set value to converted value
bus_w(addr,writeVals[val-1]);
#ifdef VERBOSE
printf("Value sent is %d\n",writeVals[val-1]);
#endif
}
//read value and return the converted value
val=bus_r(addr);
#ifdef VERBOSE
printf("Value read from reg is %d\n",val);
#endif
switch(val){
case 6:val=1;break;
case 2:val=2;break;
case 0:val=3;break;
case 1:val=4;break;
default:printf("Weird value read:%d\n",val);return -3;break;
}
#ifdef VERBOSE
printf("Confgain of module:%d is set to %s gain of val:%d\n",imod,cGainVal[val-1],val);
#endif
return val;
}
u_int32_t runBusy(void) { u_int32_t runBusy(void) {
return bus_r(STATUS_REG)&RUN_BUSY_BIT; return bus_r(STATUS_REG)&RUN_BUSY_BIT;
} }

View File

@ -47,7 +47,8 @@ int setContinousReadOut(int d);
int setDACRegister(int idac, int val, int imod); int setDACRegister(int idac, int val, int imod);
float getTemperature(int tempSensor, int imod); float getTemperature(int tempSensor, int imod);
int getHighVoltage(int val, int imod); int initHighVoltage(int val, int imod);
int initConfGain(int val, int imod);
u_int64_t getMcsNumber(); u_int64_t getMcsNumber();
u_int32_t getMcsVersion(); u_int32_t getMcsVersion();

View File

@ -760,21 +760,40 @@ float getTemperatureByModule(int tempSensor, int imod)
} }
int getHighVoltageByModule(int val, int imod) int initHighVoltageByModule(int val, int imod)
{ {
int im; int im;
//for the particular module //for the particular module
if (imod>=0 && imod<nModX) { if (imod>=0 && imod<nModX) {
return getHighVoltage(val,imod); return initHighVoltage(val,imod);
} }
else{ else{
//checks if all modules have the same value(ALLMOD) //checks if all modules have the same value(ALLMOD)
for (im=1; im<nModX; im++) { for (im=1; im<nModX; im++) {
if (getHighVoltage(val,im)!=getHighVoltage(val,0)) { if (initHighVoltage(val,im)!=initHighVoltage(val,0)) {
return -1; return -1;
} }
} }
return getHighVoltage(val,0); return initHighVoltage(val,0);
}
}
int initConfGainByModule(int val, int imod)
{
int im;
//for the particular module
if (imod>=0 && imod<nModX) {
return initConfGain(val,imod);
}
else{
//checks if all modules have the same value(ALLMOD)
for (im=1; im<nModX; im++) {
if (initConfGain(val,im)!=initConfGain(val,0)) {
return -1;
}
}
return initConfGain(val,0);
} }
} }

View File

@ -31,8 +31,8 @@ enum {VREF_DS, VCASCN_PB, VCASCP_PB, VOUT_CM, VCASC_OUT, VIN_CM, VREF_COMP, IB_T
#define DACCS {0,0,1,1,2,2,3,3,4,4,5,5,6,6} #define DACCS {0,0,1,1,2,2,3,3,4,4,5,5,6,6}
#define DACADDR {0,1,0,1,0,1,0,1,0,1,0,1,0,1} #define DACADDR {0,1,0,1,0,1,0,1,0,1,0,1,0,1}
//Temp/HIGH VOLTAGE Definitions //Register Definitions for temp,hv,dac gain
enum {TEMP_ADC, TEMP_FPGA, HIGH_VOLTAGE}; enum {TEMP_ADC, TEMP_FPGA, HIGH_VOLTAGE, CONFGAIN};
//dynamic range //dynamic range
#define MAX5523 #define MAX5523
@ -120,9 +120,10 @@ float getDACbyIndexDACU(int ind, int imod);
int getThresholdEnergy(); int getThresholdEnergy();
int setThresholdEnergy(int ethr); int setThresholdEnergy(int ethr);
/* Temp/HV routines*/ /* Other DAC index routines*/
float getTemperatureByModule(int tempSensor, int imod); float getTemperatureByModule(int tempSensor, int imod);
int getHighVoltageByModule(int val, int imod); int initHighVoltageByModule(int val, int imod);
int initConfGainByModule(int val, int imod);
/* Initialization*/ /* Initialization*/
int initChannel(int ft,int cae, int ae, int coe, int ocoe, int counts,int imod ); int initChannel(int ft,int cae, int ae, int coe, int ocoe, int counts,int imod );

View File

@ -792,7 +792,7 @@ int set_dac(int fnum) {
int n; int n;
float val; float val;
int idac=0; int idac=0;
int itemp=-1; int ireg=-1;
sprintf(mess,"Can't set DAC/TEMP/HV\n"); sprintf(mess,"Can't set DAC/TEMP/HV\n");
@ -847,13 +847,16 @@ int set_dac(int fnum) {
idac=IB_TESTC; idac=IB_TESTC;
break; break;
case TEMPERATURE_ADC: case TEMPERATURE_ADC:
itemp=TEMP_ADC; ireg=TEMP_ADC;
break; break;
case TEMPERATURE_FPGA: case TEMPERATURE_FPGA:
itemp=TEMP_FPGA; ireg=TEMP_FPGA;
break; break;
case HV_POT: case HV_POT:
itemp=HIGH_VOLTAGE; ireg=HIGH_VOLTAGE;
break;
case G_CONF_GAIN:
ireg=CONFGAIN;
break; break;
default: default:
printf("Unknown DAC/TEMP/HV index %d\n",ind); printf("Unknown DAC/TEMP/HV index %d\n",ind);
@ -863,14 +866,18 @@ int set_dac(int fnum) {
if (ret==OK) { if (ret==OK) {
//dac //dac
if(itemp==-1) if(ireg==-1)
retval=initDACbyIndexDACU(idac,val,imod); retval=initDACbyIndexDACU(idac,val,imod);
else else
{ //HV {//Conf gain
if(itemp==HIGH_VOLTAGE) if (ireg==CONFGAIN)
retval=getHighVoltageByModule(val,imod); retval=initConfGainByModule(val,imod);
else//Temp //HV or conf gain
retval=getTemperatureByModule(itemp,imod); else if(ireg==HIGH_VOLTAGE)
retval=initHighVoltageByModule(val,imod);
//Temp
else
retval=getTemperatureByModule(ireg,imod);
} }
} }
#endif #endif
@ -878,8 +885,12 @@ int set_dac(int fnum) {
printf("DAC/TEMP/HV set to %f V\n", retval); printf("DAC/TEMP/HV set to %f V\n", retval);
#endif #endif
ret=FAIL; ret=FAIL;
if (itemp==HIGH_VOLTAGE){ if((ireg==HIGH_VOLTAGE)||(ireg==CONFGAIN)){
if (retval!=-1) 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\n");
else
ret=OK; ret=OK;
} }
else if (retval==val || val==-1) else if (retval==val || val==-1)
@ -888,7 +899,6 @@ int set_dac(int fnum) {
if(ret==FAIL) if(ret==FAIL)
printf("Setting dac/hv %d of module %d: wrote %f but read %f\n", ind, imod, val, retval); printf("Setting dac/hv %d of module %d: wrote %f but read %f\n", ind, imod, val, retval);
/* send answer */ /* send answer */
/* send OK/failed */ /* send OK/failed */
n = sendDataOnly(&ret,sizeof(ret)); n = sendDataOnly(&ret,sizeof(ret));