Skip to content

Commit

Permalink
m2kAnalogOut: implement setVoltage and setVoltageRaw
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
Adrian-Stanea committed Dec 8, 2023
1 parent 78035d0 commit 5ce2e27
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
17 changes: 17 additions & 0 deletions include/libm2k/analog/m2kanalogout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/analog/m2kanalogout_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<long long>(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<long long>(raw));
return chn->getLongValue("raw");
}


double M2kAnalogOutImpl::getCalibscale(unsigned int index)
{
Expand Down
3 changes: 3 additions & 0 deletions src/analog/m2kanalogout_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<libm2k::utils::DeviceGeneric> m_m2k_fabric;
std::vector<double> m_max_samplerate;
Expand Down

0 comments on commit 5ce2e27

Please sign in to comment.