I am trying to calibrate the CN0540 using pyadi-iio like IIO oscilloscope does.
I've found this commit in the pyadi-iio repo that removes the calibrate function from cn0540.py, why was this done?
Furthermore, I've tried to copy the settings used by IIO osc (see image) using pyadi-iio with the calibrate function copied from cn0532.py (this seems to be a newer impl, then the one removed from cn0540.py) and reworked.
adc = cn0540.cn0540(uri='ip:localhost')
adc.sw_cc = 1
adc.fda_disable_status = 1
adc.fda_mode = 'full-power'
adc.monitor_powerup = 0
adc_chan = adc._rxadc
dac_chan = adc._ltc2606
adc_scale = float(adc._get_iio_attr("voltage0", "scale", False, adc_chan))
dac_scale = float(adc._get_iio_attr("voltage0", "scale", True, dac_chan))
for _ in range(20):
raw = adc._get_iio_attr("voltage0", "raw", False, adc_chan)
adc_voltage = raw * adc_scale
raw = adc._get_iio_attr("voltage0", "raw", True, dac_chan)
dac_voltage = (raw * dac_scale - adc_voltage) / dac_scale
e = int(dac_voltage * dac_scale)
if int(dac_voltage) > 2 ** 16 - 1:
print(
"Warning: DAC voltage at upper limit, "
+ f"calibration may not converge (Error: {e-(2**16-1)} codes).\n"
+ "Make sure sensor is connected."
)
dac_voltage = 2 ** 16 - 1
elif int(dac_voltage) < 0:
print(
"Warning: DAC voltage at lower limit, "
+ f"calibration may not converge (Error: {e} codes).\n"
+ "Make sure sensor is connected.")
dac_voltage = 0
print(f"dac_voltage= {dac_voltage}")
adc._set_iio_attr_float("voltage0", "raw", True, int(dac_voltage), dac_chan)
print(f"adc.input_voltage= {adc.input_voltage}")
print(f"adc.shift_voltage= {adc.shift_voltage}")
print(f"adc.sensor_voltage= {adc.sensor_voltage}")
print(f"adc.rx()= {adc.rx()}")
The output of the above code is:
Warning: DAC voltage at lower limit, calibration may not converge (Error: -271 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -2089 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1934 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1815 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1730 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1662 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1610 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1571 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1539 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1515 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1496 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1481 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1469 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1459 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1452 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1446 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1441 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1437 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1434 codes). Make sure sensor is connected. dac_voltage= 0 Warning: DAC voltage at lower limit, calibration may not converge (Error: -1431 codes). Make sure sensor is connected. dac_voltage= 0 adc.input_voltage= 1743.8377985608402 adc.shift_voltage= 0.0 adc.sensor_voltage= -7975.565681703683 adc.rx()= [2883584 11402 11402 ... 11394 11394 11394]
A sensor is connected to the CN0540.
What have I missed to get good data out of the CN0540 using pyadi-iio?