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];
double Feb_Control_rate_meas[16384];
double ratemax=-1;
void Module_Module(struct Module* mod,unsigned int number, unsigned int address_top){
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_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){
//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;
printf(" tau %lf %lf ", (double)tau_in_Nsec, (double) tau_in_sec);
unsigned int np = 16384; //max slope 16 * 1024
double b0[1024];
double m[1024];
if(tau_in_sec<0||period_in_sec<0){
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
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;
}
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);
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);
if(Feb_Control_rate_meas[i] > ratemax) ratemax= Feb_Control_rate_meas[i];
}
/*
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;
double beforemax;
b0[0] = 0;
m[0] = 1;
for(i=0; i<1024; i++)
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);
Feb_Control_rate_correction_table[0] = (((int)(m[0]+0.5)&0xf)<<14) | ((int)(b0[0]+0.5)&0x3fff);
int b=0;
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;
for(;;next_i++){
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;
b0[b] = 16383;
m[b] = 15;
break;
}
@ -1880,17 +1884,20 @@ int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){
double delta = s*sxx - sx*sx;
b0[b] = (sxx*sy - sx*sxy)/delta;
m[b] = (s*sxy - sx*sy) /delta;
beforemax= b0[b];
if(m[b]<0||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 "
"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]);*/
// cout<<s<<" "<<sx<<" "<<sy<<" "<<sxx<<" "<<" "<<sxy<<" "<<delta<<" "<<m[b]<<" "<<b0[b]<<endl;
}else{
b0[b] = 16383;
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);
@ -1971,11 +1978,12 @@ int Feb_Control_PrintCorrectedValues(){
lsb = i&3;
base = Feb_Control_rate_correction_table[i>>2] & 0x3fff;
slope = ((Feb_Control_rate_correction_table[i>>2] & 0x3c000) >> 14);
delta = slope*lsb;
corr = delta+base;
if(base==16383 && slope==15) corr=4095;
printf("Readout Input: %d,\tBase:%d,\tSlope:%d,\tLSB:%d,\tDelta:%d\tResult:%d\tReal:%f\n",
delta = slope*lsb;
corr = delta+base;
if(slope==15) corr= 3*slope+base;
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]);
}
return 1;