diff --git a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer deleted file mode 100755 index 07c0556cd..000000000 Binary files a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer and /dev/null differ diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index 1d849c9a7..685b0d8de 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -1150,8 +1150,12 @@ int getNumTransceiverSamples() { return ntSamples; } int setExpTime(int64_t val) { setPatternWaitInterval(0, val); + + // 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; @@ -1171,7 +1175,9 @@ int setPeriod(int64_t val) { // validate for tolerance int64_t retval = getPeriod(); val /= (NS_TO_CLK_CYCLE * clkFrequency[SYNC_CLK]); - if (val != retval) { + int64_t toleranceNs = 3 * (1000000000 / clkFrequency[SYNC_CLK]); + int64_t diff = val - retval; + if (diff < -toleranceNs || diff > toleranceNs) { return FAIL; } return OK; @@ -1195,12 +1201,15 @@ int setDelayAfterTrigger(int64_t val) { // validate for tolerance int64_t retval = getDelayAfterTrigger(); val /= (NS_TO_CLK_CYCLE * clkFrequency[SYNC_CLK]); - if (val != retval) { + int64_t toleranceNs = 3 * (1000000000 / clkFrequency[SYNC_CLK]); + int64_t diff = val - retval; + if (diff < -toleranceNs || diff > toleranceNs) { return FAIL; } return OK; } + int64_t getDelayAfterTrigger() { return get64BitReg(DELAY_LSB_REG, DELAY_MSB_REG) / (NS_TO_CLK_CYCLE * clkFrequency[SYNC_CLK]); diff --git a/slsDetectorServers/slsDetectorServer/src/loadPattern.c b/slsDetectorServers/slsDetectorServer/src/loadPattern.c index b119ac674..fcb47a109 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 (double)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, @@ -381,7 +383,7 @@ void setPatternWaitInterval(int level, uint64_t t) { #elif MYTHEN3D runclk = clkDivider[SYSTEM_C0]; #endif - uint64_t numClocks = t * (NS_TO_CLK_CYCLE * runclk); + uint64_t numClocks = (uint64_t)(t * (NS_TO_CLK_CYCLE * runclk) + 0.5); setPatternWaitClocks(level, numClocks); } diff --git a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c index 513055e0d..2eb473125 100644 --- a/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/xilinx_ctbDetectorServer/slsDetectorFunctionList.c @@ -768,8 +768,12 @@ int getNumTransceiverSamples() { int setExpTime(int64_t val) { setPatternWaitInterval(0, val); + + // 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; @@ -789,7 +793,9 @@ int setPeriod(int64_t val) { // validate for tolerance int64_t retval = getPeriod(); val /= (NS_TO_CLK_CYCLE * clkFrequency[RUN_CLK]); - 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; @@ -812,7 +818,9 @@ int setDelayAfterTrigger(int64_t val) { // validate for tolerance int64_t retval = getDelayAfterTrigger(); val /= (NS_TO_CLK_CYCLE * clkFrequency[RUN_CLK]); - 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;