mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 15:20:02 +02:00
implemented high voltage for normal modules
This commit is contained in:
parent
44d6b0ffc0
commit
b1a3a224ff
@ -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;
|
*top = 0;
|
||||||
*master = 0;
|
*master = 0;
|
||||||
//mapping new memory to read master top module configuration
|
//mapping new memory to read master top module configuration
|
||||||
@ -168,6 +168,8 @@ void Beb_GetModuleCopnfiguration(int* master, int* top){
|
|||||||
*top = 1;
|
*top = 1;
|
||||||
if(ret&MASTER_BIT_MASK)
|
if(ret&MASTER_BIT_MASK)
|
||||||
*master = 1;
|
*master = 1;
|
||||||
|
if(ret&NORMAL_MODULE_BIT_MASK)
|
||||||
|
*normal = 1;
|
||||||
//close file pointer
|
//close file pointer
|
||||||
Beb_close(fd,csp0base);
|
Beb_close(fd,csp0base);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ struct BebInfo{
|
|||||||
unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb);
|
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);
|
void Beb_EndofDataSend(int tengiga);
|
||||||
|
|
||||||
int Beb_SetMasterViaSoftware();
|
int Beb_SetMasterViaSoftware();
|
||||||
|
@ -61,6 +61,7 @@ int Feb_Control_current_index;
|
|||||||
|
|
||||||
int Feb_Control_counter_bit = 1;
|
int Feb_Control_counter_bit = 1;
|
||||||
int Feb_control_master = 0;
|
int Feb_control_master = 0;
|
||||||
|
int Feb_control_normal = 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];
|
||||||
@ -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;
|
unsigned int i;
|
||||||
Feb_Control_module_number = 0;
|
Feb_Control_module_number = 0;
|
||||||
Feb_Control_current_index = 0;
|
Feb_Control_current_index = 0;
|
||||||
Feb_control_master = master;
|
Feb_control_master = master;
|
||||||
|
Feb_control_normal = normal;
|
||||||
|
|
||||||
//global send
|
//global send
|
||||||
Feb_Control_AddModule1(0,1,0xff,0,1);
|
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){
|
//only master gets to call this function
|
||||||
return Feb_Control_SetHighVoltage1(Feb_Control_module_number,value);
|
int Feb_Control_SetHighVoltage(int value){
|
||||||
}
|
|
||||||
|
|
||||||
int Feb_Control_SetHighVoltage1(unsigned int module_num,float value){
|
if(!Feb_control_normal){
|
||||||
unsigned int module_index=0;
|
cprintf(RED,"\nError: Setting High Voltage not implemented for special modules\n");
|
||||||
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);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}else
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if(!Feb_Control_SendHighVoltage(Module_GetTopRightAddress(&modules[module_index]),&value)) return 0;
|
printf(" Setting High Voltage: %d(v)\t",value);
|
||||||
|
|
||||||
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");;
|
|
||||||
|
|
||||||
static const unsigned int nsteps = 256;
|
static const unsigned int nsteps = 256;
|
||||||
static const float vmin=0;
|
static const float vmin=0;
|
||||||
static const float vmax=300;
|
static const float vmax=300;
|
||||||
|
unsigned int dacval = 0;
|
||||||
|
|
||||||
unsigned int b = 0;
|
//open file
|
||||||
if(!Feb_Control_VoltageToDAC(*value,&b,nsteps,vmin,vmax)){
|
FILE* fd=fopen("/sys/class/hwmon/hwmon5/device/out0_output","w");
|
||||||
printf("Waring: SetHighVoltage bad value, %f. The range is 0 to 300 V.\n",*value);
|
if(fd==NULL){
|
||||||
|
cprintf(RED,"\nWarning: Could not open file for writing to set high voltage\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
//calculate dac value
|
||||||
unsigned int r = 0x20000000 | (b&0xff);
|
if(!Feb_Control_VoltageToDAC(value,&dacval,nsteps,vmin,vmax)){
|
||||||
if(Feb_Control_activated){
|
cprintf(RED,"\nWarning: SetHighVoltage bad value, %d. The range is 0 to 300 V.\n",value);
|
||||||
if(!Feb_Interface_WriteRegister(dst_num,0,r,0,0)){
|
|
||||||
cprintf(RED,"Warning: trouble setting high voltage for dst_num %d.\n",dst_num);
|
|
||||||
return 0;
|
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;
|
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){
|
int Feb_Control_DecodeDACString(char* dac_str, unsigned int* module_index, int* top, int* bottom, unsigned int* dac_ch){
|
||||||
char* local_s = dac_str;
|
char* local_s = dac_str;
|
||||||
|
@ -84,7 +84,6 @@ int Feb_Control_GetModuleNumber();
|
|||||||
int Feb_Control_VoltageToDAC(float value, unsigned int* digital, unsigned int nsteps, float vmin, float vmax);
|
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);
|
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);
|
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();
|
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();
|
int Feb_Control_CheckSetup();
|
||||||
|
|
||||||
unsigned int Feb_Control_GetNModules();
|
unsigned int Feb_Control_GetNModules();
|
||||||
unsigned int Feb_Control_GetNHalfModules();
|
unsigned int Feb_Control_GetNHalfModules();
|
||||||
|
|
||||||
int Feb_Control_SetHighVoltage(float value);
|
int Feb_Control_SetHighVoltage(int value);
|
||||||
int Feb_Control_SetHighVoltage1(unsigned int module_num,float value);
|
int Feb_Control_GetHighVoltage(int* value);
|
||||||
|
|
||||||
|
|
||||||
int Feb_Control_SetIDelays(unsigned int module_num, unsigned int ndelay_units);
|
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);
|
int Feb_Control_SetIDelays1(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units);
|
||||||
|
@ -115,6 +115,8 @@
|
|||||||
//module configuration
|
//module configuration
|
||||||
#define TOP_BIT_MASK 0x00f
|
#define TOP_BIT_MASK 0x00f
|
||||||
#define MASTER_BIT_MASK 0x200
|
#define MASTER_BIT_MASK 0x200
|
||||||
|
#define NORMAL_MODULE_BIT_MASK 0x400
|
||||||
|
|
||||||
// Master Slave Top Bottom Definition
|
// Master Slave Top Bottom Definition
|
||||||
#define MODULE_CONFIGURATION_MASK 0x84
|
#define MODULE_CONFIGURATION_MASK 0x84
|
||||||
//Software Configuration
|
//Software Configuration
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -78,6 +78,7 @@ int default_offset_values[3] = {3851000,3851000,3851000};
|
|||||||
enum masterFlags masterMode=IS_SLAVE;
|
enum masterFlags masterMode=IS_SLAVE;
|
||||||
int top = 0;
|
int top = 0;
|
||||||
int master = 0;
|
int master = 0;
|
||||||
|
int normal = 0;
|
||||||
|
|
||||||
|
|
||||||
#define TEN_GIGA_BUFFER_SIZE 4112
|
#define TEN_GIGA_BUFFER_SIZE 4112
|
||||||
@ -142,7 +143,7 @@ int initDetector(){
|
|||||||
getModuleConfiguration();
|
getModuleConfiguration();
|
||||||
Feb_Interface_FebInterface();
|
Feb_Interface_FebInterface();
|
||||||
Feb_Control_FebControl();
|
Feb_Control_FebControl();
|
||||||
Feb_Control_Init(master,top,getDetectorNumber());
|
Feb_Control_Init(master,top,normal, getDetectorNumber());
|
||||||
printf("FEB Initialization done\n");
|
printf("FEB Initialization done\n");
|
||||||
Beb_Beb();
|
Beb_Beb();
|
||||||
printf("BEB Initialization done\n");
|
printf("BEB Initialization done\n");
|
||||||
@ -184,7 +185,7 @@ int initDetectorStop(){
|
|||||||
getModuleConfiguration();
|
getModuleConfiguration();
|
||||||
Feb_Interface_FebInterface();
|
Feb_Interface_FebInterface();
|
||||||
Feb_Control_FebControl();
|
Feb_Control_FebControl();
|
||||||
Feb_Control_Init(master,top,getDetectorNumber());
|
Feb_Control_Init(master,top,normal,getDetectorNumber());
|
||||||
printf("FEB Initialization done\n");
|
printf("FEB Initialization done\n");
|
||||||
/* Beb_Beb(-1);
|
/* Beb_Beb(-1);
|
||||||
printf("BEB constructor done\n");*/
|
printf("BEB constructor done\n");*/
|
||||||
@ -198,15 +199,18 @@ int initDetectorStop(){
|
|||||||
void getModuleConfiguration(){
|
void getModuleConfiguration(){
|
||||||
int *m=&master;
|
int *m=&master;
|
||||||
int *t=⊤
|
int *t=⊤
|
||||||
|
int *n=&normal;
|
||||||
/*if(getDetectorNumber() == 0xbeb015){
|
/*if(getDetectorNumber() == 0xbeb015){
|
||||||
master = 1;
|
master = 1;
|
||||||
top = 1;
|
top = 1;
|
||||||
}*/
|
}*/
|
||||||
Beb_GetModuleCopnfiguration(m,t);
|
Beb_GetModuleConfiguration(m,t,n);
|
||||||
if(top) printf("*************** TOP ***************\n");
|
if(top) printf("*************** TOP ***************\n");
|
||||||
else printf("*************** BOTTOM ***************\n");
|
else printf("*************** BOTTOM ***************\n");
|
||||||
if(master) printf("*************** MASTER ***************\n");
|
if(master) printf("*************** MASTER ***************\n");
|
||||||
else printf("*************** SLAVE ***************\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){
|
int setHighVoltage(int val, int imod){
|
||||||
if(val!=-1){
|
if(val!=-1){
|
||||||
printf(" Setting High Voltage: %d\n",val);
|
|
||||||
if(!master)
|
|
||||||
eiger_highvoltage = val;
|
|
||||||
else if(Feb_Control_SetHighVoltage(val))
|
|
||||||
eiger_highvoltage = 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;
|
return eiger_highvoltage;
|
||||||
}
|
}
|
||||||
|
@ -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]);
|
printf("DAC set to %d in dac units and %d mV\n", retval[0],retval[1]);
|
||||||
#endif
|
#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)
|
if(mV)
|
||||||
temp = retval[1];
|
temp = retval[1];
|
||||||
else
|
else
|
||||||
temp = retval[0];
|
temp = retval[0];
|
||||||
if ((abs(temp-val)<=5) || val==-1) {
|
if ((abs(temp-val)<=5) || val==-1) {
|
||||||
ret=OK;
|
ret=OK;
|
||||||
if (differentClients)
|
|
||||||
ret=FORCE_UPDATE;
|
|
||||||
} else {
|
} else {
|
||||||
ret=FAIL;
|
ret=FAIL;
|
||||||
printf("Setting dac %d of module %d: wrote %d but read %d\n", idac, imod, val, temp);
|
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 answer */
|
||||||
/* send OK/failed */
|
/* send OK/failed */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user