CTB frequency rounding, CTB frequency measurement, CTB frequency units (#1423)

* round CTB clocks to next closest possible value, added freq measurement

* added time for firmware to measrue actual value after frequency change

* add check for backwards compatibility

* change CTB and XCTB clock values to MHz, TODO: units and validation errors

* changed runclk command to use units and float, TODO: dbit, adcclk, why is everything called StringTo ?

* do the same for dbit and adcclk

* added tolerance to exptime, fixed test

* update default values in server defs

* added virtual check in Altera_PLL, update testcases

* change python and pyctbgui to accept and return floating point MHz

* update help and comments

* Dev/ctb clocks fix (#1434)

* introduced new type Hz, typetraits, String conversions, command generation (not yet generated)

* incorrect unit typo

* cmd generation and compiles

* default to MHz, removed space between units for consistency with timers, min and max checks for clks

* in python, but need to change the default to Hz again for clean code and intuition

* allow ints, doubles, implicit conversions

* dont allow raw ints, doubles and implicit conversions

* fixed tests

* added operators for Hz in python

* fix test for min clk for xilinx ctb

* fix test

* fix python tests

* fixed xilinx period and default clks

* test fix

* removed the 3 clock cycle check for ctb and implemented properly the max adc clk frq for altera ctb

* removing 3 clock cycle code from xilinx as well

* formatting

* loadpattern before 3 clk cycles code

* actualtime and measurement time to be implemented in 100ns already in fw

* fix tests

* pyzmq dependency forthe tests

* fixed pyctbgui for freq

* insert tolerance check again

* also added tolerance check for patwaittime

* formatting

* minor: rounding test

* removed Rep redundant in ToString for freq

* intro frequency unit enums, removed unnecessary template behavior for ToString with freq unit, switching from parsing string unit argument to the enum argument for ToString, adding parsing string to unit at CLI boundary

* minor, and binaries

* minor, default clk vals are 0 but set up at detector setup

* get frequency only for that unit

* tolerance process

* missed in previous commit

* some more changes to exptime and validations

* ctb is probably done

* periodleft and delayleft

* fixed xilinx freq conv as well

* fixed m3 bug, binaries

* xilinx: setup also done in stop server so that the clk is not 0

* missed a test marker

* binaries in

* review fixes, simpler validation of timers in ctb and xilinx ctb

* typo fix

* format

* fix tests

---------

Co-authored-by: Martin Mueller <martin.mueller@psi.ch>
Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch>
This commit is contained in:
Martin Mueller
2026-05-06 15:52:13 +02:00
committed by GitHub
parent bb1a73d718
commit 0837de2a5a
57 changed files with 2239 additions and 706 deletions
+15 -15
View File
@@ -1529,23 +1529,31 @@ void init_det(py::module &m) {
Detector::setNumberOfAnalogSamples,
py::arg(), py::arg() = Positions{});
CppDetectorApi.def("getADCClock",
(Result<int>(Detector::*)(sls::Positions) const) &
(Result<defs::Hz>(Detector::*)(sls::Positions) const) &
Detector::getADCClock,
py::arg() = Positions{});
CppDetectorApi.def("setADCClock",
(void (Detector::*)(int, sls::Positions)) &
(void (Detector::*)(defs::Hz, sls::Positions)) &
Detector::setADCClock,
py::arg(), py::arg() = Positions{});
CppDetectorApi.def("getRUNClock",
(Result<int>(Detector::*)(sls::Positions) const) &
(Result<defs::Hz>(Detector::*)(sls::Positions) const) &
Detector::getRUNClock,
py::arg() = Positions{});
CppDetectorApi.def("setRUNClock",
(void (Detector::*)(int, sls::Positions)) &
(void (Detector::*)(defs::Hz, sls::Positions)) &
Detector::setRUNClock,
py::arg(), py::arg() = Positions{});
CppDetectorApi.def("getDBITClock",
(Result<defs::Hz>(Detector::*)(sls::Positions) const) &
Detector::getDBITClock,
py::arg() = Positions{});
CppDetectorApi.def("setDBITClock",
(void (Detector::*)(defs::Hz, sls::Positions)) &
Detector::setDBITClock,
py::arg(), py::arg() = Positions{});
CppDetectorApi.def("getSYNCClock",
(Result<int>(Detector::*)(sls::Positions) const) &
(Result<defs::Hz>(Detector::*)(sls::Positions) const) &
Detector::getSYNCClock,
py::arg() = Positions{});
CppDetectorApi.def("getPowerList",
@@ -1646,14 +1654,6 @@ void init_det(py::module &m) {
(void (Detector::*)(defs::readoutMode, sls::Positions)) &
Detector::setReadoutMode,
py::arg(), py::arg() = Positions{});
CppDetectorApi.def("getDBITClock",
(Result<int>(Detector::*)(sls::Positions) const) &
Detector::getDBITClock,
py::arg() = Positions{});
CppDetectorApi.def("setDBITClock",
(void (Detector::*)(int, sls::Positions)) &
Detector::setDBITClock,
py::arg(), py::arg() = Positions{});
CppDetectorApi.def("getExternalSamplingSource",
(Result<int>(Detector::*)(sls::Positions) const) &
Detector::getExternalSamplingSource,
@@ -1891,9 +1891,9 @@ void init_det(py::module &m) {
Detector::configureTransceiver,
py::arg() = Positions{});
CppDetectorApi.def(
"getPatterFileName",
"getPatternFileName",
(Result<std::string>(Detector::*)(sls::Positions) const) &
Detector::getPatterFileName,
Detector::getPatternFileName,
py::arg() = Positions{});
CppDetectorApi.def(
"setPattern",
+55
View File
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
/*
This file contains Python bindings for the Hz and for conversion to other units from and to string.
*/
#include "py_headers.h"
#include <cmath>
#include "sls/ToString.h"
#include "sls/sls_detector_defs.h"
namespace py = pybind11;
constexpr double kHz = 1e3;
constexpr double MHz = 1e6;
void init_freq(py::module &m) {
py::class_<slsDetectorDefs::Hz> Hz(m, "Hz");
Hz.def(py::init<int>());
Hz.def_readwrite("value", &slsDetectorDefs::Hz::value);
Hz.def("__repr__", [](const slsDetectorDefs::Hz &f) {
return sls::ToString(f);
});
Hz.def("__str__", [](const slsDetectorDefs::Hz &f) {
return sls::ToString(f);
});
Hz.def(py::self == py::self);
Hz.def("__mul__", [](const slsDetectorDefs::Hz &h, int x) {
return slsDetectorDefs::Hz(h.value * x);
}, py::is_operator());
Hz.def("__rmul__", [](const slsDetectorDefs::Hz &h, int x) {
return slsDetectorDefs::Hz(h.value * x);
}, py::is_operator());
Hz.def("__truediv__", [](const slsDetectorDefs::Hz &h, int x) {
return slsDetectorDefs::Hz(h.value / x);
}, py::is_operator());
Hz.def("__add__", [](const slsDetectorDefs::Hz &a,
const slsDetectorDefs::Hz &b) {
return slsDetectorDefs::Hz(a.value + b.value);
}, py::is_operator());
Hz.def("__sub__", [](const slsDetectorDefs::Hz &a,
const slsDetectorDefs::Hz &b) {
return slsDetectorDefs::Hz(a.value - b.value);
}, py::is_operator());
m.def("kHz", [](double v) {
return slsDetectorDefs::Hz(static_cast<int>(std::round(v * kHz)));
});
m.def("MHz", [](double v) {
return slsDetectorDefs::Hz(static_cast<int>(std::round(v * MHz)));
});
}
+2
View File
@@ -21,6 +21,7 @@ void init_source(py::module &);
void init_duration(py::module &);
void init_pedestal(py::module &);
void init_bit(py::module &);
void init_freq(py::module &);
PYBIND11_MODULE(_slsdet, m) {
m.doc() = R"pbdoc(
@@ -42,6 +43,7 @@ PYBIND11_MODULE(_slsdet, m) {
init_duration(m);
init_pedestal(m);
init_bit(m);
init_freq(m);
// init_experimental(m);
py::module io = m.def_submodule("io", "Submodule for io");