diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index 97357cf12..cfd71ef7e 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -1145,9 +1145,11 @@ int getNumTransceiverSamples() { return ntSamples; } int setExpTime(int64_t val) { setPatternWaitInterval(0, val); - // validate for tolerance + // Tolerance: three clock periods in ns. int64_t retval = getExpTime(); - if (val != retval) { + int64_t toleranceNs = 3 * (1000000000 / clkFrequency[RUN_CLK]); + int64_t diff = val - retval; + if (diff < -toleranceNs || diff > toleranceNs) { return FAIL; } return OK; diff --git a/slsDetectorServers/slsDetectorServer/src/loadPattern.c b/slsDetectorServers/slsDetectorServer/src/loadPattern.c index 929460897..021295476 100644 --- a/slsDetectorServers/slsDetectorServer/src/loadPattern.c +++ b/slsDetectorServers/slsDetectorServer/src/loadPattern.c @@ -307,7 +307,9 @@ uint64_t getPatternWaitInterval(int level) { LOG(logERROR, ("runclk is 0. Cannot divide by 0. Returning -1.\n")); return -1; } - return numClocks / (NS_TO_CLK_CYCLE * runclk); + double conv = NS_TO_CLK_CYCLE * runclk; + uint64_t waitNs = (uint64_t)(numClocks / conv + 0.5); + return waitNs; } int validate_setPatternWaitClocksAndInterval(char *message, int level, diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 19bee554a..49ab27d3e 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -5867,7 +5867,7 @@ int set_clock_frequency(int file_des) { if (getFrequency(c) == val) { LOG(logINFO, ("Same %s: %d %s\n", modeName, val, "Hz")); } else { - int ret = setFrequency(c, val); // MM: Poblem + int ret = setFrequency(c, val); if (ret == FAIL) { sprintf(mess, "Could not set %s to %d %s\n", modeName, val,"Hz"); LOG(logERROR, (mess)); diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c index 1c1a55a8a..962b9d3fa 100644 --- a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c @@ -1055,9 +1055,11 @@ int getNumTransceiverSamples() { int setExpTime(int64_t val) { setPatternWaitInterval(0, val); - // validate for tolerance + // Tolerance: three clock periods in ns. int64_t retval = getExpTime(); - if (val != retval) { + int64_t toleranceNs = 3 * (1000000000 / clkFrequency[RUN_CLK]); + int64_t diff = val - retval; + if (diff < -toleranceNs || diff > toleranceNs) { return FAIL; } return OK;