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"));
|
||||
enum DACINDEX vthdacs[] = {M_VTH1, M_VTH2, M_VTH3};
|
||||
for (int i = 0; i < NCOUNTERS; ++i) {
|
||||
// if change in enable
|
||||
if ((arg & (1 << i)) ^ (oldmask & (1 << i))) {
|
||||
// will disable if counter disabled, else set corresponding vth dac
|
||||
enum DACINDEX ind[] = {M_VTH1, M_VTH2, M_VTH3};
|
||||
setDAC(ind[i], vthEnabledVals[i], 0);
|
||||
// disable, disable value
|
||||
int value = DEFAULT_COUNTER_DISABLED_VTH_VAL;
|
||||
// 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 */
|
||||
void setDAC(enum DACINDEX ind, int val, int mV) {
|
||||
// invalid value
|
||||
if (val < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// out of scope, NDAC + 1 for vthreshold
|
||||
if ((int)ind > NDAC + 1) {
|
||||
LOG(logERROR, ("Unknown dac index %d\n", ind));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ind == M_VTHRESHOLD) {
|
||||
LOG(logINFO,
|
||||
("Setting Threshold voltages to %d %s\n", val, (mV ? "mv" : "")));
|
||||
setDAC(M_VTH1, val, mV);
|
||||
setDAC(M_VTH2, val, mV);
|
||||
setDAC(M_VTH3, val, mV);
|
||||
return;
|
||||
}
|
||||
char *dac_names[] = {DAC_NAMES};
|
||||
|
||||
// remember vthx values and set 2800 if counter disabled
|
||||
uint32_t counters = getCounterMask();
|
||||
int vthdacs[] = {M_VTH1, M_VTH2, M_VTH3};
|
||||
for (int i = 0; i < NCOUNTERS; ++i) {
|
||||
if (vthdacs[i] == (int)ind) {
|
||||
// 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;
|
||||
// threshold dacs (remember value, vthreshold: skip disabled)
|
||||
if (ind == M_VTHRESHOLD || ind == M_VTH1 || ind == M_VTH2 ||
|
||||
ind == M_VTH3) {
|
||||
char *dac_names[] = {DAC_NAMES};
|
||||
int vthdacs[] = {M_VTH1, M_VTH2, M_VTH3};
|
||||
uint32_t counters = getCounterMask();
|
||||
for (int i = 0; i < NCOUNTERS; ++i) {
|
||||
if ((int)ind == vthdacs[i] || ind == M_VTHRESHOLD) {
|
||||
int dacval = val;
|
||||
// if not disabled value, remember value
|
||||
if (dacval != DEFAULT_COUNTER_DISABLED_VTH_VAL) {
|
||||
// convert mv to dac
|
||||
if (mV) {
|
||||
if (LTC2620_D_VoltageToDac(val, &dacval) == FAIL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
vthEnabledVals[i] = dacval;
|
||||
LOG(logINFO,
|
||||
("Remembering %s [%d]\n", dac_names[ind], dacval));
|
||||
}
|
||||
vthEnabledVals[i] = vthval;
|
||||
LOG(logINFO, ("Remembering %s [%d]\n", dac_names[ind], vthval));
|
||||
}
|
||||
// set vthx to disable val, if counter disabled
|
||||
if (!(counters & (1 << i))) {
|
||||
LOG(logINFO, ("Disabling %s\n", dac_names[ind]));
|
||||
val = DEFAULT_COUNTER_DISABLED_VTH_VAL;
|
||||
mV = 0;
|
||||
// if vthreshold,skip for disabled counters
|
||||
if ((ind == M_VTHRESHOLD) && (!(counters & (1 << i)))) {
|
||||
continue;
|
||||
}
|
||||
setGeneralDAC(vthdacs[i], val, mV);
|
||||
}
|
||||
}
|
||||
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],
|
||||
val, (mV ? "mV" : "dac units")));
|
||||
int dacval = val;
|
||||
@ -1334,20 +1340,29 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
|
||||
|
||||
int getDAC(enum DACINDEX ind, int mV) {
|
||||
if (ind == M_VTHRESHOLD) {
|
||||
int ret[NCOUNTERS] = {0};
|
||||
ret[0] = getDAC(M_VTH1, mV);
|
||||
ret[1] = getDAC(M_VTH2, mV);
|
||||
ret[2] = getDAC(M_VTH3, mV);
|
||||
|
||||
if ((ret[0] == ret[1]) && (ret[1] == ret[2])) {
|
||||
LOG(logINFO, ("\tvthreshold match\n"));
|
||||
return ret[0];
|
||||
} else {
|
||||
LOG(logERROR, ("\tvthreshold mismatch vth1:%d vth2:%d "
|
||||
"vth3:%d\n",
|
||||
ret[0], ret[1], ret[2]));
|
||||
return -1;
|
||||
int ret = -1, ret1 = -1;
|
||||
// get only for enabled counters
|
||||
uint32_t counters = getCounterMask();
|
||||
int vthdacs[] = {M_VTH1, M_VTH2, M_VTH3};
|
||||
for (int i = 0; i < NCOUNTERS; ++i) {
|
||||
if (counters & (1 << i)) {
|
||||
ret1 = getDAC(vthdacs[i], mV);
|
||||
// first enabled counter
|
||||
if (ret == -1) {
|
||||
ret = ret1;
|
||||
}
|
||||
// different values for enabled counters
|
||||
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) {
|
||||
|
@ -317,6 +317,9 @@ int setOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex, int val);
|
||||
int getOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex);
|
||||
#endif
|
||||
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 getMaxDacSteps();
|
||||
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
|
||||
|
@ -1238,34 +1238,6 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) {
|
||||
ret = OK;
|
||||
} else {
|
||||
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",
|
||||
serverDacIndex, val, retval);
|
||||
LOG(logERROR, (mess));
|
||||
|
@ -25,7 +25,7 @@ TEST_CASE("Setting and reading back MYTHEN3 dacs", "[.cmd][.dacs]") {
|
||||
CmdProxy proxy(&det);
|
||||
auto det_type = det.getDetectorType().squash();
|
||||
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("vrshaper") { test_dac(defs::VRSHAPER, "vrshaper", 1280); }
|
||||
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("vcal_p") { test_dac(defs::VCAL_P, "vcal_p", 1712); }
|
||||
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") {
|
||||
// Read out individual vcmp to be able to reset after
|
||||
// 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");
|
||||
}
|
||||
|
||||
// change vthreshold when counters disabled
|
||||
// disabling counters change vth values
|
||||
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;
|
||||
proxy.Call("dac", {"vth1"}, -1, GET, oss);
|
||||
REQUIRE(oss.str() == "dac vth1 2200\n");
|
||||
std::ostringstream oss1, oss2, oss3;
|
||||
proxy.Call("dac", {"vth1"}, -1, GET, oss1);
|
||||
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;
|
||||
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);
|
||||
REQUIRE(oss.str() == "dac vth2 2200\n");
|
||||
}
|
||||
// counters enabled, sets remembered values
|
||||
proxy.Call("counters", {"0", "1", "2"}, -1, PUT);
|
||||
{
|
||||
std::ostringstream oss;
|
||||
proxy.Call("dac", {"vth3"}, -1, GET, oss);
|
||||
REQUIRE(oss.str() == "dac vth3 2200\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 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
|
||||
for (int i = 0; i != det.size(); ++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});
|
||||
}
|
||||
}
|
||||
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", {"vtrim"}, -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_pixbuf"}, -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