From 775453cfef909462ff922c11ffc1860d76eba572 Mon Sep 17 00:00:00 2001 From: Juliano Murari <juliano.murari@ess.eu> Date: Wed, 27 Jul 2022 15:57:16 +0200 Subject: [PATCH] Add condition to calculate flat top current --- sis8300bcmApp/src/sis8300bcm.cpp | 41 +++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/sis8300bcmApp/src/sis8300bcm.cpp b/sis8300bcmApp/src/sis8300bcm.cpp index a9b1434..7da1cf5 100644 --- a/sis8300bcmApp/src/sis8300bcm.cpp +++ b/sis8300bcmApp/src/sis8300bcm.cpp @@ -1168,6 +1168,8 @@ int sis8300bcm::deviceDone() double doubleValue; unsigned int uintValue; double flattopStart, flattopEnd, flattopCharge; + int autoFlattopEnable; + double autoFlattopStart, autoFlattopEnd, triggerWidth; // readout system wide parameters asynPrintDeviceInfo(pasynUserSelf, "readout system wide parameters"); @@ -1265,16 +1267,37 @@ int sis8300bcm::deviceDone() return ret; } setDoubleParam(addr, BCMAcctFlatTopCharge, flattopCharge); - // flat top start and end have been read-back before the start of acquisition - getDoubleParam(addr, BCMAcctFlatTopStart, &flattopStart); - getDoubleParam(addr, BCMAcctFlatTopEnd, &flattopEnd); - // calculate the average current over flattop - ret = sis8300drvbcm_get_channel_flattop_current(mDeviceHandle, addr, flattopEnd - flattopStart, flattopCharge, &doubleValue); - if (ret) { - asynPrintError(pasynUserSelf, "sis8300drvbcm_get_channel_flattop_current returned %d", ret); - return ret; + + // flat top current, check if automatic mode is enabled + getIntegerParam(addr, BCMAcctAutoFlatTopEnable, &autoFlattopEnable); + asynPrintDeviceInfo(pasynUserSelf, "Channel %d auto flattop enable is %d", addr, autoFlattopEnable); + if(autoFlattopEnable){ + // auto flat top start and end have been read-back before the start of acquisition + getDoubleParam(addr, BCMAcctAutoFlatTopStart, &autoFlattopStart); + getDoubleParam(addr, BCMAcctAutoFlatTopEnd, &autoFlattopEnd); + getDoubleParam(addr, BCMAcctTriggerWidth, &triggerWidth); + printf("Channel %d auto flattop start %f\n", addr, autoFlattopStart); + printf("Channel %d auto flattop end %f\n", addr, autoFlattopEnd); + printf("Channel %d auto trigger width %f\n", addr, triggerWidth); + // calculate the average current over automatic flattop + ret = sis8300drvbcm_get_channel_flattop_current(mDeviceHandle, addr, triggerWidth - autoFlattopStart + autoFlattopEnd, flattopCharge, &doubleValue); + if (ret) { + asynPrintError(pasynUserSelf, "sis8300drvbcm_get_channel_flattop_current auto returned %d", ret); + return ret; + } + asynPrintDeviceInfo(pasynUserSelf, "Channel %d auto flattop current %f mA", addr, doubleValue); + }else{ + // flat top start and end have been read-back before the start of acquisition + getDoubleParam(addr, BCMAcctFlatTopStart, &flattopStart); + getDoubleParam(addr, BCMAcctFlatTopEnd, &flattopEnd); + // calculate the average current over flattop + ret = sis8300drvbcm_get_channel_flattop_current(mDeviceHandle, addr, flattopEnd - flattopStart, flattopCharge, &doubleValue); + if (ret) { + asynPrintError(pasynUserSelf, "sis8300drvbcm_get_channel_flattop_current returned %d", ret); + return ret; + } + asynPrintDeviceInfo(pasynUserSelf, "Channel %d flattop current %f mA", addr, doubleValue); } - asynPrintDeviceInfo(pasynUserSelf, "flattop current %f mA", doubleValue); setDoubleParam(addr, BCMAcctFlatTopCurrent, doubleValue); ret = sis8300drvbcm_get_channel_alarm_hold(mDeviceHandle, addr, &uintValue); -- GitLab