diff --git a/src/analog/m2kanalogin_impl.cpp b/src/analog/m2kanalogin_impl.cpp index 5515b89b..d8291d3a 100644 --- a/src/analog/m2kanalogin_impl.cpp +++ b/src/analog/m2kanalogin_impl.cpp @@ -579,6 +579,7 @@ void M2kAnalogInImpl::setRange(ANALOG_IN_CHANNEL channel, M2K_RANGE range) } m_m2k_fabric->setStringValue(channel, "gain", std::string(str_gain_mode)); + setVerticalOffset(channel,m_adc_hw_vert_offset[channel]); m_trigger->setCalibParameters(channel, getScalingFactor(channel), m_adc_hw_vert_offset.at(channel)); } diff --git a/src/m2kcalibration_impl.cpp b/src/m2kcalibration_impl.cpp index 3cd462b9..22d46ac4 100644 --- a/src/m2kcalibration_impl.cpp +++ b/src/m2kcalibration_impl.cpp @@ -95,9 +95,16 @@ void M2kCalibrationImpl::setAdcInCalibMode() // Make sure hardware triggers are disabled before calibrating m_trigger0_mode = m_m2k_trigger->getAnalogMode(ANALOG_IN_CHANNEL_1); m_trigger1_mode = m_m2k_trigger->getAnalogMode(ANALOG_IN_CHANNEL_2); + m_m2k_trigger->setAnalogMode(ANALOG_IN_CHANNEL_1, ALWAYS); m_m2k_trigger->setAnalogMode(ANALOG_IN_CHANNEL_2, ALWAYS); + m_adc_ch0_vert_offset = m_m2k_adc->getVerticalOffset(static_cast(0)); + m_adc_ch1_vert_offset = m_m2k_adc->getVerticalOffset(static_cast(1)); + + m_m2k_adc->setVerticalOffset(static_cast(0),0); + m_m2k_adc->setVerticalOffset(static_cast(1),0); + m_trigger_src = m_m2k_trigger->getAnalogSource(); m_m2k_trigger->setAnalogSource(CHANNEL_1); @@ -143,6 +150,9 @@ void M2kCalibrationImpl::restoreAdcFromCalibMode() m_m2k_adc->setSampleRate(adc_sampl_freq); m_m2k_adc->setOversamplingRatio(adc_oversampl); + m_m2k_adc->setVerticalOffset(static_cast(0), m_adc_ch0_vert_offset); + m_m2k_adc->setVerticalOffset(static_cast(1), m_adc_ch1_vert_offset); + m_m2k_adc->enableChannel(0, m_adc_channels_enabled.at(0)); m_m2k_adc->enableChannel(1, m_adc_channels_enabled.at(1)); @@ -190,19 +200,11 @@ bool M2kCalibrationImpl::calibrateADCoffset() // Ground ADC inputs setCalibrationMode(ADC_GND); - // Set DAC channels to middle scale - if (m_m2k_adc->hasCalibbias()) { - m_adc_ch0_vert_offset = m_m2k_adc->getRawVerticalOffset(static_cast(0)); - m_adc_ch1_vert_offset = m_m2k_adc->getRawVerticalOffset(static_cast(1)); - } else { - m_adc_ch0_vert_offset = 0; - m_adc_ch1_vert_offset = 0; - } - - m_m2k_adc->setAdcCalibOffset(static_cast(0), 2048); m_m2k_adc->setVerticalOffset(static_cast(0), 0); - m_m2k_adc->setAdcCalibOffset(static_cast(1), 2048); + m_m2k_adc->setAdcCalibOffset(static_cast(0), 2048); m_m2k_adc->setVerticalOffset(static_cast(1), 0); + m_m2k_adc->setAdcCalibOffset(static_cast(1), 2048); + // Allow some time for the voltage to settle std::this_thread::sleep_for(std::chrono::milliseconds(50)); @@ -733,8 +735,9 @@ bool M2kCalibrationImpl::calibrateDAC() } updateDacCorrections(); - restoreDacFromCalibMode(); + restoreAdcFromCalibMode(); + restoreDacFromCalibMode(); m_dac_calibrated = true; return true; diff --git a/src/m2kcalibration_impl.hpp b/src/m2kcalibration_impl.hpp index 82fc02c2..305f009d 100644 --- a/src/m2kcalibration_impl.hpp +++ b/src/m2kcalibration_impl.hpp @@ -84,8 +84,8 @@ class M2kCalibrationImpl : public M2kCalibration int m_adc_ch0_offset; int m_adc_ch1_offset; - int m_adc_ch0_vert_offset; - int m_adc_ch1_vert_offset; + double m_adc_ch0_vert_offset; + double m_adc_ch1_vert_offset; int m_dac_a_ch_offset; int m_dac_b_ch_offset; double m_adc_ch0_gain;