Skip to content

Commit

Permalink
Calibration: Call stopAcquisition after every getSamplesRaw
Browse files Browse the repository at this point in the history
Previously stopAcquisition was only after calibrating ADC and DAC
alltogether. This causes the calibration to use continous buffer values
between calibration steps. ADC read does about 22 reads (one for offset
20 for fine tuning the offset and another one for gain), while DAC
calibration makes use of the ADC to calibrate offset and gain with one
read each. The buffers were continous to some measure due to the kernel
buffer configuration. By stopping the acquistion - we destroy the buffers
and force a reacquistion. This should give out better calibration values.

Signed-off-by: Adrian Suciu <adrian.suciu@analog.com>
  • Loading branch information
adisuciu committed Sep 7, 2020
1 parent 713d80d commit 3ce6fdd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/m2kcalibration_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ bool M2kCalibrationImpl::calibrateADCoffset()

const unsigned int num_samples = 1e5;
ch_data = m_m2k_adc->getSamplesRaw(num_samples);
m_m2k_adc->stopAcquisition();

if (ch_data.size() == 0) {
return false;
}
Expand Down Expand Up @@ -254,6 +256,8 @@ bool M2kCalibrationImpl::calibrateADCgain()
setCalibrationMode(ADC_REF1);

ch_data = m_m2k_adc->getSamplesRaw(num_samples);
m_m2k_adc->stopAcquisition();

if (ch_data.size() == 0) {
return false;
}
Expand Down Expand Up @@ -419,6 +423,8 @@ bool M2kCalibrationImpl::fine_tune(size_t span, int16_t centerVal0, int16_t cent
std::this_thread::sleep_for(std::chrono::milliseconds(5));

ch_data = m_m2k_adc->getSamplesRaw(num_samples);
m_m2k_adc->stopAcquisition();

if (ch_data.size() == 0) {
goto out_cleanup;
}
Expand Down Expand Up @@ -558,6 +564,8 @@ bool M2kCalibrationImpl::calibrateDACoffset()
std::this_thread::sleep_for(std::chrono::milliseconds(50));

ch_data = m_m2k_adc->getSamplesRaw(num_samples);
m_m2k_adc->stopAcquisition();

if (ch_data.size() == 0) {
return false;
}
Expand Down Expand Up @@ -627,6 +635,8 @@ bool M2kCalibrationImpl::calibrateDACgain()

const unsigned int num_samples = 15e4;
ch_data = m_m2k_adc->getSamplesRaw(num_samples);
m_m2k_adc->stopAcquisition();

if (ch_data.size() == 0) {
return false;
}
Expand Down Expand Up @@ -687,7 +697,6 @@ bool M2kCalibrationImpl::calibrateADC()
updateAdcCorrections();
restoreAdcFromCalibMode();
m_adc_calibrated = true;
m_m2k_adc->stopAcquisition();
return true;
calibration_fail:
m_cancel=false;
Expand Down Expand Up @@ -728,7 +737,6 @@ bool M2kCalibrationImpl::calibrateDAC()
restoreAdcFromCalibMode();

m_dac_calibrated = true;
m_m2k_adc->stopAcquisition();
return true;
calibration_fail:
m_cancel=false;
Expand Down

0 comments on commit 3ce6fdd

Please sign in to comment.