diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index fa13d9d7a..1fa4fe417 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -1641,7 +1641,9 @@ int get_adc(int file_des) { // valid index if (ret == OK) { LOG(logDEBUG1, ("Getting ADC %d\n", serverAdcIndex)); -#if defined(MYTHEN3D) || defined(GOTTHARD2D) || defined(XILINX_CHIPTESTBOARDD) +#if defined(XILINX_CHIPTESTBOARDD) + ret = getADC(serverAdcIndex, &retval, mess); +#elif defined(MYTHEN3D) || defined(GOTTHARD2D) ret = getADC(serverAdcIndex, &retval); if (ret == FAIL) { if (ind == TEMPERATURE_FPGA) { diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/bin/xilinx_ctbDetectorServer_developer b/slsDetectorServers/xilinx_ctbDetectorServer/bin/xilinx_ctbDetectorServer_developer index 3fb9ec0b3..658096edd 100755 Binary files a/slsDetectorServers/xilinx_ctbDetectorServer/bin/xilinx_ctbDetectorServer_developer and b/slsDetectorServers/xilinx_ctbDetectorServer/bin/xilinx_ctbDetectorServer_developer differ diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c index 9b30ab682..3d8b1d493 100644 --- a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c @@ -1482,11 +1482,8 @@ int setPower(enum DACINDEX ind, int val, char *mess) { return OK; } -int getADC(enum ADCINDEX ind, int *value) { +int getADC(enum ADCINDEX ind, int *value, char *mess) { *value = 0; -#ifdef VIRTUAL - return OK; -#endif switch (ind) { // slow adcs case S_ADC0: @@ -1498,44 +1495,60 @@ int getADC(enum ADCINDEX ind, int *value) { case S_ADC6: case S_ADC7: LOG(logDEBUG1, ("Reading Slow ADC Channel %d\n", (int)ind - S_ADC0)); - return getSlowADC((int)ind - S_ADC0, value); + return getSlowADC((int)ind - S_ADC0, value, mess); case TEMP_FPGA: LOG(logDEBUG1, ("Reading FPGA Temperature\n")); - return getTemperature(value); + return getTemperature(value, mess); default: - LOG(logERROR, ("Adc Index %d not defined \n", (int)ind)); + snprintf(mess, MAX_STR_LENGTH, "Adc Index %d not defined\n", (int)ind); + LOG(logERROR, (mess)); return FAIL; } } -int getSlowADC(int ichan, int *retval) { +int getSlowADC(int ichan, int *retval, char *mess) { *retval = 0; -#ifndef VIRTUAL + int fval = 0; + +#ifdef VIRTUAL + fval = 1; +#else char fname[MAX_STR_LENGTH]; memset(fname, 0, MAX_STR_LENGTH); sprintf(fname, SLOWADC_DRIVER_FILE_NAME, ichan); LOG(logDEBUG1, ("fname %s\n", fname)); - - if (readParameterFromFile(fname, "slow adc", retval) == FAIL) { - LOG(logERROR, ("Could not get slow adc\n")); + if (readParameterFromFile(fname, "slow adc", &fval) == FAIL) { + snprintf(mess, MAX_STR_LENGTH, "Could not read slow adc channel %d\n", + ichan); + LOG(logERROR, (mess)); return FAIL; } - // TODO assuming already converted to uV - // convert to uV - // double value = SLOWDAC_CONVERTION_FACTOR_TO_UV * (double)(*retval); - // LOG(logINFO, ("Slow ADC [%d]: %f uV\n", ichan, value)); - //*retval = (int)value; - - LOG(logINFO, ("Slow ADC [%d]: %d uV\n", ichan, (*retval))); #endif + + // value in uV + int refMaxuv = SLOW_ADC_MAX_MV * 1000; + int regMinuv = 0; + int maxSteps = SLOW_ADC_MAX_STEPS; + if (ConvertToDifferentRange(0, maxSteps, regMinuv, refMaxuv, fval, + retval) == FAIL) { + snprintf(mess, MAX_STR_LENGTH, + "Could not convert slow adc channel (fval:0x%x) to uv\n", + fval); + LOG(logERROR, (mess)); + return -1; + } + + LOG(logINFO, + ("\tSlow adc [%d]: %d uV (reg: 0x%x)\n", ichan, *retval, fval)); return OK; } -int getTemperature(int *retval) { +int getTemperature(int *retval, char *mess) { *retval = 0; #ifndef VIRTUAL if (readParameterFromFile(TEMP_DRIVER_FILE_NAME, "temperature", retval) == FAIL) { + snprintf(mess, MAX_STR_LENGTH, "Could not read temperature\n"); LOG(logERROR, ("Could not get temperature\n")); return FAIL; } diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.h index 64766d63e..8ccea05b8 100644 --- a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.h @@ -143,9 +143,9 @@ int getPowerRail(enum PWRINDEX ind, int *retval, char *mess); int getPower(enum DACINDEX ind, int *retval, char *mess); int setPower(enum DACINDEX ind, int val, char *mess); -int getADC(enum ADCINDEX ind, int *value); -int getSlowADC(int ichan, int *retval); -int getTemperature(int *retval); +int getADC(enum ADCINDEX ind, int *value, char *mess); +int getSlowADC(int ichan, int *retval, char *mess); +int getTemperature(int *retval, char *mess); int setHighVoltage(int val); // parameters - timing, extsig diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorServer_defs.h index ef1cef945..591bf7545 100644 --- a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorServer_defs.h @@ -65,11 +65,13 @@ #define MAX_ANALOG_SAMPLES (0x3FFF) #define MAX_DIGITAL_SAMPLES (0x3FFF) -#define DAC_MIN_MV (0) -#define DAC_MAX_MV (2048) -#define POWER_RGLTR_MIN (1041) -#define POWER_RGLTR_MAX (2661) -#define VIO_MIN_MV (1200) // for fpga to function +#define DAC_MIN_MV (0) +#define DAC_MAX_MV (2048) +#define POWER_RGLTR_MIN (1041) +#define POWER_RGLTR_MAX (2661) +#define VIO_MIN_MV (1200) // for fpga to function +#define SLOW_ADC_MAX_MV (2500) // AD7689 +#define SLOW_ADC_MAX_STEPS (0xFFFF + 1) // AD7689 /* Defines in the Firmware */ #define WAIT_TIME_PATTERN_READ (10)