mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-22 14:38:14 +02:00
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:
parent
9f85175dce
commit
05aaefb8f0
@ -856,28 +856,29 @@ float getTemperature(int tempSensor, int imod){
|
||||
float val;
|
||||
char cTempSensor[2][100]={"ADCs/ASICs","VRs/FPGAs"};
|
||||
imod=0;//ignoring more than 1 mod for now
|
||||
int i,j,k,repeats=6,times=11;
|
||||
u_int32_t tempVal=0;
|
||||
|
||||
int i,j,k,repeats=6;
|
||||
u_int32_t tempVal=0,tempVal2=0;
|
||||
#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
|
||||
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
|
||||
|
||||
for(k=0;k<2;k++){
|
||||
for(i=0;i<times;i++) {
|
||||
//repeats is number of register writes for delay
|
||||
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
|
||||
for(j=0;j<repeats;j++)
|
||||
bus_w(TEMP_IN_REG,(T1_CLK_BIT)&~(T1_CS_BIT)|(T2_CLK_BIT));//high clk low cs
|
||||
for(i=0;i<20;i++) {
|
||||
//repeats is number of register writes for delay
|
||||
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
|
||||
for(j=0;j<repeats;j++)
|
||||
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
|
||||
tempVal= (tempVal<<1) + (bus_r(TEMP_OUT_REG) & (1<<tempSensor));
|
||||
if(i<=10){//only the first time
|
||||
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
|
||||
val=((float)tempVal)/4.0;
|
||||
|
||||
@ -887,46 +888,96 @@ float getTemperature(int tempSensor, int imod){
|
||||
return val;
|
||||
}
|
||||
|
||||
int getHighVoltage(int val, int imod){
|
||||
|
||||
|
||||
int initHighVoltage(int val, int imod){
|
||||
#ifdef VERBOSE
|
||||
printf("Setting/Getting High Voltage of module:%d with val:%d\n",imod,val);
|
||||
#endif
|
||||
volatile u_int32_t addr=HV_REG;
|
||||
int loop;
|
||||
int found=0;
|
||||
int input []={ 0, 90,110,120,150,180,200};
|
||||
int value1[]={0x0,0x0,0x2,0x4,0x6,0x8,0xA};
|
||||
int value2[]={0x0,0x1,0x3,0x5,0x7,0x9,0xB};
|
||||
if(val!=-1)
|
||||
{
|
||||
for(loop=0;loop<7;loop++)
|
||||
if(val==input[loop]) {
|
||||
found=1;
|
||||
int writeVal,writeVal2;
|
||||
switch(val){
|
||||
case -1: break;
|
||||
case 0: writeVal=0x0; writeVal2=0x0; break;
|
||||
case 90: writeVal=0x0; writeVal2=0x1; break;
|
||||
case 110:writeVal=0x2; writeVal2=0x3; break;
|
||||
case 120:writeVal=0x4; writeVal2=0x5; break;
|
||||
case 150:writeVal=0x6; writeVal2=0x7; break;
|
||||
case 180:writeVal=0x8; writeVal2=0x9; break;
|
||||
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
|
||||
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
|
||||
bus_w(addr,value1[loop]);
|
||||
bus_w(addr,value2[loop]);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
//read value and return the converted value
|
||||
val=bus_r(addr);
|
||||
#ifdef VERBOSE
|
||||
printf("High Voltage of module:%d is %d\n",imod,val);
|
||||
printf("Value read from reg is %d\n",val);
|
||||
#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) {
|
||||
return bus_r(STATUS_REG)&RUN_BUSY_BIT;
|
||||
}
|
||||
|
@ -47,7 +47,8 @@ int setContinousReadOut(int d);
|
||||
int setDACRegister(int idac, int val, 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_int32_t getMcsVersion();
|
||||
|
@ -760,21 +760,40 @@ float getTemperatureByModule(int tempSensor, int imod)
|
||||
}
|
||||
|
||||
|
||||
int getHighVoltageByModule(int val, int imod)
|
||||
int initHighVoltageByModule(int val, int imod)
|
||||
{
|
||||
int im;
|
||||
//for the particular module
|
||||
if (imod>=0 && imod<nModX) {
|
||||
return getHighVoltage(val,imod);
|
||||
return initHighVoltage(val,imod);
|
||||
}
|
||||
else{
|
||||
//checks if all modules have the same value(ALLMOD)
|
||||
for (im=1; im<nModX; im++) {
|
||||
if (getHighVoltage(val,im)!=getHighVoltage(val,0)) {
|
||||
if (initHighVoltage(val,im)!=initHighVoltage(val,0)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 DACADDR {0,1,0,1,0,1,0,1,0,1,0,1,0,1}
|
||||
|
||||
//Temp/HIGH VOLTAGE Definitions
|
||||
enum {TEMP_ADC, TEMP_FPGA, HIGH_VOLTAGE};
|
||||
//Register Definitions for temp,hv,dac gain
|
||||
enum {TEMP_ADC, TEMP_FPGA, HIGH_VOLTAGE, CONFGAIN};
|
||||
|
||||
//dynamic range
|
||||
#define MAX5523
|
||||
@ -120,9 +120,10 @@ float getDACbyIndexDACU(int ind, int imod);
|
||||
int getThresholdEnergy();
|
||||
int setThresholdEnergy(int ethr);
|
||||
|
||||
/* Temp/HV routines*/
|
||||
/* Other DAC index routines*/
|
||||
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*/
|
||||
int initChannel(int ft,int cae, int ae, int coe, int ocoe, int counts,int imod );
|
||||
|
@ -792,7 +792,7 @@ int set_dac(int fnum) {
|
||||
int n;
|
||||
float val;
|
||||
int idac=0;
|
||||
int itemp=-1;
|
||||
int ireg=-1;
|
||||
|
||||
sprintf(mess,"Can't set DAC/TEMP/HV\n");
|
||||
|
||||
@ -847,13 +847,16 @@ int set_dac(int fnum) {
|
||||
idac=IB_TESTC;
|
||||
break;
|
||||
case TEMPERATURE_ADC:
|
||||
itemp=TEMP_ADC;
|
||||
ireg=TEMP_ADC;
|
||||
break;
|
||||
case TEMPERATURE_FPGA:
|
||||
itemp=TEMP_FPGA;
|
||||
ireg=TEMP_FPGA;
|
||||
break;
|
||||
case HV_POT:
|
||||
itemp=HIGH_VOLTAGE;
|
||||
ireg=HIGH_VOLTAGE;
|
||||
break;
|
||||
case G_CONF_GAIN:
|
||||
ireg=CONFGAIN;
|
||||
break;
|
||||
default:
|
||||
printf("Unknown DAC/TEMP/HV index %d\n",ind);
|
||||
@ -863,14 +866,18 @@ int set_dac(int fnum) {
|
||||
|
||||
if (ret==OK) {
|
||||
//dac
|
||||
if(itemp==-1)
|
||||
if(ireg==-1)
|
||||
retval=initDACbyIndexDACU(idac,val,imod);
|
||||
else
|
||||
{ //HV
|
||||
if(itemp==HIGH_VOLTAGE)
|
||||
retval=getHighVoltageByModule(val,imod);
|
||||
else//Temp
|
||||
retval=getTemperatureByModule(itemp,imod);
|
||||
{//Conf gain
|
||||
if (ireg==CONFGAIN)
|
||||
retval=initConfGainByModule(val,imod);
|
||||
//HV or conf gain
|
||||
else if(ireg==HIGH_VOLTAGE)
|
||||
retval=initHighVoltageByModule(val,imod);
|
||||
//Temp
|
||||
else
|
||||
retval=getTemperatureByModule(ireg,imod);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -878,8 +885,12 @@ int set_dac(int fnum) {
|
||||
printf("DAC/TEMP/HV set to %f V\n", retval);
|
||||
#endif
|
||||
ret=FAIL;
|
||||
if (itemp==HIGH_VOLTAGE){
|
||||
if (retval!=-1)
|
||||
if((ireg==HIGH_VOLTAGE)||(ireg==CONFGAIN)){
|
||||
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;
|
||||
}
|
||||
else if (retval==val || val==-1)
|
||||
@ -888,7 +899,6 @@ int set_dac(int fnum) {
|
||||
if(ret==FAIL)
|
||||
printf("Setting dac/hv %d of module %d: wrote %f but read %f\n", ind, imod, val, retval);
|
||||
|
||||
|
||||
/* send answer */
|
||||
/* send OK/failed */
|
||||
n = sendDataOnly(&ret,sizeof(ret));
|
||||
|
Loading…
x
Reference in New Issue
Block a user