fixed corrections for rate correction, needed to reset daq completely

This commit is contained in:
Dhanya Maliakal 2016-02-17 15:17:40 +01:00
parent 764078d465
commit 8d2f54838a
7 changed files with 63 additions and 23 deletions

View File

@ -60,7 +60,7 @@ int Feb_Control_module_number;
int Feb_Control_current_index;
int Feb_Control_counter_bit = 1;
int Feb_control_master = 0;
unsigned int Feb_Control_rate_correction_table[1024];
double Feb_Control_rate_meas[16384];
@ -138,17 +138,17 @@ unsigned int Module_GetBottomLeftAddress(struct Module* mod) {return mod->botto
unsigned int Module_GetBottomRightAddress(struct Module* mod) {return mod->bottom_right_address;}
unsigned int Module_SetTopIDelay(struct Module* mod,unsigned int chip,unsigned int value) { return Module_TopAddressIsValid(mod) &&chip<4 ? (mod->idelay_top[chip]=value) : 0;} //chip 0=ll,1=lr,0=rl,1=rr
unsigned int Module_GetTopIDelay(struct Module* mod,unsigned int chip) { return chip<4 ? mod->idelay_top[chip] : 0;} //chip 0=ll,1=lr,0=rl,1=rr
unsigned int Module_GetTopIDelay(struct Module* mod,unsigned int chip) { return chip<4 ? mod->idelay_top[chip] : 0;} //chip 0=ll,1=lr,0=rl,1=rr
unsigned int Module_SetBottomIDelay(struct Module* mod,unsigned int chip,unsigned int value) { return Module_BottomAddressIsValid(mod) &&chip<4 ? (mod->idelay_bottom[chip]=value) : 0;} //chip 0=ll,1=lr,0=rl,1=rr
unsigned int Module_GetBottomIDelay(struct Module* mod,unsigned int chip) { return chip<4 ? mod->idelay_bottom[chip] : 0;} //chip 0=ll,1=lr,0=rl,1=rr
unsigned int Module_GetBottomIDelay(struct Module* mod,unsigned int chip) { return chip<4 ? mod->idelay_bottom[chip] : 0;} //chip 0=ll,1=lr,0=rl,1=rr
float Module_SetHighVoltage(struct Module* mod,float value) { return Module_TopAddressIsValid(mod) ? (mod->high_voltage=value) : -1;}
float Module_GetHighVoltage(struct Module* mod) { return mod->high_voltage;}
float Module_SetHighVoltage(struct Module* mod,float value) { return Feb_control_master ? (mod->high_voltage=value) : -1;}// Module_TopAddressIsValid(mod) ? (mod->high_voltage=value) : -1;}
float Module_GetHighVoltage(struct Module* mod) { return mod->high_voltage;}
int Module_SetTopDACValue(struct Module* mod,unsigned int i, int value) { return (i<Module_ndacs && Module_TopAddressIsValid(mod)) ? (mod->top_dac[i]=value) : -1;}
int Module_GetTopDACValue(struct Module* mod,unsigned int i) { return (i<Module_ndacs) ? mod->top_dac[i]:-1;}
int Module_SetBottomDACValue(struct Module* mod,unsigned int i, int value) { return (i<Module_ndacs && Module_BottomAddressIsValid(mod)) ? (mod->bottom_dac[i]=value) : -1;}
int Module_GetBottomDACValue(struct Module* mod,unsigned int i) { return (i<Module_ndacs) ? mod->bottom_dac[i]:-1;}
int Module_SetTopDACValue(struct Module* mod,unsigned int i, int value) { return (i<Module_ndacs && Module_TopAddressIsValid(mod)) ? (mod->top_dac[i]=value) : -1;}
int Module_GetTopDACValue(struct Module* mod,unsigned int i) { return (i<Module_ndacs) ? mod->top_dac[i] : -1;}
int Module_SetBottomDACValue(struct Module* mod,unsigned int i, int value) { return (i<Module_ndacs && Module_BottomAddressIsValid(mod)) ? (mod->bottom_dac[i]=value): -1;}
int Module_GetBottomDACValue(struct Module* mod,unsigned int i) { return (i<Module_ndacs) ? mod->bottom_dac[i] : -1;}
@ -178,6 +178,7 @@ int Feb_Control_Init(int master, int top, int module_num){
unsigned int i;
Feb_Control_module_number = 0;
Feb_Control_current_index = 0;
Feb_control_master = master;
//global send
Feb_Control_AddModule1(0,1,0xff,0,1);
@ -534,7 +535,7 @@ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){
}
int Feb_Control_CheckSetup(){
int Feb_Control_CheckSetup(int master){
printf("Checking Set up\n");
unsigned int i,j;
int ok = 1;
@ -552,7 +553,7 @@ int Feb_Control_CheckSetup(){
ok=0;
}
}
if(Module_GetHighVoltage(&modules[i])<0){
if((Feb_control_master) &&(Module_GetHighVoltage(&modules[i])<0)){
cprintf(RED,"Warning: module %d's high voltage not set.\n",Module_GetModuleNumber(&modules[i]));
ok=0;
}
@ -705,7 +706,7 @@ int Feb_Control_SetHighVoltage1(unsigned int module_num,float value){
unsigned int module_index=0;
unsigned int i;
if(Module_TopAddressIsValid(&modules[module_index])){
if(Feb_control_master){//if(Module_TopAddressIsValid(&modules[module_index])){
if(!Feb_Control_GetModuleIndex(module_num,&module_index)){/*||!Module_TopAddressIsValid(&modules[module_index])){*/
cprintf(RED,"Error could not set high voltage module number %d invalid.\n",module_num);
return 0;
@ -958,7 +959,9 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){
for(l_r=0;l_r<2;l_r++){ // l_r loop
//printf("\nl_r:%d\t\t",l_r);
unsigned int disable_chip_mask = l_r ? DAQ_CS_BAR_LEFT : DAQ_CS_BAR_RIGHT;
if(!(Feb_Interface_WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8,0,0)&&Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT)&&Feb_Control_StartDAQOnlyNWaitForFinish(5000))){
if(!(Feb_Interface_WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8,0,0)
&&Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT)
&&Feb_Control_StartDAQOnlyNWaitForFinish(5000))){
printf("Could not select chips\n");
return 0;
}
@ -1183,7 +1186,7 @@ int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag){
}
int Feb_Control_Reset(){
int Feb_Control_Reset(){printf("Reset daq\n");
if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_RESET,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)){
cprintf(RED,"Warning: Could not reset daq, no response.\n");
return 0;
@ -1897,9 +1900,17 @@ int Feb_Control_SetRateCorrectionTable(unsigned int *table){
return 0;
}
printf("Setting rate correction table. %d %d %d %d ....\n",
table[0],table[1],table[2],table[3]);
//was added otherwise after an acquire, startdaqonlywatiforfinish waits forever
if(!Feb_Control_SetCommandRegister(DAQ_RESET_COMPLETELY)){
cprintf(RED,"Warning: Could not Feb_Control_SetCommandRegister for loading trim bits.\n");
return 0;
}
printf("daq reset completely\n");
if(Module_TopAddressIsValid(&modules[1])){
if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
!Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
@ -1915,7 +1926,7 @@ int Feb_Control_SetRateCorrectionTable(unsigned int *table){
return 0;
}
}
cprintf(BLUE, "done with writing to memory\n");
return 1;
}

View File

@ -522,6 +522,18 @@ int setRateCorrection(int64_t custom_tau_in_nsec){//in nanosec (will never be -1
return Feb_Control_Get_RateTable_Tau_in_nsec();
}
int getRateCorrectionEnable(){
return Feb_Control_GetRateCorrectionVariable();
}
int getDefaultSettingsTau_in_nsec(){
switch(thisSettings){
case STANDARD: return STANDARD_TAU;
case HIGHGAIN: return HIGHGAIN_TAU;
case LOWGAIN: return LOWGAIN_TAU;
default: return -1;
}
}
int setModule(sls_detector_module myMod, int* gain, int* offset){
@ -577,7 +589,6 @@ int setModule(sls_detector_module myMod, int* gain, int* offset){
return FAIL;
}
return 0;
}

View File

@ -2501,7 +2501,6 @@ double multiSlsDetector::getRateCorrectionTau(){
}
if (getDetectorsType() != MYTHEN){
cout<<"ret1:"<<ret1<<endl;
//if set by the slsDetector
if(ret1 == 0)
thisMultiDetector->correctionMask&=~(1<<RATE_CORRECTION);

View File

@ -2771,7 +2771,7 @@ int slsDetector::setModule(sls_detector_module module, int* gainval, int* offset
}
}
if(ret == FAIL && thisDetector->myDetectorType == EIGER && strcasestr(mess,"tau")){
if(ret == FAIL && thisDetector->myDetectorType == EIGER && strcasestr(mess,"Rate")){
setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION));
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
thisDetector->tDead = 0;

View File

@ -52,6 +52,8 @@ int pulsePixel(int n, int x, int y);
int pulsePixelNMove(int n, int x, int y);
int pulseChip(int n);
int setRateCorrection(int64_t custom_tau_in_nsec);
int getRateCorrectionEnable();
int getDefaultSettingsTau_in_nsec();
#endif
#if defined(MYTHEND) || defined(GOTTHARDD)

View File

@ -1899,6 +1899,25 @@ int set_module(int file_des) {
} else {
#ifdef EIGERD
ret=setModule(myModule, myGain, myOffset);
//rate correction
if(getRateCorrectionEnable()){
int64_t tau_ns = getDefaultSettingsTau_in_nsec();
if(tau_ns < 0){
sprintf(mess,"Cannot set Rate correction. Rate correction Deactivated, settings %d not recognized by detector\n",thisSettings);
cprintf(RED,"%s",mess);
ret = FAIL;
setRateCorrection(0);
}
retval = setRateCorrection(tau_ns); //tau_ns will not be -1 here
if(tau_ns != retval){
if(retval == -1)
strcpy(mess,"Could not set Rate correction. Rate correction Deactivated, (tau/subexptime) must be < 0.0015\n");
else
strcpy(mess,"Could not set Rate correction. Rate correction Deactivated\n");
cprintf(RED,"%s",mess);
ret = FAIL;
}
}
#else
ret=setModule(myModule);
#endif
@ -3860,13 +3879,11 @@ int rate_correct(int file_des) {
#endif
#ifdef SLS_DETECTOR_FUNCTION_LIST
//tau = -1, use default tau of settings
if((ret==OK)&&(tau_ns<0)){
switch(thisSettings){
case STANDARD: tau_ns = STANDARD_TAU; break;
case HIGHGAIN: tau_ns = HIGHGAIN_TAU; break;
case LOWGAIN: tau_ns = LOWGAIN_TAU; break;
default:
tau_ns = getDefaultSettingsTau_in_nsec();
if(tau_ns < 0){
ret = FAIL;
sprintf(mess,"Cannot set rate correction. Settings %d not recognized by detector\n",thisSettings);
cprintf(RED,"%s",mess);