gotthard:highvoltage done

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@57 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2011-11-22 15:08:48 +00:00
parent 1ecde6beeb
commit 39d9ae8b7b
6 changed files with 129 additions and 55 deletions

View File

@ -852,8 +852,7 @@ int setDACRegister(int idac, int val, int imod) {
}
float getTemperature(int tempSensor, int imod)
{
float getTemperature(int tempSensor, int imod){
float val;
char cTempSensor[2][100]={"ADCs/ASICs","VRs/FPGAs"};
imod=0;//ignoring more than 1 mod for now
@ -863,31 +862,59 @@ float getTemperature(int tempSensor, int imod)
#ifdef VERBOSE
printf("Getting Temperature of module:%d for the %s\n",imod,cTempSensor[tempSensor]);
#endif
bus_w(TEMP_SPI_IN,(T1_CLK_BIT)|(T1_CS_BIT)|(T2_CLK_BIT)|(T2_CS_BIT));//standby
bus_w(TEMP_SPI_IN,(T1_CLK_BIT)&~(T1_CS_BIT)|(T2_CLK_BIT));//high clk low cs
bus_w(TEMP_IN_REG,(T1_CLK_BIT)|(T1_CS_BIT)|(T2_CLK_BIT)|(T2_CS_BIT));//standby
bus_w(TEMP_IN_REG,(T1_CLK_BIT)&~(T1_CS_BIT)|(T2_CLK_BIT));//high clk low cs
for(k=0;k<2;k++){
for(i=0;i<times;i++) {
//repeats is number of register writes for delay
for(j=0;j<repeats;j++)
bus_w(TEMP_SPI_IN,~(T1_CLK_BIT)&~(T1_CS_BIT)&~(T2_CLK_BIT)&~(T2_CS_BIT));//low clk low cs
bus_w(TEMP_IN_REG,~(T1_CLK_BIT)&~(T1_CS_BIT)&~(T2_CLK_BIT)&~(T2_CS_BIT));//low clk low cs
for(j=0;j<repeats;j++)
bus_w(TEMP_SPI_IN,(T1_CLK_BIT)&~(T1_CS_BIT)|(T2_CLK_BIT));//high clk low cs
bus_w(TEMP_IN_REG,(T1_CLK_BIT)&~(T1_CS_BIT)|(T2_CLK_BIT));//high clk low cs
if(times==11)//only the first time
tempVal= (tempVal<<1) + (bus_r(TEMP_SPI_OUT) & (1<<tempSensor));
tempVal= (tempVal<<1) + (bus_r(TEMP_OUT_REG) & (1<<tempSensor));
}
times=8;
}
bus_w(TEMP_SPI_IN,(T1_CLK_BIT)|(T1_CS_BIT)|(T2_CLK_BIT)|(T2_CS_BIT));//standby
bus_w(TEMP_IN_REG,(T1_CLK_BIT)|(T1_CS_BIT)|(T2_CLK_BIT)|(T2_CS_BIT));//standby
val=((float)tempVal)/4.0;
#ifdef VERBOSE//read time from start needed??
#ifdef VERBOSE
printf("Temperature of module:%d for the %s is %.2fC\n",imod,cTempSensor[tempSensor],val);
#endif
return val;
}
int getHighVoltage(int val, int imod){
#ifdef VERBOSE
printf("Getting High Voltage of module:%d\n",imod);
#endif
volatile u_int32_t addr=HV_REG;
int input []={ 0, 90,110,120,150,180,200};
int value1[]={0x0,0x0,0x2,0x4,0x6,0x8,0xA};
int value2[]={0x0,0x1,0x3,0x5,0x7,0x9,0xB};
//changing anything here should also be changed in
//server_funcs.c to check if wrongly written
switch(val){
case -1: break;
case 0: bus_w(addr,0x0); break;
case 90: bus_w(addr,0x0); bus_w(addr,0x1); break;
case 110: bus_w(addr,0x2); bus_w(addr,0x3); break;
case 120: bus_w(addr,0x4); bus_w(addr,0x5); break;
case 150: bus_w(addr,0x6); bus_w(addr,0x7); break;
case 180: bus_w(addr,0x8); bus_w(addr,0x9); break;
case 200: bus_w(addr,0xA); bus_w(addr,0xB); break;
default : printf("Not a valid voltage\n"); return -1; break;
}
val=bus_r(addr);
#ifdef VERBOSE
printf("High Voltage of module:%d is %d\n",imod,val);
#endif
return val;
}
u_int32_t runBusy(void) {
return bus_r(STATUS_REG)&RUN_BUSY_BIT;

View File

@ -47,6 +47,7 @@ int setContinousReadOut(int d);
int setDACRegister(int idac, int val, int imod);
float getTemperature(int tempSensor, int imod);
int getHighVoltage(int val, int imod);
u_int64_t getMcsNumber();
u_int32_t getMcsVersion();

View File

@ -587,6 +587,7 @@ float initDACbyIndexDACU(int ind, int val, int imod) {
if (setDACRegister(ind, -1, im)!=setDACRegister(ind, -1, 0)) {
#ifdef VERBOSE
printf("mod %d returning -1\n",im);
#endif
return -1;
@ -727,7 +728,6 @@ float getDACbyIndexDACU(int ind, int imod) {
}
//changed arguments by dhanya
int initDAC(int dac_addr, int value, int imod) {
int i;
#ifdef VERBOSE
@ -741,6 +741,43 @@ int initDAC(int dac_addr, int value, int imod) {
return 0;
}
float getTemperatureByModule(int tempSensor, int imod)
{
int im;
//for the particular module
if (imod>=0 && imod<nModX) {
return getTemperature(tempSensor,imod);
}
else{
//checks if all modules have the same value(ALLMOD)
for (im=1; im<nModX; im++) {
if (getTemperature(tempSensor,im)!=getTemperature(tempSensor,0)) {
return -1;
}
}
return getTemperature(tempSensor,0);
}
}
int getHighVoltageByModule(int val, int imod)
{
int im;
//for the particular module
if (imod>=0 && imod<nModX) {
return getHighVoltage(val,imod);
}
else{
//checks if all modules have the same value(ALLMOD)
for (im=1; im<nModX; im++) {
if (getHighVoltage(val,im)!=getHighVoltage(val,0)) {
return -1;
}
}
return getHighVoltage(val,0);
}
}
void showbits(int h)
{

View File

@ -25,14 +25,14 @@
// DAC definitions
enum {VREF_DS, VCASCN_PB, VCASCP_PB, VOUT_CM, VCASC_OUT, VIN_CM, VREF_COMP, IB_TESTC};
enum {VREF_DS, VCASCN_PB, VCASCP_PB, VOUT_CM, VCASC_OUT, VIN_CM, VREF_COMP, IB_TESTC, };
/* DAC adresses */
#define DACCS {0,0,1,1,2,2,3,3,4,4,5,5,6,6}
#define DACADDR {0,1,0,1,0,1,0,1,0,1,0,1,0,1}
//Temp definitions
enum {TEMP_ADC, TEMP_FPGA};
//Temp/HIGH VOLTAGE Definitions
enum {TEMP_ADC, TEMP_FPGA, HIGH_VOLTAGE};
//dynamic range
#define MAX5523
@ -119,6 +119,11 @@ float initDACbyIndexDACU(int ind,int val, int imod);
float getDACbyIndexDACU(int ind, int imod);
int getThresholdEnergy();
int setThresholdEnergy(int ethr);
/* Temp/HV routines*/
float getTemperatureByModule(int tempSensor, int imod);
int getHighVoltageByModule(int val, int imod);
/* Initialization*/
int initChannel(int ft,int cae, int ae, int coe, int ocoe, int counts,int imod );
int initChannelbyNumber(sls_detector_channel myChan);

View File

@ -8,21 +8,24 @@
/* registers defined in FPGA */
#define GAIN_REG 0x10<<11
#define DAQ_REG 0x1b<<11
#define DUMMY_REG 0x13<<11
#define FIX_PATT_REG 0x45<<11
#define FPGA_VERSION_REG 0x47<<11
#define DUMMY_REG 0x13<<11
#define CONTROL_REG 0x5d<<11
#define STATUS_REG 0x5e<<11
#define CONFIG_REG 0x5f<<11
#define EXT_SIGNAL_REG 0x6a<<11
#define GAIN_REG 0x10<<11
#define DAQ_REG 0x1b<<11
//temperature
#define TEMP_SPI_IN 0x81<<11
#define TEMP_SPI_OUT 0x82<<11
#define TEMP_IN_REG 0x81<<11
#define TEMP_OUT_REG 0x82<<11
//HV
#define HV_REG 0x93<<11
//not used so far
#define SPEED_REG 0x006000

View File

@ -783,7 +783,7 @@ int read_register(int fnum) {
}
int set_dac(int fnum) {
//everything in here does for all mods
float retval;
int ret=OK;
int arg[2];
@ -794,7 +794,7 @@ int set_dac(int fnum) {
int idac=0;
int itemp=-1;
sprintf(mess,"Can't set DAC/POT/TEMP\n");
sprintf(mess,"Can't set DAC/TEMP/HV\n");
n = receiveDataOnly(arg,sizeof(arg));
@ -812,7 +812,7 @@ int set_dac(int fnum) {
}
#ifdef VERBOSE
printf("Setting DAC/POT/TEMP %d of module %d to %f V\n", ind, imod, val);
printf("Setting DAC/TEMP/HV %d of module %d to %f V\n", ind, imod, val);
#endif
if (imod>=getNModBoard())
@ -852,34 +852,39 @@ int set_dac(int fnum) {
case TEMPERATURE_FPGA:
itemp=TEMP_FPGA;
break;
case HV_POT:
itemp=HIGH_VOLTAGE;
break;
default:
printf("Unknown DAC/POT/TEMP index %d\n",ind);
sprintf(mess,"Unknown DAC/POT/TEMP index %d\n",ind);
printf("Unknown DAC/TEMP/HV index %d\n",ind);
sprintf(mess,"Unknown DAC/TEMP/HV index %d\n",ind);
ret=FAIL;
}
if (ret==OK) {
if(itemp!=-1) {
if (imod>=0 && imod<nModX)
retval=getTemperature(itemp,imod);
else
//get only the first mods temp, but dunno when this is used
retval=getTemperature(itemp,0);
}
else
//dac
if(itemp==-1)
retval=initDACbyIndexDACU(idac,val,imod);
else
{ //HV
if(itemp==HIGH_VOLTAGE)
retval=getHighVoltageByModule(val,imod);
else//Temp
retval=getTemperatureByModule(itemp,imod);
}
}
#endif
#ifdef VERBOSE
printf("DAC/POT/TEMP set to %f V\n", retval);
printf("DAC/TEMP/HV set to %f V\n", retval);
#endif
if (retval==val || val==-1)
ret=OK;
else {
ret=FAIL;
printf("Setting dac/pot %d of module %d: wrote %f but read %f\n", ind, imod, val, retval);
}
if((itemp==HIGH_VOLTAGE)&&(retval!=-1))
ret =OK;
else if (retval==val || val==-1)
ret=OK;
if(ret==FAIL)
printf("Setting dac/hv %d of module %d: wrote %f but read %f\n", ind, imod, val, retval);
/* send answer */
@ -891,12 +896,8 @@ int set_dac(int fnum) {
} else {
n += sendDataOnly(mess,sizeof(mess));
}
/* Maybe this is done inside the initialization funcs */
//detectorDacs[imod][ind]=val;
/*return ok/fail*/
return ret;
}