implemented high voltage for normal modules

This commit is contained in:
Dhanya Maliakal 2016-11-11 14:43:18 +01:00
parent 44d6b0ffc0
commit b1a3a224ff
12 changed files with 104 additions and 55 deletions

View File

@ -149,7 +149,7 @@ void Beb_Beb(){
void Beb_GetModuleCopnfiguration(int* master, int* top){
void Beb_GetModuleConfiguration(int* master, int* top, int* normal){
*top = 0;
*master = 0;
//mapping new memory to read master top module configuration
@ -168,6 +168,8 @@ void Beb_GetModuleCopnfiguration(int* master, int* top){
*top = 1;
if(ret&MASTER_BIT_MASK)
*master = 1;
if(ret&NORMAL_MODULE_BIT_MASK)
*normal = 1;
//close file pointer
Beb_close(fd,csp0base);
}

View File

@ -45,7 +45,7 @@ struct BebInfo{
unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb);
void Beb_GetModuleCopnfiguration(int* master, int* top);
void Beb_GetModuleConfiguration(int* master, int* top, int* normal);
void Beb_EndofDataSend(int tengiga);
int Beb_SetMasterViaSoftware();

View File

@ -61,6 +61,7 @@ int Feb_Control_current_index;
int Feb_Control_counter_bit = 1;
int Feb_control_master = 0;
int Feb_control_normal = 0;
unsigned int Feb_Control_rate_correction_table[1024];
double Feb_Control_rate_meas[16384];
@ -181,11 +182,12 @@ void Feb_Control_FebControl(){
int Feb_Control_Init(int master, int top, int module_num){
int Feb_Control_Init(int master, int top, int normal, int module_num){
unsigned int i;
Feb_Control_module_number = 0;
Feb_Control_current_index = 0;
Feb_control_master = master;
Feb_control_normal = normal;
//global send
Feb_Control_AddModule1(0,1,0xff,0,1);
@ -492,59 +494,94 @@ float Feb_Control_DACToVoltage(unsigned int digital,unsigned int nsteps,float vm
}
int Feb_Control_SetHighVoltage(float value){
return Feb_Control_SetHighVoltage1(Feb_Control_module_number,value);
}
//only master gets to call this function
int Feb_Control_SetHighVoltage(int value){
int Feb_Control_SetHighVoltage1(unsigned int module_num,float value){
unsigned int module_index=0;
unsigned int i;
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);
if(!Feb_control_normal){
cprintf(RED,"\nError: Setting High Voltage not implemented for special modules\n");
return 0;
}
}else
return 0;
if(!Feb_Control_SendHighVoltage(Module_GetTopRightAddress(&modules[module_index]),&value)) return 0;
if(module_index!=0) Module_SetHighVoltage(&modules[module_index],value);
else for(i=0;i<moduleSize;i++) Module_SetHighVoltage(&modules[i],value);
printf("\tHigh voltage of dst %d set to %f.\n",Module_GetTopRightAddress(&modules[module_index]),Module_GetHighVoltage(&modules[module_index]));
return 1;
}
int Feb_Control_SendHighVoltage(unsigned int dst_num,float* value){
// printf("sending high voltage to dst_num "<<dst_num<<".\n");;
printf(" Setting High Voltage: %d(v)\t",value);
static const unsigned int nsteps = 256;
static const float vmin=0;
static const float vmax=300;
unsigned int dacval = 0;
unsigned int b = 0;
if(!Feb_Control_VoltageToDAC(*value,&b,nsteps,vmin,vmax)){
printf("Waring: SetHighVoltage bad value, %f. The range is 0 to 300 V.\n",*value);
//open file
FILE* fd=fopen("/sys/class/hwmon/hwmon5/device/out0_output","w");
if(fd==NULL){
cprintf(RED,"\nWarning: Could not open file for writing to set high voltage\n");
return 0;
}
unsigned int r = 0x20000000 | (b&0xff);
if(Feb_Control_activated){
if(!Feb_Interface_WriteRegister(dst_num,0,r,0,0)){
cprintf(RED,"Warning: trouble setting high voltage for dst_num %d.\n",dst_num);
//calculate dac value
if(!Feb_Control_VoltageToDAC(value,&dacval,nsteps,vmin,vmax)){
cprintf(RED,"\nWarning: SetHighVoltage bad value, %d. The range is 0 to 300 V.\n",value);
return 0;
}
}
//convert to string, add 0 and write to file
fprintf(fd, "%d0\n", dacval);
*value = Feb_Control_DACToVoltage(b,nsteps,vmin,vmax);
printf("%d(dac)\n", dacval);
fclose(fd);
return 1;
}
int Feb_Control_GetHighVoltage(int* value){
if(!Feb_control_normal){
cprintf(RED,"\nError: Getting High Voltage not implemented for special modules\n");
return 0;
}
printf(" Getting High Voltage: ");
static const unsigned int nsteps = 256;
static const float vmin=0;
static const float vmax=300;
unsigned int dacval = 0;
size_t readbytes=0;
char* line=NULL;
//open file
FILE* fd=fopen("/sys/class/hwmon/hwmon5/device/in0_input","r");
if(fd==NULL){
cprintf(RED,"\nWarning: Could not open file for writing to get high voltage\n");
return 0;
}
// Read twice, since the first value is sometimes outdated
if(getline(&line, &readbytes, fd) == -1){
cprintf(RED,"\nWarning: could not read file to get high voltage\n");
return 0;
}
rewind(fd);
free(line);
readbytes=0;
readbytes = getline(&line, &readbytes, fd);
if(readbytes == -1){
cprintf(RED,"\nWarning: could not read file to get high voltage\n");
return 0;
}
// Remove the trailing 0
dacval = atoi(line)/10;
//convert dac to v
*value = (int)(Feb_Control_DACToVoltage(dacval,nsteps,vmin,vmax)+0.5);
printf("%d(v)\t%d(dac)\n", *value, dacval);
free(line);
fclose(fd);
return 1;
}
int Feb_Control_DecodeDACString(char* dac_str, unsigned int* module_index, int* top, int* bottom, unsigned int* dac_ch){
char* local_s = dac_str;

View File

@ -84,7 +84,6 @@ int Feb_Control_GetModuleNumber();
int Feb_Control_VoltageToDAC(float value, unsigned int* digital, unsigned int nsteps, float vmin, float vmax);
float Feb_Control_DACToVoltage(unsigned int digital,unsigned int nsteps,float vmin,float vmax);
int Feb_Control_SendHighVoltage(unsigned int module_index, float* value);
int Feb_Control_SendIDelays(unsigned int dst_num, int chip_lr, unsigned int channels, unsigned int ndelay_units);
@ -112,15 +111,14 @@ int Feb_Control_GetModuleNumber();
void Feb_Control_FebControl();
int Feb_Control_Init(int master, int top, int module_num);
int Feb_Control_Init(int master, int top, int normal, int module_num);
int Feb_Control_CheckSetup();
unsigned int Feb_Control_GetNModules();
unsigned int Feb_Control_GetNHalfModules();
int Feb_Control_SetHighVoltage(float value);
int Feb_Control_SetHighVoltage1(unsigned int module_num,float value);
int Feb_Control_SetHighVoltage(int value);
int Feb_Control_GetHighVoltage(int* value);
int Feb_Control_SetIDelays(unsigned int module_num, unsigned int ndelay_units);
int Feb_Control_SetIDelays1(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units);

View File

@ -115,6 +115,8 @@
//module configuration
#define TOP_BIT_MASK 0x00f
#define MASTER_BIT_MASK 0x200
#define NORMAL_MODULE_BIT_MASK 0x400
// Master Slave Top Bottom Definition
#define MODULE_CONFIGURATION_MASK 0x84
//Software Configuration

View File

@ -78,6 +78,7 @@ int default_offset_values[3] = {3851000,3851000,3851000};
enum masterFlags masterMode=IS_SLAVE;
int top = 0;
int master = 0;
int normal = 0;
#define TEN_GIGA_BUFFER_SIZE 4112
@ -142,7 +143,7 @@ int initDetector(){
getModuleConfiguration();
Feb_Interface_FebInterface();
Feb_Control_FebControl();
Feb_Control_Init(master,top,getDetectorNumber());
Feb_Control_Init(master,top,normal, getDetectorNumber());
printf("FEB Initialization done\n");
Beb_Beb();
printf("BEB Initialization done\n");
@ -184,7 +185,7 @@ int initDetectorStop(){
getModuleConfiguration();
Feb_Interface_FebInterface();
Feb_Control_FebControl();
Feb_Control_Init(master,top,getDetectorNumber());
Feb_Control_Init(master,top,normal,getDetectorNumber());
printf("FEB Initialization done\n");
/* Beb_Beb(-1);
printf("BEB constructor done\n");*/
@ -198,15 +199,18 @@ int initDetectorStop(){
void getModuleConfiguration(){
int *m=&master;
int *t=&top;
int *n=&normal;
/*if(getDetectorNumber() == 0xbeb015){
master = 1;
top = 1;
}*/
Beb_GetModuleCopnfiguration(m,t);
Beb_GetModuleConfiguration(m,t,n);
if(top) printf("*************** TOP ***************\n");
else printf("*************** BOTTOM ***************\n");
if(master) printf("*************** MASTER ***************\n");
else printf("*************** SLAVE ***************\n");
if(normal) printf("*************** NORMAL ***************\n");
else printf("*************** SPECIAL ***************\n");
}
@ -428,13 +432,17 @@ void setDAC(enum detDacIndex ind, int val, int imod, int mV, int retval[]){
}
int setHighVoltage(int val, int imod){
if(val!=-1){
printf(" Setting High Voltage: %d\n",val);
if(!master)
eiger_highvoltage = val;
else if(Feb_Control_SetHighVoltage(val))
eiger_highvoltage = val;
if(master)
Feb_Control_SetHighVoltage(val);
}
if(master && !Feb_Control_GetHighVoltage(&eiger_highvoltage)){
cprintf(RED,"Warning: Could not read high voltage\n");
return 0;
}
return eiger_highvoltage;
}

View File

@ -1258,21 +1258,23 @@ int set_dac(int file_des) {
printf("DAC set to %d in dac units and %d mV\n", retval[0],retval[1]);
#endif
if(ret == OK){
//takes time to set high voltage, so no check for it
if(ret == OK && ind != HV_POT && ind != HV_NEW){
if(mV)
temp = retval[1];
else
temp = retval[0];
if ((abs(temp-val)<=5) || val==-1) {
ret=OK;
if (differentClients)
ret=FORCE_UPDATE;
} else {
ret=FAIL;
printf("Setting dac %d of module %d: wrote %d but read %d\n", idac, imod, val, temp);
}
}
if(ret == OK && differentClients)
ret=FORCE_UPDATE;
/* send answer */
/* send OK/failed */