settings for jungfrau

This commit is contained in:
Dhanya Maliakal
2015-12-01 16:43:23 +01:00
parent 58dbc59af2
commit 61f0506c2c
9 changed files with 306 additions and 136 deletions

View File

@ -1576,37 +1576,19 @@ int initHighVoltage(int val, int imod){
int initConfGain(int isettings,int val,int imod){
int retval;
u_int32_t addr=GAIN_REG;
if(val!=-1){
#ifdef VERBOSE
printf("Setting Gain of module:%d with val:%d\n",imod,val);
#endif
bus_w(addr,((val<<GAIN_OFFSET)|(bus_r(addr)&~GAIN_MASK)));
}
retval=(bus_r(addr)&GAIN_MASK);
#ifdef VERBOSE
printf("Value read from Gain reg is %d\n",retval);
#endif
if((val!=-1)&&(retval!=val))
return -1;
u_int32_t addr=CONFGAIN_REG;
if(isettings!=-1){
#ifdef VERBOSE
printf("Writing Settings of module:%d with val:%d\n",imod,isettings);
printf("Setting Gain of module:%d with val:%d\n",imod,val);
#endif
bus_w(addr,((isettings<<SETTINGS_OFFSET)|(bus_r(addr)&~SETTINGS_MASK)));
bus_w(addr,val);
}
retval=((bus_r(addr)&SETTINGS_MASK)>>SETTINGS_OFFSET);
retval=(bus_r(addr));
#ifdef VERBOSE
printf("Settings read from reg is %d\n",retval);
printf("Value read from Gain reg is %d\n",retval);
#endif
if((isettings!=-1)&&(retval!=isettings)){
printf("\n\nSettings r\n\n");
return -1;
}
return retval;
return retval;
}

View File

@ -847,38 +847,51 @@ int setSettings(int i, int imod) {
else
printf("\ninside set settings wit settings=%d...\n",i);
#endif
int confgain[] = CONF_GAIN;
int isett=-2,retval;
int isett=-1,val=-1,retval=-1;
enum conf_gain {
dynamic = 0x0f00, //dynamic
dynamichighgain0 = 0x0f01, //dynamichighgain0
fixgain1 = 0x0f02, //fixgain1
fixgain2 = 0x0f06, //fixgain2
forceswitchgain1 = 0x1f00, //forceswitchgain1
forceswitchgain2 = 0x3f00 //forceswitchgain2
};
//reading settings
if(i==GET_SETTINGS){
retval=initConfGainByModule(i,i,imod);
if(retval==i)
isett=UNDEFINED;
}
//writing settings
else{
retval=initConfGainByModule(i,confgain[i],imod);
if(retval!=i)
isett=UNDEFINED;
}
//if error while read/writing
if(isett==UNDEFINED)
printf("Error:Weird Value read back from the Gain/Settings Reg\n");
else{
//validating the settings read back
if((retval>=HIGHGAIN)&&(retval<=VERYHIGHGAIN))
isett=retval;
else{
isett=UNDEFINED;
printf("Error:Wrong Settings Read out:%d\n",retval);
}
}
thisSettings=isett;
//determine conf value to write
if(i!=GET_SETTINGS){
switch(i){
case DYNAMICGAIN: val = dynamic;break;
case DYNAMICHG0: val = dynamichighgain0;break;
case FIXGAIN1: val = fixgain1;break;
case FIXGAIN2: val = fixgain2;break;
case FORCESWITCHG1: val = forceswitchgain1;break;
case FORCESWITCHG2: val = forceswitchgain2;break;
default:
printf("Error: This settings is not defined for this detector %d\n",i);
return GET_SETTINGS;
}
}
retval=initConfGainByModule(i,val,imod);
switch(retval){
case dynamic: isett=DYNAMICGAIN; break;
case dynamichighgain0: isett=DYNAMICHG0; break;
case fixgain1: isett=FIXGAIN1; break;
case fixgain2: isett=FIXGAIN2; break;
case forceswitchgain1: isett=FORCESWITCHG1; break;
case forceswitchgain2: isett=FORCESWITCHG2; break;
default:
isett=UNDEFINED;
printf("Error:Wrong settings read out from Gain Reg 0x%x\n",retval);
break;
}
thisSettings=isett;
#ifdef VERBOSE
printf("detector settings are %d\n",thisSettings);
printf("detector settings are %d\n",thisSettings);
#endif
return thisSettings;
return thisSettings;
}
@ -1530,7 +1543,8 @@ int initModulebyNumber(sls_detector_module myMod) {
int imod;
// int obe;
// int ow;
int v[NDAC];
/* int v[NDAC];*/
int retval =-1, idac;
nchip=myMod.nchip;
@ -1559,7 +1573,7 @@ int initModulebyNumber(sls_detector_module myMod) {
v[idac]=(myMod.dacs)[idac];
*/
/*
v[VDAC0]=(myMod.dacs)[0];
v[VDAC1]=(myMod.dacs)[1];
v[VDAC2]=(myMod.dacs)[2];
@ -1580,11 +1594,19 @@ int initModulebyNumber(sls_detector_module myMod) {
printf("vdac6=%d\n",v[VDAC6]);
printf("vdac7=%d\n",v[VDAC7]);
#endif
*/
// initDACs(v,imod);
// initMCBregisters(myMod.reg,imod);
for (idac=0; idac<NDAC; idac++){
retval = setDac(idac,(myMod.dacs)[idac]);
if(retval ==(myMod.dacs)[idac])
printf("Setting dac % to %d\n",idac,retval);
else
printf("Error: Could not set dac %d, wrote %d but read %d\n",idac,(myMod.dacs)[idac],retval);
}
if (detectorModules) {
for (im=modmi; im<modma; im++) {
#ifdef VERBOSE
@ -1597,7 +1619,7 @@ int initModulebyNumber(sls_detector_module myMod) {
//setting the conf gain and the settings register
setSettings(myMod.reg,imod);
return myMod.reg;
return thisSettings;
}

View File

@ -9,9 +9,6 @@
#define RGSH1VALS {300,200,400}
#define RGSH2VALS {260,300,260}
//high,dynamic,low,medium,very high
#define CONF_GAIN {0,0, 0, 1, 6, 2, 1}//dynamic gain confgain yet to be figured out-probably 8 or 16
#define DEFAULTGAIN {11.66,9.32,14.99}
#define DEFAULTOFFSET {817.5,828.6,804.2}

View File

@ -19,7 +19,20 @@
#define FPGA_INIT_PAT 0x60008
#define FPGA_INIT_ADDR 0xb0000000
#ifdef JUNGFRAU_DHANYA
#define POWER_ON_REG 0x5e<<11
#define ADCREG1 0x08
#define ADCREG2 0x14
#define ADCREG3 0x4
#define ADCREG4 0x5
#define ADCREG_VREFS 0x18
#define ADC_INVERSION_REG 0x43<<11
#define ADC_PIPELINE_REG 0x42<<11
#define DBIT_PIPELINE_REG 0x59<<11
#define MEM_MACHINE_FIFOS_REG 0x4f<<11
#define CONFGAIN_REG 0x5d<<11 /** was actually GAIN_REG which seems to be set to 0 later in this file*/
#endif
/* constant FPGAVersionReg_c : integer:= 0; */

View File

@ -139,7 +139,7 @@ int init_detector(int b, int checkType) {
// setSettings(GET_SETTINGS,-1);
initDac(0); initDac(8); //initializes the two dacs
//Initialization
setFrames(-1);
setTrains(-1);
@ -160,6 +160,70 @@ int init_detector(int b, int checkType) {
// getDynamicRange();
setROI(-1,NULL,&retvalsize,&ret);
allocateRAM();
#ifdef JUNGFRAU_DHANYA
if(myDetectorType==JUNGFRAU){
//set dacs
int retval = -1;
int dacvalues[14][2]={
{0, 1250}, //vout_cm
{10, 1053}, //vin_com
{1, 600}, //vb_sda
{11, 1000}, //vb_colbuf
{2, 3000}, //vb_test_cur
{3, 830}, //vcascp_pixbuf
{4, 1630}, //vcascn_pixbuf
{12, 750}, //vb_pixbuf
{6, 480}, //vref_ds
{5, 1000}, //vb_ds
{7, 400}, //vref_comp
{13, 1220}, //vb_comp
{8, 1500}, //vref_prech
{9, 3000}, //vdd_prot
};
for(i=0;i<14;++i){
retval=setDac(dacvalues[i][0], dacvalues[i][1]);
if(retval!=dacvalues[i][1])
printf("Error: Setting dac %d failed, wrote %d, read %d\n",dacvalues[i][0],dacvalues[i][1],retval);
}
//power on the chips
bus_w(POWER_ON_REG,0x1);
//reset adc
writeADC(ADCREG1,0x3); writeADC(ADCREG1,0x0);
writeADC(ADCREG2,0x40);
writeADC(ADCREG3,0xf);
writeADC(ADCREG4,0x3f);
//vrefs - configurable?
writeADC(ADCREG_VREFS,0x2);
//set ADCINVERSionreg (by trial and error)
bus_w(ADC_INVERSION_REG,0x453b2a9c);
//set adc_pipeline
bus_w(ADC_PIPELINE_REG,0x20);
//set dbit_pipeline
bus_w(DBIT_PIPELINE_REG,0x100e);
usleep(1000000);//1s
//reset mem machine fifos fifos
bus_w(MEM_MACHINE_FIFOS_REG,0x4000);
bus_w(MEM_MACHINE_FIFOS_REG,0x0);
//reset run control
bus_w(MEM_MACHINE_FIFOS_REG,0x0400);
bus_w(MEM_MACHINE_FIFOS_REG,0x0);
//set default setting
setSettings(DYNAMICGAIN,-1);
}
#endif
return OK;
}
@ -955,7 +1019,7 @@ int read_register(int file_des) {
int set_dac(int file_des) {
//default:all mods
int retval, retval1;
int retval, retval1;
int ret=OK;
int arg[3];
enum dacIndex ind;
@ -989,8 +1053,8 @@ int set_dac(int file_des) {
if (imod<0)
imod=ALLMOD;
#ifdef MCB_FUNCS
@ -999,66 +1063,67 @@ int set_dac(int file_des) {
ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else{
if (ind<16) {
if (mV) {
if (val>2500)
val=-1;
printf("%d mV is ",val);
if (val>0)
val=4095*val/2500;
printf("%d DACu\n", val);
} else if (val>4095)
val=-1;
retval=setDac(ind,val);
/* if(idac==HIGH_VOLTAGE) */
/* retval=initHighVoltageByModule(val,imod); */
/* else */
/* retval=initDACbyIndexDACU(idac,val,imod); */
}
else if (ind==ADC_VPP) {
printf("Setting ADC VPP to %d\n",val);
if (val>4 || val<0)
printf("Cannot set ADC VPP to %d\n",val);
else {
writeADC(0x18,val);
adcvpp=val;
}
retval=adcvpp;;
if (ind<16) {
}
if (mV) {
if (val>2500)
val=-1;
printf("%d mV is ",val);
if (val>0)
val=4095*val/2500;
printf("%d DACu\n", val);
} else if (val>4095)
val=-1;
retval=setDac(ind,val);
/* if(idac==HIGH_VOLTAGE) */
/* retval=initHighVoltageByModule(val,imod); */
/* else */
/* retval=initDACbyIndexDACU(idac,val,imod); */
}
else if (ind==ADC_VPP) {
printf("Setting ADC VPP to %d\n",val);
if (val>4 || val<0)
printf("Cannot set ADC VPP to %d\n",val);
else {
writeADC(0x18,val);
adcvpp=val;
}
retval=adcvpp;;
}
}
}
if(ret==OK){
/* ret=FAIL; */
/* if(idac==HIGH_VOLTAGE){ */
/* if(retval==-2) */
/* strcpy(mess,"Invalid Voltage.Valid values are 0,90,110,120,150,180,200"); */
/* else if(retval==-3) */
/* strcpy(mess,"Weird value read back or it has not been set yet\n"); */
/* else */
/* ret=OK; */
/* }//since v r saving only msb */
/* else if ((retval-val)<=3 || val==-1) */
/* ret=OK; */
if (ind<16) {
if (mV) {
printf("%d DACu is ",retval);
retval1=2500*retval/16535;
printf("%d mV \n",retval1);
} else
retval1=retval;
/* ret=FAIL; */
/* if(idac==HIGH_VOLTAGE){ */
/* if(retval==-2) */
/* strcpy(mess,"Invalid Voltage.Valid values are 0,90,110,120,150,180,200"); */
/* else if(retval==-3) */
/* strcpy(mess,"Weird value read back or it has not been set yet\n"); */
/* else */
/* ret=OK; */
/* }//since v r saving only msb */
/* else if ((retval-val)<=3 || val==-1) */
/* ret=OK; */
if (ind<16) {
if (mV) {
printf("%d DACu is ",retval);
retval1=2500*retval/16535;
printf("%d mV \n",retval1);
} else
retval1=retval;
}
}
#endif
#ifdef VERBOSE
printf("DAC set to %d V\n", retval);
#endif
}
if(ret==FAIL)
printf("Setting dac %d of module %d: wrote %d but read %d\n", ind, imod, val, retval);
else{
@ -1433,8 +1498,8 @@ int set_module(int file_des) {
sls_detector_module myModule;
int *myChip=malloc(NCHIP*sizeof(int));
int *myChan=malloc(NCHIP*NCHAN*sizeof(int));
int *myDac=malloc(NDAC*sizeof(int));/**dhanya*/
int *myAdc=malloc(NADC*sizeof(int));/**dhanya*/
int *myDac=malloc(NDAC*sizeof(int));
int *myAdc=malloc(NADC*sizeof(int));
int retval, n;
int ret=OK;
int dr;// ow;
@ -1503,6 +1568,8 @@ int set_module(int file_des) {
} else {
#ifdef MCB_FUNCS
retval=initModulebyNumber(myModule);
if(retval != myModule.reg)
ret = FAIL;
#endif
}
}