Skip to content

Commit

Permalink
Calibration: cache voffset values and reload after calibration
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Suciu <[email protected]>
  • Loading branch information
adisuciu committed Sep 7, 2020
1 parent 3ce6fdd commit 2b8cce8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/analog/m2kanalogin_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
27 changes: 15 additions & 12 deletions src/m2kcalibration_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ANALOG_IN_CHANNEL>(0));
m_adc_ch1_vert_offset = m_m2k_adc->getVerticalOffset(static_cast<ANALOG_IN_CHANNEL>(1));

m_m2k_adc->setVerticalOffset(static_cast<ANALOG_IN_CHANNEL>(0),0);
m_m2k_adc->setVerticalOffset(static_cast<ANALOG_IN_CHANNEL>(1),0);

m_trigger_src = m_m2k_trigger->getAnalogSource();
m_m2k_trigger->setAnalogSource(CHANNEL_1);

Expand Down Expand Up @@ -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<ANALOG_IN_CHANNEL>(0), m_adc_ch0_vert_offset);
m_m2k_adc->setVerticalOffset(static_cast<ANALOG_IN_CHANNEL>(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));

Expand Down Expand Up @@ -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<ANALOG_IN_CHANNEL>(0));
m_adc_ch1_vert_offset = m_m2k_adc->getRawVerticalOffset(static_cast<ANALOG_IN_CHANNEL>(1));
} else {
m_adc_ch0_vert_offset = 0;
m_adc_ch1_vert_offset = 0;
}

m_m2k_adc->setAdcCalibOffset(static_cast<ANALOG_IN_CHANNEL>(0), 2048);
m_m2k_adc->setVerticalOffset(static_cast<ANALOG_IN_CHANNEL>(0), 0);
m_m2k_adc->setAdcCalibOffset(static_cast<ANALOG_IN_CHANNEL>(1), 2048);
m_m2k_adc->setAdcCalibOffset(static_cast<ANALOG_IN_CHANNEL>(0), 2048);
m_m2k_adc->setVerticalOffset(static_cast<ANALOG_IN_CHANNEL>(1), 0);
m_m2k_adc->setAdcCalibOffset(static_cast<ANALOG_IN_CHANNEL>(1), 2048);


// Allow some time for the voltage to settle
std::this_thread::sleep_for(std::chrono::milliseconds(50));
Expand Down Expand Up @@ -733,8 +735,9 @@ bool M2kCalibrationImpl::calibrateDAC()
}

updateDacCorrections();
restoreDacFromCalibMode();

restoreAdcFromCalibMode();
restoreDacFromCalibMode();

m_dac_calibrated = true;
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/m2kcalibration_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2b8cce8

Please sign in to comment.