From 5ce2e27414cb12ae09a3760ce1e0a82487384865 Mon Sep 17 00:00:00 2001 From: Adrian Stanea Date: Fri, 8 Dec 2023 15:19:38 +0200 Subject: [PATCH] m2kAnalogOut: implement setVoltage and setVoltageRaw - when these functions are called the output of the corresponding channel should be set to the specified value - the change should be reflected in the iio channel raw attribute for dac-a and dac-b Signed-off-by: Adrian Stanea --- include/libm2k/analog/m2kanalogout.hpp | 17 +++++++++++++++++ src/analog/m2kanalogout_impl.cpp | 19 +++++++++++++++++++ src/analog/m2kanalogout_impl.hpp | 3 +++ 3 files changed, 39 insertions(+) diff --git a/include/libm2k/analog/m2kanalogout.hpp b/include/libm2k/analog/m2kanalogout.hpp index d48b0bd7..05452829 100644 --- a/include/libm2k/analog/m2kanalogout.hpp +++ b/include/libm2k/analog/m2kanalogout.hpp @@ -469,6 +469,23 @@ class LIBM2K_API M2kAnalogOut * @return double - the value of the maximum samplerate */ virtual double getMaximumSamplerate(unsigned int chn_idx) = 0; + + + /** + * @brief Sets the voltage output of the DAC channel + * @param chn_idx - unsigned int representing the index of the channel + * @param volts - actual value to be set + * @return unsigned short - the corresponding raw value for the given voltage + */ + virtual unsigned short setVoltage(unsigned int chn_idx, double volts) = 0; + + /** + * @brief Sets the raw output of the DAC channel + * @param chn_idx - unsigned int representing the index of the channel + * @param raw - actual value to be set + * @return unsigned short - the value set in the raw attribute + */ + virtual unsigned short setVoltageRaw(unsigned int chn_idx, unsigned short raw) = 0; }; } } diff --git a/src/analog/m2kanalogout_impl.cpp b/src/analog/m2kanalogout_impl.cpp index f9730cff..1ad0600c 100644 --- a/src/analog/m2kanalogout_impl.cpp +++ b/src/analog/m2kanalogout_impl.cpp @@ -132,6 +132,25 @@ void M2kAnalogOutImpl::loadNbKernelBuffers() } } } +unsigned short M2kAnalogOutImpl::setVoltage(unsigned int chn_idx, double volts) +{ + auto chn = getDacDevice(chn_idx)->getChannel(0, true); + auto raw = static_cast(convertVoltsToRaw(chn_idx, volts)); + // having the raw_enable attribute set to enable shout give at the dac output the corresponding raw value + chn->setStringValue("raw_enable", "enabled"); + chn->setLongValue("raw", raw); + return chn->getLongValue("raw"); +} + +unsigned short M2kAnalogOutImpl::setVoltageRaw(unsigned int chn_idx, unsigned short raw) +{ + auto chn = getDacDevice(chn_idx)->getChannel(0, true); + // having the raw_enable attribute set to enable shout give at the dac output the corresponding raw value + chn->setStringValue("raw_enable", "enabled"); + chn->setLongValue("raw", static_cast(raw)); + return chn->getLongValue("raw"); +} + double M2kAnalogOutImpl::getCalibscale(unsigned int index) { diff --git a/src/analog/m2kanalogout_impl.hpp b/src/analog/m2kanalogout_impl.hpp index 26efb7e6..2e5bc23b 100644 --- a/src/analog/m2kanalogout_impl.hpp +++ b/src/analog/m2kanalogout_impl.hpp @@ -92,6 +92,9 @@ class M2kAnalogOutImpl : public M2kAnalogOut void deinitialize(); void loadNbKernelBuffers(); + unsigned short setVoltage(unsigned int chn_idx, double volts) override; + unsigned short setVoltageRaw(unsigned int chn_idx, unsigned short raw) override; + private: std::shared_ptr m_m2k_fabric; std::vector m_max_samplerate;