mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-23 15:00:02 +02:00
m3: vthreshold set/get only enabled counters but remember value, vth always overwrite, disable counter sets vth to 2800, enable counter sets saved values
This commit is contained in:
parent
54c24b3de7
commit
daae52ca63
@ -933,12 +933,17 @@ void setCounterMask(uint32_t arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG(logINFO, ("\tUpdating Vth dacs\n"));
|
LOG(logINFO, ("\tUpdating Vth dacs\n"));
|
||||||
|
enum DACINDEX vthdacs[] = {M_VTH1, M_VTH2, M_VTH3};
|
||||||
for (int i = 0; i < NCOUNTERS; ++i) {
|
for (int i = 0; i < NCOUNTERS; ++i) {
|
||||||
// if change in enable
|
// if change in enable
|
||||||
if ((arg & (1 << i)) ^ (oldmask & (1 << i))) {
|
if ((arg & (1 << i)) ^ (oldmask & (1 << i))) {
|
||||||
// will disable if counter disabled, else set corresponding vth dac
|
// disable, disable value
|
||||||
enum DACINDEX ind[] = {M_VTH1, M_VTH2, M_VTH3};
|
int value = DEFAULT_COUNTER_DISABLED_VTH_VAL;
|
||||||
setDAC(ind[i], vthEnabledVals[i], 0);
|
// enable, set saved values
|
||||||
|
if (arg & (1 << i)) {
|
||||||
|
value = vthEnabledVals[i];
|
||||||
|
}
|
||||||
|
setGeneralDAC(vthdacs[i], value, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1262,51 +1267,52 @@ void setThresholdEnergy(int counterIndex, int eV) {
|
|||||||
|
|
||||||
/* parameters - dac, hv */
|
/* parameters - dac, hv */
|
||||||
void setDAC(enum DACINDEX ind, int val, int mV) {
|
void setDAC(enum DACINDEX ind, int val, int mV) {
|
||||||
|
// invalid value
|
||||||
if (val < 0) {
|
if (val < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// out of scope, NDAC + 1 for vthreshold
|
// out of scope, NDAC + 1 for vthreshold
|
||||||
if ((int)ind > NDAC + 1) {
|
if ((int)ind > NDAC + 1) {
|
||||||
LOG(logERROR, ("Unknown dac index %d\n", ind));
|
LOG(logERROR, ("Unknown dac index %d\n", ind));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ind == M_VTHRESHOLD) {
|
// threshold dacs (remember value, vthreshold: skip disabled)
|
||||||
LOG(logINFO,
|
if (ind == M_VTHRESHOLD || ind == M_VTH1 || ind == M_VTH2 ||
|
||||||
("Setting Threshold voltages to %d %s\n", val, (mV ? "mv" : "")));
|
ind == M_VTH3) {
|
||||||
setDAC(M_VTH1, val, mV);
|
char *dac_names[] = {DAC_NAMES};
|
||||||
setDAC(M_VTH2, val, mV);
|
int vthdacs[] = {M_VTH1, M_VTH2, M_VTH3};
|
||||||
setDAC(M_VTH3, val, mV);
|
uint32_t counters = getCounterMask();
|
||||||
return;
|
for (int i = 0; i < NCOUNTERS; ++i) {
|
||||||
}
|
if ((int)ind == vthdacs[i] || ind == M_VTHRESHOLD) {
|
||||||
char *dac_names[] = {DAC_NAMES};
|
int dacval = val;
|
||||||
|
// if not disabled value, remember value
|
||||||
// remember vthx values and set 2800 if counter disabled
|
if (dacval != DEFAULT_COUNTER_DISABLED_VTH_VAL) {
|
||||||
uint32_t counters = getCounterMask();
|
// convert mv to dac
|
||||||
int vthdacs[] = {M_VTH1, M_VTH2, M_VTH3};
|
if (mV) {
|
||||||
for (int i = 0; i < NCOUNTERS; ++i) {
|
if (LTC2620_D_VoltageToDac(val, &dacval) == FAIL) {
|
||||||
if (vthdacs[i] == (int)ind) {
|
return;
|
||||||
// remember enabled values for vthx
|
}
|
||||||
if (val != DEFAULT_COUNTER_DISABLED_VTH_VAL) {
|
|
||||||
int vthval = val;
|
|
||||||
if (mV) {
|
|
||||||
if (LTC2620_D_VoltageToDac(val, &vthval) == FAIL) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
vthEnabledVals[i] = dacval;
|
||||||
|
LOG(logINFO,
|
||||||
|
("Remembering %s [%d]\n", dac_names[ind], dacval));
|
||||||
}
|
}
|
||||||
vthEnabledVals[i] = vthval;
|
// if vthreshold,skip for disabled counters
|
||||||
LOG(logINFO, ("Remembering %s [%d]\n", dac_names[ind], vthval));
|
if ((ind == M_VTHRESHOLD) && (!(counters & (1 << i)))) {
|
||||||
}
|
continue;
|
||||||
// set vthx to disable val, if counter disabled
|
}
|
||||||
if (!(counters & (1 << i))) {
|
setGeneralDAC(vthdacs[i], val, mV);
|
||||||
LOG(logINFO, ("Disabling %s\n", dac_names[ind]));
|
|
||||||
val = DEFAULT_COUNTER_DISABLED_VTH_VAL;
|
|
||||||
mV = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setGeneralDAC(ind, val, mV);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setGeneralDAC(enum DACINDEX ind, int val, int mV) {
|
||||||
|
char *dac_names[] = {DAC_NAMES};
|
||||||
LOG(logDEBUG1, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind],
|
LOG(logDEBUG1, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind],
|
||||||
val, (mV ? "mV" : "dac units")));
|
val, (mV ? "mV" : "dac units")));
|
||||||
int dacval = val;
|
int dacval = val;
|
||||||
@ -1334,20 +1340,29 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
|
|||||||
|
|
||||||
int getDAC(enum DACINDEX ind, int mV) {
|
int getDAC(enum DACINDEX ind, int mV) {
|
||||||
if (ind == M_VTHRESHOLD) {
|
if (ind == M_VTHRESHOLD) {
|
||||||
int ret[NCOUNTERS] = {0};
|
int ret = -1, ret1 = -1;
|
||||||
ret[0] = getDAC(M_VTH1, mV);
|
// get only for enabled counters
|
||||||
ret[1] = getDAC(M_VTH2, mV);
|
uint32_t counters = getCounterMask();
|
||||||
ret[2] = getDAC(M_VTH3, mV);
|
int vthdacs[] = {M_VTH1, M_VTH2, M_VTH3};
|
||||||
|
for (int i = 0; i < NCOUNTERS; ++i) {
|
||||||
if ((ret[0] == ret[1]) && (ret[1] == ret[2])) {
|
if (counters & (1 << i)) {
|
||||||
LOG(logINFO, ("\tvthreshold match\n"));
|
ret1 = getDAC(vthdacs[i], mV);
|
||||||
return ret[0];
|
// first enabled counter
|
||||||
} else {
|
if (ret == -1) {
|
||||||
LOG(logERROR, ("\tvthreshold mismatch vth1:%d vth2:%d "
|
ret = ret1;
|
||||||
"vth3:%d\n",
|
}
|
||||||
ret[0], ret[1], ret[2]));
|
// different values for enabled counters
|
||||||
return -1;
|
else if (ret1 != ret) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (ret == -1) {
|
||||||
|
LOG(logERROR, ("\tvthreshold mismatch (of enabled counters)\n"));
|
||||||
|
} else {
|
||||||
|
LOG(logINFO, ("\tvthreshold match %d\n", ret));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mV) {
|
if (!mV) {
|
||||||
|
@ -317,6 +317,9 @@ int setOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex, int val);
|
|||||||
int getOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex);
|
int getOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex);
|
||||||
#endif
|
#endif
|
||||||
void setDAC(enum DACINDEX ind, int val, int mV);
|
void setDAC(enum DACINDEX ind, int val, int mV);
|
||||||
|
#ifdef MYTHEN3D
|
||||||
|
void setGeneralDAC(enum DACINDEX ind, int val, int mV);
|
||||||
|
#endif
|
||||||
int getDAC(enum DACINDEX ind, int mV);
|
int getDAC(enum DACINDEX ind, int mV);
|
||||||
int getMaxDacSteps();
|
int getMaxDacSteps();
|
||||||
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
|
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
|
||||||
|
@ -1238,34 +1238,6 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) {
|
|||||||
ret = OK;
|
ret = OK;
|
||||||
} else {
|
} else {
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
#ifdef MYTHEN3D
|
|
||||||
// give a different exception message if counter not enabled
|
|
||||||
int isCounterError = 0;
|
|
||||||
if (serverDacIndex == M_VTHRESHOLD ||
|
|
||||||
serverDacIndex == M_VTH1 || serverDacIndex == M_VTH2 ||
|
|
||||||
serverDacIndex == M_VTH3) {
|
|
||||||
uint32_t counter_retval = getCounterMask();
|
|
||||||
// vthreshold, all counters should have been enabled
|
|
||||||
if (serverDacIndex == M_VTHRESHOLD) {
|
|
||||||
if (counter_retval != MAX_COUNTER_MSK) {
|
|
||||||
isCounterError = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// corresponding counter should have been enabled
|
|
||||||
else {
|
|
||||||
int vthdacs[] = {M_VTH1, M_VTH2, M_VTH3};
|
|
||||||
for (int i = 0; i < NCOUNTERS; ++i) {
|
|
||||||
if ((vthdacs[i] == (int)serverDacIndex) &&
|
|
||||||
(!(counter_retval & (1 << i)))) {
|
|
||||||
isCounterError = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isCounterError) {
|
|
||||||
strcpy(mess, "Could not set dac as counter disabled\n");
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
sprintf(mess, "Setting dac %d : wrote %d but read %d\n",
|
sprintf(mess, "Setting dac %d : wrote %d but read %d\n",
|
||||||
serverDacIndex, val, retval);
|
serverDacIndex, val, retval);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
|
@ -25,7 +25,7 @@ TEST_CASE("Setting and reading back MYTHEN3 dacs", "[.cmd][.dacs]") {
|
|||||||
CmdProxy proxy(&det);
|
CmdProxy proxy(&det);
|
||||||
auto det_type = det.getDetectorType().squash();
|
auto det_type = det.getDetectorType().squash();
|
||||||
if (det_type == defs::MYTHEN3) {
|
if (det_type == defs::MYTHEN3) {
|
||||||
SECTION("vcassh") { test_dac(defs::VCASSH, "vcassh", 1200); }
|
/*SECTION("vcassh") { test_dac(defs::VCASSH, "vcassh", 1200); }
|
||||||
SECTION("vth2") { test_dac(defs::VTH2, "vth2", 2800); }
|
SECTION("vth2") { test_dac(defs::VTH2, "vth2", 2800); }
|
||||||
SECTION("vrshaper") { test_dac(defs::VRSHAPER, "vrshaper", 1280); }
|
SECTION("vrshaper") { test_dac(defs::VRSHAPER, "vrshaper", 1280); }
|
||||||
SECTION("vrshaper_n") {
|
SECTION("vrshaper_n") {
|
||||||
@ -42,7 +42,7 @@ TEST_CASE("Setting and reading back MYTHEN3 dacs", "[.cmd][.dacs]") {
|
|||||||
SECTION("vishaper") { test_dac(defs::VISHAPER, "vishaper", 1708); }
|
SECTION("vishaper") { test_dac(defs::VISHAPER, "vishaper", 1708); }
|
||||||
SECTION("vcal_p") { test_dac(defs::VCAL_P, "vcal_p", 1712); }
|
SECTION("vcal_p") { test_dac(defs::VCAL_P, "vcal_p", 1712); }
|
||||||
SECTION("vtrim") { test_dac(defs::VTRIM, "vtrim", 2800); }
|
SECTION("vtrim") { test_dac(defs::VTRIM, "vtrim", 2800); }
|
||||||
SECTION("vdcsh") { test_dac(defs::VDCSH, "vdcsh", 800); }
|
SECTION("vdcsh") { test_dac(defs::VDCSH, "vdcsh", 800); }*/
|
||||||
SECTION("vthreshold") {
|
SECTION("vthreshold") {
|
||||||
// Read out individual vcmp to be able to reset after
|
// Read out individual vcmp to be able to reset after
|
||||||
// the test is done
|
// the test is done
|
||||||
@ -62,39 +62,49 @@ TEST_CASE("Setting and reading back MYTHEN3 dacs", "[.cmd][.dacs]") {
|
|||||||
REQUIRE(oss.str() == "dac vthreshold 1234\n");
|
REQUIRE(oss.str() == "dac vthreshold 1234\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// change vthreshold when counters disabled
|
// disabling counters change vth values
|
||||||
proxy.Call("counters", {"0"}, -1, PUT);
|
proxy.Call("counters", {"0"}, -1, PUT);
|
||||||
REQUIRE_NOTHROW(proxy.Call("dac", {"vth1", "2100"}, -1, PUT));
|
|
||||||
REQUIRE_THROWS(proxy.Call("dac", {"vth2", "2100"}, -1, PUT));
|
|
||||||
REQUIRE_THROWS(proxy.Call("dac", {"vth3", "2100"}, -1, PUT));
|
|
||||||
REQUIRE_THROWS(proxy.Call("dac", {"vthreshold", "2100"}, -1, PUT));
|
|
||||||
proxy.Call("counters", {"0", "2"}, -1, PUT);
|
|
||||||
REQUIRE_NOTHROW(proxy.Call("dac", {"vth1", "2100"}, -1, PUT));
|
|
||||||
REQUIRE_THROWS(proxy.Call("dac", {"vth2", "2100"}, -1, PUT));
|
|
||||||
REQUIRE_NOTHROW(proxy.Call("dac", {"vth3", "2100"}, -1, PUT));
|
|
||||||
REQUIRE_THROWS(proxy.Call("dac", {"vthreshold", "2200"}, -1, PUT));
|
|
||||||
proxy.Call("counters", {"0", "1", "2"}, -1, PUT);
|
|
||||||
// should remember the previous values when counter set
|
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss1, oss2, oss3;
|
||||||
proxy.Call("dac", {"vth1"}, -1, GET, oss);
|
proxy.Call("dac", {"vth1"}, -1, GET, oss1);
|
||||||
REQUIRE(oss.str() == "dac vth1 2200\n");
|
REQUIRE(oss1.str() == "dac vth1 1234\n");
|
||||||
|
proxy.Call("dac", {"vth2"}, -1, GET, oss2);
|
||||||
|
REQUIRE(oss2.str() == "dac vth2 2800\n");
|
||||||
|
proxy.Call("dac", {"vth3"}, -1, GET, oss3);
|
||||||
|
REQUIRE(oss3.str() == "dac vth3 2800\n");
|
||||||
}
|
}
|
||||||
|
// vthreshold changes vth for only enabled counters
|
||||||
|
REQUIRE_NOTHROW(proxy.Call("dac", {"vthreshold", "2100"}, -1, PUT));
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
|
proxy.Call("dac", {"vthreshold"}, -1, GET, oss);
|
||||||
|
REQUIRE(oss.str() == "dac vthreshold 2100\n");
|
||||||
|
std::ostringstream oss1, oss2, oss3;
|
||||||
|
proxy.Call("dac", {"vth1"}, -1, GET, oss1);
|
||||||
|
REQUIRE(oss1.str() == "dac vth1 2100\n");
|
||||||
|
proxy.Call("dac", {"vth2"}, -1, GET, oss2);
|
||||||
|
REQUIRE(oss2.str() == "dac vth2 2800\n");
|
||||||
|
proxy.Call("dac", {"vth3"}, -1, GET, oss3);
|
||||||
|
REQUIRE(oss3.str() == "dac vth3 2800\n");
|
||||||
|
}
|
||||||
|
// vth overwrite vth even if counter disabled
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
proxy.Call("dac", {"vth2", "2200"}, -1, PUT);
|
||||||
proxy.Call("dac", {"vth2"}, -1, GET, oss);
|
proxy.Call("dac", {"vth2"}, -1, GET, oss);
|
||||||
REQUIRE(oss.str() == "dac vth2 2200\n");
|
REQUIRE(oss.str() == "dac vth2 2200\n");
|
||||||
}
|
}
|
||||||
|
// counters enabled, sets remembered values
|
||||||
|
proxy.Call("counters", {"0", "1", "2"}, -1, PUT);
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss1, oss2, oss3;
|
||||||
proxy.Call("dac", {"vth3"}, -1, GET, oss);
|
proxy.Call("dac", {"vth1"}, -1, GET, oss1);
|
||||||
REQUIRE(oss.str() == "dac vth3 2200\n");
|
REQUIRE(oss1.str() == "dac vth1 2100\n");
|
||||||
|
proxy.Call("dac", {"vth2"}, -1, GET, oss2);
|
||||||
|
REQUIRE(oss2.str() == "dac vth2 2200\n");
|
||||||
|
proxy.Call("dac", {"vth3"}, -1, GET, oss3);
|
||||||
|
REQUIRE(oss3.str() == "dac vth3 2100\n");
|
||||||
}
|
}
|
||||||
REQUIRE_NOTHROW(proxy.Call("dac", {"vth1", "2100"}, -1, PUT));
|
|
||||||
REQUIRE_NOTHROW(proxy.Call("dac", {"vth2", "2100"}, -1, PUT));
|
|
||||||
REQUIRE_NOTHROW(proxy.Call("dac", {"vth3", "2100"}, -1, PUT));
|
|
||||||
REQUIRE_NOTHROW(proxy.Call("dac", {"vthreshold", "2100"}, -1, PUT));
|
|
||||||
|
|
||||||
// Reset dacs after test
|
// Reset dacs after test
|
||||||
for (int i = 0; i != det.size(); ++i) {
|
for (int i = 0; i != det.size(); ++i) {
|
||||||
det.setCounterMask(mask[i], {i});
|
det.setCounterMask(mask[i], {i});
|
||||||
@ -103,7 +113,7 @@ TEST_CASE("Setting and reading back MYTHEN3 dacs", "[.cmd][.dacs]") {
|
|||||||
det.setDAC(defs::VTH3, vth3[i], false, {i});
|
det.setDAC(defs::VTH3, vth3[i], false, {i});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
REQUIRE_THROWS(proxy.Call("dac", {"vsvp"}, -1, GET));
|
/*REQUIRE_THROWS(proxy.Call("dac", {"vsvp"}, -1, GET));
|
||||||
REQUIRE_THROWS(proxy.Call("dac", {"vsvn"}, -1, GET));
|
REQUIRE_THROWS(proxy.Call("dac", {"vsvn"}, -1, GET));
|
||||||
// REQUIRE_THROWS(proxy.Call("dac", {"vtrim"}, -1, GET));
|
// REQUIRE_THROWS(proxy.Call("dac", {"vtrim"}, -1, GET));
|
||||||
// REQUIRE_THROWS(proxy.Call("dac", {"vrpreamp"}, -1, GET));
|
// REQUIRE_THROWS(proxy.Call("dac", {"vrpreamp"}, -1, GET));
|
||||||
@ -146,7 +156,7 @@ TEST_CASE("Setting and reading back MYTHEN3 dacs", "[.cmd][.dacs]") {
|
|||||||
REQUIRE_THROWS(proxy.Call("dac", {"vb_comp"}, -1, GET));
|
REQUIRE_THROWS(proxy.Call("dac", {"vb_comp"}, -1, GET));
|
||||||
REQUIRE_THROWS(proxy.Call("dac", {"vb_pixbuf"}, -1, GET));
|
REQUIRE_THROWS(proxy.Call("dac", {"vb_pixbuf"}, -1, GET));
|
||||||
REQUIRE_THROWS(proxy.Call("dac", {"vin_com"}, -1, GET));
|
REQUIRE_THROWS(proxy.Call("dac", {"vin_com"}, -1, GET));
|
||||||
REQUIRE_THROWS(proxy.Call("dac", {"vdd_prot"}, -1, GET));
|
REQUIRE_THROWS(proxy.Call("dac", {"vdd_prot"}, -1, GET));*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user