change server with new boundary for counts above teh max

This commit is contained in:
Gemma Tinti 2016-09-27 20:47:59 +02:00
parent 5c81abdce0
commit 8a80cb489d
2 changed files with 28 additions and 20 deletions

View File

@ -64,7 +64,7 @@ int Feb_control_master = 0;
unsigned int Feb_Control_rate_correction_table[1024]; unsigned int Feb_Control_rate_correction_table[1024];
double Feb_Control_rate_meas[16384]; double Feb_Control_rate_meas[16384];
double ratemax=-1;
void Module_Module(struct Module* mod,unsigned int number, unsigned int address_top){ void Module_Module(struct Module* mod,unsigned int number, unsigned int address_top){
unsigned int i; unsigned int i;
@ -1792,7 +1792,6 @@ int Feb_Control_PulseChip(int npulses){
int64_t Feb_Control_Get_RateTable_Tau_in_nsec(){ return Feb_Control_RateTable_Tau_in_nsec;} int64_t Feb_Control_Get_RateTable_Tau_in_nsec(){ return Feb_Control_RateTable_Tau_in_nsec;}
int64_t Feb_Control_Get_RateTable_Period_in_nsec(){ return Feb_Control_RateTable_Period_in_nsec;} int64_t Feb_Control_Get_RateTable_Period_in_nsec(){ return Feb_Control_RateTable_Period_in_nsec;}
//returns -1 if slope is too high
int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){ int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){
//period = exptime if 16bit, period = subexptime if 32 bit //period = exptime if 16bit, period = subexptime if 32 bit
@ -1803,25 +1802,28 @@ int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){
double tau_in_sec = (double)tau_in_Nsec/(double)1e9; double tau_in_sec = (double)tau_in_Nsec/(double)1e9;
printf(" tau %lf %lf ", (double)tau_in_Nsec, (double) tau_in_sec);
unsigned int np = 16384; //max slope 16 * 1024 unsigned int np = 16384; //max slope 16 * 1024
double b0[1024]; double b0[1024];
double m[1024]; double m[1024];
if(tau_in_sec<0||period_in_sec<0){ if(tau_in_sec<0||period_in_sec<0){
if(dr == 32) if(dr == 32)
printf("Error tau %f and sub_exposure_time %f must be greater than 0.\n", tau_in_sec, period_in_sec); printf("Error tau %lf and sub_exposure_time %lf must be greater than 0.\n", tau_in_sec, period_in_sec);
else else
printf("Error tau %f and exposure_time %f must be greater than 0.\n", tau_in_sec, period_in_sec); printf("Error tau %lf and exposure_time %lf must be greater than 0.\n", tau_in_sec, period_in_sec);
return 0; return 0;
} }
cprintf(BLUE, "Changing Rate Correction Table tau:%f sec, period:%f sec",tau_in_sec,period_in_sec); cprintf(BLUE, "Changing Rate Correction Table tau:%0.8f sec, period:%f sec",tau_in_sec,period_in_sec);
printf("\tCalculating table for tau of %lld ns.\n", tau_in_Nsec); printf("\tCalculating table for tau of %lld ns.\n", tau_in_Nsec);
int i; int i;
for(i=0;i<np;i++) for(i=0;i<np;i++){
Feb_Control_rate_meas[i] = i*exp(-i/period_in_sec*tau_in_sec); Feb_Control_rate_meas[i] = i*exp(-i/period_in_sec*tau_in_sec);
if(Feb_Control_rate_meas[i] > ratemax) ratemax= Feb_Control_rate_meas[i];
}
/* /*
b : index/address of block ram/rate correction table b : index/address of block ram/rate correction table
@ -1840,13 +1842,11 @@ int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){
*/ */
int next_i=0; int next_i=0;
double beforemax;
b0[0] = 0; b0[0] = 0;
m[0] = 1; m[0] = 1;
for(i=0; i<1024; i++) Feb_Control_rate_correction_table[0] = (((int)(m[0]+0.5)&0xf)<<14) | ((int)(b0[0]+0.5)&0x3fff);
Feb_Control_rate_correction_table[i] = 65535;
Feb_Control_rate_correction_table[0] = (((int)(m[0]+0.5)&0xf)<<14) | ((int)(b0[0]+0.5)&0x3fff);
int b=0; int b=0;
for(b=1;b<1024;b++){ for(b=1;b<1024;b++){
@ -1854,9 +1854,13 @@ int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){
double s=0,sx=0,sy=0,sxx=0,sxy=0; double s=0,sx=0,sy=0,sxx=0,sxy=0;
for(;;next_i++){ for(;;next_i++){
if(next_i>=np){ if(next_i>=np){
for(; b<1024; b++){
if(beforemax>ratemax) b0[b] = beforemax;
else b0[b] = ratemax;
m[b] = 15;
Feb_Control_rate_correction_table[b] = (((int)(m[b]+0.5)&0xf)<<14) | ((int)(b0[b]+0.5)&0x3fff);
}
b=1024; b=1024;
b0[b] = 16383;
m[b] = 15;
break; break;
} }
@ -1880,17 +1884,20 @@ int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){
double delta = s*sxx - sx*sx; double delta = s*sxx - sx*sx;
b0[b] = (sxx*sy - sx*sxy)/delta; b0[b] = (sxx*sy - sx*sxy)/delta;
m[b] = (s*sxy - sx*sy) /delta; m[b] = (s*sxy - sx*sy) /delta;
beforemax= b0[b];
if(m[b]<0||m[b]>15){ if(m[b]<0||m[b]>15){
m[b]=15; m[b]=15;
b0[b]=16383; if(beforemax>ratemax) b0[b] = beforemax;
else b0[b] = ratemax;
} }
/*printf("After Loop s: %f,\t sx: %f,\t sy: %f,\t sxx: %f,\t sxy: %f,\t " /*printf("After Loop s: %f,\t sx: %f,\t sy: %f,\t sxx: %f,\t sxy: %f,\t "
"next_i: %d,\t b: %d,\t Feb_Control_rate_meas[next_i]: %f\n", "next_i: %d,\t b: %d,\t Feb_Control_rate_meas[next_i]: %f\n",
s, sx, sy, sxx, sxy, next_i, b, Feb_Control_rate_meas[next_i]);*/ s, sx, sy, sxx, sxy, next_i, b, Feb_Control_rate_meas[next_i]);*/
// cout<<s<<" "<<sx<<" "<<sy<<" "<<sxx<<" "<<" "<<sxy<<" "<<delta<<" "<<m[b]<<" "<<b0[b]<<endl; // cout<<s<<" "<<sx<<" "<<sy<<" "<<sxx<<" "<<" "<<sxy<<" "<<delta<<" "<<m[b]<<" "<<b0[b]<<endl;
}else{ }else{
b0[b] = 16383; if(beforemax>ratemax) b0[b] = beforemax;
else b0[b] = ratemax;
m[b] = 15; m[b] = 15;
} }
Feb_Control_rate_correction_table[b] = (((int)(m[b]+0.5)&0xf)<<14) | ((int)(b0[b]+0.5)&0x3fff); Feb_Control_rate_correction_table[b] = (((int)(m[b]+0.5)&0xf)<<14) | ((int)(b0[b]+0.5)&0x3fff);
@ -1971,11 +1978,12 @@ int Feb_Control_PrintCorrectedValues(){
lsb = i&3; lsb = i&3;
base = Feb_Control_rate_correction_table[i>>2] & 0x3fff; base = Feb_Control_rate_correction_table[i>>2] & 0x3fff;
slope = ((Feb_Control_rate_correction_table[i>>2] & 0x3c000) >> 14); slope = ((Feb_Control_rate_correction_table[i>>2] & 0x3c000) >> 14);
delta = slope*lsb; delta = slope*lsb;
corr = delta+base; corr = delta+base;
if(base==16383 && slope==15) corr=4095; if(slope==15) corr= 3*slope+base;
printf("Readout Input: %d,\tBase:%d,\tSlope:%d,\tLSB:%d,\tDelta:%d\tResult:%d\tReal:%f\n", printf("Readout Input: %d,\tBase:%d,\tSlope:%d,\tLSB:%d,\tDelta:%d\tResult:%d\tReal:%lf\n",
i, base, slope, lsb, delta, corr, Feb_Control_rate_meas[i]); i, base, slope, lsb, delta, corr, Feb_Control_rate_meas[i]);
} }
return 1; return 1;