Post Go back to editing

Trouble calibrating CN0540 using pyadi-iio

Category: Software
Product Number: CN0540
Software Version: 0.0.16

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?

Parents
  • Hi Wyatt,

    What sensor are you using (CN0532, or other IEPE sensor?), and what is the output with a zero input? IEPE sensors typically have a 10V offset. You could measure this with a multimeter.

    Also see this issue:  CN0540/DE10-nano signal wrong 

    -Mark

      can you take a look at this as well?

  • Hi Mark,

    For testing, I'm using a skf cmss 2200 accelerometer.

    By zero input, do you mean without a sensor attached? If, so here is that output:

    Warning: DAC voltage at lower limit, calibration may not converge (Error: -299 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -2111 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1950 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1821 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1728 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1655 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1598 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1553 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1517 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1489 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1467 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1449 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1435 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1423 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1414 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1406 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1400 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1395 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1391 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    Warning: DAC voltage at lower limit, calibration may not converge (Error: -1388 codes).
    Make sure sensor is connected.
    dac_voltage= 0
    adc.input_voltage= 1689.82184965452
    adc.shift_voltage= 0.0
    adc.sensor_voltage= -7986.440015390977
    adc.rx()= [2752512   11037   11037 ...   11027   11027   11027]
    

    Probing VIN with a multimeter without a sensor attached reads 25.07, and 12.81 with the skf cmss 2200 connected.

    I'm pretty confident the issue is with how I'm using the device, because if I use IIO Oscilloscope (with a Kuiper image see this question) everything seems to work as expected.

    P.S How do link to an EZ question like in your reply?

  • Hi Wyatt,

    25.07 when disconnected, and 12.81 with the skf cmss 2200 connected sounds reasonable - and the CN0540 should be able to handle that offset.

    I've asked  to take a look at this he's more familiar with this board. In the meantime - can you try disable /commenting out the calibration routine, and manually write to the dac_chan, interpolating until you get an ADC output near zero? That should at least get everything else up and running.

    -Mark

  • Hi Mark,

    I tried to do what you suggested, and manually set the value with this script:

    from adi import cn0540
    
    adc = cn0540.cn0540(uri='ip:localhost')
    
    adc.sw_cc = 1
    adc.fda_disable_status = 0
    adc.fda_mode = 'full-power'
    adc.monitor_powerup = 1
    
    adc.shift_voltage = 4057
    
    print(f'fault flag = {adc.sw_ff_status}')
    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(adc.rx())
    

    and the output was:

    fault flag = 0
    adc.input_voltage = -1001.87802219444
    adc.shift_voltage = 4056.9575
    adc.sensor_voltage = 9041.698873213465
    [-1703936    58965    58965 ...    58965    58965    58965]
    

    however, when I have the sensor on a spinning motor, rather than sitting on my desk, I get:

    fault flag = 0
    adc.input_voltage = -993.70200098994
    adc.shift_voltage = 4056.9575
    adc.sensor_voltage = 9032.38787706089
    [-1703936    58898    58899 ...    59053    59054    59055]
    

    Which leads me to think that the sensor is somehow disconnected from the ADC, even though sw_cc, and monitor_powerup are both set to 1, and the fault flag is 0, the fault LED on the board is on as well.

    Is there something I'm missing that could disconnect the sensor from the ADC?

    Thank you,

    --- Wyatt

  • Hi  , sorry for the late reply, I've been out of the office. I don't have immediate access to a CN0540 nor the exact sensor you're using, but there's a couple of simple measurements you can do to start building confidence that the setup is working properly. You've already confirmed that the excitation current source is working, and that the sensor is at least biasing up properly. One other simple test would be to put a milliammeter in series with the sensor and measure the actual excitation current, which I believe should be 4.5 mA.

    Next, take a multimeter and start "walking" down the signal chain - does 12.81V show up at R11? If not - that would indicate that U1, S2-D2 path is open, and to check the state of SW_IN.

    But the fact that you have to bring ADC.shift_voltage all the way to near full-scale is an indication that the signal is getting through the switch. Next - check the voltages at the centre conductor of J2 and J3 - both should be around 2.5V (assuming ADC.shift_voltage is set properly). If you wiggle the sensor, J3 should wiggle.

    Next, look at the output of U4, probing at either side of R64/R65. The average of these two voltages should be 2.5V, and if you wiggle the sensor, you should see complementary waveforms.

    I WAS going to say that your adc.input_voltage of around 1000 was fine, but it looks like that's in millivolts:

    https://github.com/analogdevicesinc/pyadi-iio/blob/master/adi/cn0540.py#L65

    If that's the case, it looks like something may indeed be going on, and you'd expect to see about a volt between R64 and R65.

    Let's start with this and see if it leads to any clues. (Or ideally, the root cause.)

    -Mark

  • HI ,

    I've tested the voltages you suggested, and I seem to be getting different results than you expected.

    With the sensor sitting idle, and adc.shift_voltage set to 4057, I read:

    R11: 12.8

    J2: 2.49

    J3: 1.41

    R65: 1.57

    R64: 2.39

    None of the points wiggle with the sensor on a spinning motor.

    I don't have a setup for measuring mAh from the sensor, but since I can get good data when using the Kuiper image, and IIO Oscilloscope (IIO Oscilloscope won't work on my image), I'm sure it's got to be a config issue.

    Do these readings provide any insight for you?

    Thanks,

    --- Wyatt

Reply
  • HI ,

    I've tested the voltages you suggested, and I seem to be getting different results than you expected.

    With the sensor sitting idle, and adc.shift_voltage set to 4057, I read:

    R11: 12.8

    J2: 2.49

    J3: 1.41

    R65: 1.57

    R64: 2.39

    None of the points wiggle with the sensor on a spinning motor.

    I don't have a setup for measuring mAh from the sensor, but since I can get good data when using the Kuiper image, and IIO Oscilloscope (IIO Oscilloscope won't work on my image), I'm sure it's got to be a config issue.

    Do these readings provide any insight for you?

    Thanks,

    --- Wyatt

Children
  • Hi Wyatt,

    Probably the easiest way to get a snapshot of the configuration(s) and differences between IIO Osc and your code is to run IIO Oscilloscope and successfully capture data, then either logged into the DE10-Nano console run:

    iio_info

    or from your remote host computer:

    iio_info -u ip:analog.local

    Pay particular attention to the GPIO / one-bit-adc-dac values.

    Then run your script, verify failing behavior, then repeat the iio_info.

    This assumes that IIO Oscilloscope doesn't change any configuration stuff when you stop capturing data. Let's start with this and see what comes up.

    One other thing - can you confirm that your CN0540 class is the latest pyadi-iio master::

    github.com/.../cn0540.py

      ,  , what is your progress on this? I don't have a setup in front of me, this should be fairly straightforward. I believe you said you knew what the issue was?

    -Mark

  • Hi ,

    There doesn't seem to be any meaningful differences between the output of iio_info when using IIO oscilloscope or, the custom script:

    Custom scipt:
    
    iio_info version: 0.25 (git tag:b6028fde)
    Libiio version: 0.25 (git tag: b6028fd) backends: local xml ip serial
    IIO context created with local backend.
    Backend version: 0.25 (git tag: b6028fd)
    Backend description string: Linux HydraVibrationMonitor 5.10.0-yocto-standard-adi #1 SMP Thu Jun 1 14:38:12 UTC 2023 armv7l
    IIO context has 2 attributes:
            local,kernel: 5.10.0-yocto-standard-adi
            uri: local:
    IIO context has 5 devices:
            iio:device0: ad7768-1 (buffer capable)
                    1 channels found:
                            voltage0:  (input, index: 0, format: le:s24/32>>8)
                            2 channel-specific attributes found:
                                    attr  0: raw value: -1696742
                                    attr  1: scale value: 0.000488281
                    4 device-specific attributes found:
                                    attr  0: common_mode_voltage value: (AVDD1-AVSS)/2
                                    attr  1: common_mode_voltage_available value: (AVDD1-AVSS)/2 2V5 2V05 1V9 1V65 1V1 0V9 OFF
                                    attr  2: sampling_frequency value: 256000
                                    attr  3: sampling_frequency_available value: 256000 128000 64000 32000 16000 8000 4000 2000 1000
                    2 buffer-specific attributes found:
                                    attr  0: data_available value: 0
                                    attr  1: length_align_bytes value: 16
                    1 debug attributes found:
                                    debug attr  0: direct_reg_access value: 0x0
                    No trigger on this device
            iio:device1: ltc2308
                    8 channels found:
                            voltage6:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 178
                                    attr  1: scale value: 1.000000000
                            voltage3:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 123
                                    attr  1: scale value: 1.000000000
                            voltage7:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 130
                                    attr  1: scale value: 1.000000000
                            voltage0:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 163
                                    attr  1: scale value: 1.000000000
                            voltage4:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 121
                                    attr  1: scale value: 1.000000000
                            voltage1:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 135
                                    attr  1: scale value: 1.000000000
                            voltage5:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 130
                                    attr  1: scale value: 1.000000000
                            voltage2:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 179
                                    attr  1: scale value: 1.000000000
                    2 device-specific attributes found:
                                    attr  0: sleep_mode value: DISABLED
                                    attr  1: sleep_mode_available value: DISABLED ENABLED
                    No trigger on this device
            iio:device2: one-bit-adc-dac
                    18 channels found:
                            voltage0:  (input)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_sw_ff_gpio
                                    attr  1: raw value: 0
                            voltage1:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_red_led
                                    attr  1: raw value: 0
                            voltage5:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_FDA_DIS
                                    attr  1: raw value: 0
                            voltage10:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: mux_3
                                    attr  1: raw value: 0
                            voltage9:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: mux_2
                                    attr  1: raw value: 0
                            voltage0:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_blue_led
                                    attr  1: raw value: 1
                            voltage12:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: mux_5
                                    attr  1: raw value: 0
                            voltage13:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: mux_6
                                    attr  1: raw value: 0
                            voltage16:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: mux_9
                                    attr  1: raw value: 0
                            voltage3:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_ad7768-1-gpio0
                                    attr  1: raw value: 0
                            voltage6:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_FDA_MODE
                                    attr  1: raw value: 1
                            voltage2:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_shutdown_gpio
                                    attr  1: raw value: 1
                            voltage11:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: mux_4
                                    attr  1: raw value: 0
                            voltage14:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: mux_7
                                    attr  1: raw value: 0
                            voltage4:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_ad7768-1-gpio1
                                    attr  1: raw value: 0
                            voltage7:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: mux_0
                                    attr  1: raw value: 0
                            voltage8:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: mux_1
                                    attr  1: raw value: 0
                            voltage15:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: mux_8
                                    attr  1: raw value: 0
                    No trigger on this device
            iio:device3: ltc2606
                    1 channels found:
                            voltage0:  (output)
                            5 channel-specific attributes found:
                                    attr  0: powerdown value: 0
                                    attr  1: powerdown_mode value: 90kohm_to_gnd
                                    attr  2: powerdown_mode_available value: 90kohm_to_gnd
                                    attr  3: raw value: 53206
                                    attr  4: scale value: 0.062500000
                    No trigger on this device
            iio_sysfs_trigger:
                    0 channels found:
                    2 device-specific attributes found:
                                    attr  0: add_trigger ERROR: Permission denied (13)
                                    attr  1: remove_trigger ERROR: Permission denied (13)
                    No trigger on this device
    
    
    
    IIO Oscilloscope:
    
    Library version: 0.21 (git tag: 8b5a339)
    Compiled with backends: local xml ip usb
    IIO context created with local backend.
    Backend version: 0.21 (git tag: 8b5a339)
    Backend description string: Linux analog 4.19.0-ga6ef26d #1128 SMP Fri Feb 19 18:19:42 GMT 2021 armv7l
    IIO context has 2 attributes:
            local,kernel: 4.19.0-ga6ef26d
            uri: local:
    IIO context has 5 devices:
            iio:device0: ad7768-1 (buffer capable)
                    1 channels found:
                            voltage0:  (input, index: 0, format: le:s24/32>>8)
                            2 channel-specific attributes found:
                                    attr  0: raw value: -209095
                                    attr  1: scale value: 0.000488281
                    4 device-specific attributes found:
                                    attr  0: common_mode_voltage value: (AVDD1-AVSS)/2
                                    attr  1: common_mode_voltage_available value: (AVDD1-AVSS)/2 2V5 2V05 1V9 1V65 1V1 0V9 OFF
                                    attr  2: sampling_frequency value: 256000
                                    attr  3: sampling_frequency_available value: 256000 128000 64000 32000 16000 8000 4000 2000 1000
                    3 buffer-specific attributes found:
                                    attr  0: data_available value: 0
                                    attr  1: length_align_bytes value: 16
                                    attr  2: watermark value: 400
                    1 debug attributes found:
                                    debug attr  0: direct_reg_access value: 0x0
                    No trigger on this device
            iio:device1: ltc2308
                    8 channels found:
                            voltage6:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 253
                                    attr  1: scale value: 1.000000000
                            voltage3:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 1733
                                    attr  1: scale value: 1.000000000
                            voltage7:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 285
                                    attr  1: scale value: 1.000000000
                            voltage0:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 1648
                                    attr  1: scale value: 1.000000000
                            voltage4:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 1632
                                    attr  1: scale value: 1.000000000
                            voltage1:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 1727
                                    attr  1: scale value: 1.000000000
                            voltage5:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 1714
                                    attr  1: scale value: 1.000000000
                            voltage2:  (input)
                            2 channel-specific attributes found:
                                    attr  0: raw value: 1632
                                    attr  1: scale value: 1.000000000
                    2 device-specific attributes found:
                                    attr  0: sleep_mode value: DISABLED
                                    attr  1: sleep_mode_available value: DISABLED ENABLED
                    No trigger on this device
            iio:device2: one-bit-adc-dac
                    8 channels found:
                            voltage0:  (input)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_sw_ff_gpio
                                    attr  1: raw value: 0
                            voltage1:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_red_led
                                    attr  1: raw value: 0
                            voltage5:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_FDA_DIS
                                    attr  1: raw value: 0
                            voltage0:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_blue_led
                                    attr  1: raw value: 1
                            voltage3:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_ad7768-1-gpio0
                                    attr  1: raw value: 0
                            voltage6:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_FDA_MODE
                                    attr  1: raw value: 1
                            voltage2:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_shutdown_gpio
                                    attr  1: raw value: 1
                            voltage4:  (output)
                            2 channel-specific attributes found:
                                    attr  0: label value: cn0540_ad7768-1-gpio1
                                    attr  1: raw value: 0
                    No trigger on this device
            iio:device3: ltc2606
                    1 channels found:
                            voltage0:  (output)
                            5 channel-specific attributes found:
                                    attr  0: powerdown value: 0
                                    attr  1: powerdown_mode value: 90kohm_to_gnd
                                    attr  2: powerdown_mode_available value: 90kohm_to_gnd
                                    attr  3: raw value: 63113
                                    attr  4: scale value: 0.062500000
                    No trigger on this device
            iio_sysfs_trigger:
                    0 channels found:
                    2 device-specific attributes found:
                                    attr  0: add_trigger ERROR: Permission denied (-13)
                                    attr  1: remove_trigger ERROR: Permission denied (-13)
                    No trigger on this device
    

    The only thing that I notice is the missing watermark value from the custom script, but that's probably just from the differing libiio versions.

    I did find a weird effect when running the test script multiple times, the adc.input_voltage value would change more than expected, and more importantly the values from adc.rx() fall to single digit values even though nothing was changed about the setup, the script was just run multiple times.

    from adi import cn0540
    import time
    import numpy as np
    
    adc = cn0540.cn0540(uri='ip:localhost')
    
    adc.sw_cc = 1
    adc.fda_disable_status = 0
    adc.fda_mode = 'full-power'
    adc.monitor_powerup = 1
    
    adc.shift_voltage = 4895
    
    #adc.rx_output_type = 'SI'
    
    adc.rx_buffer_size = 400
    
    
    #print(f'fault flag = {adc.sw_ff_status}')
    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(adc.rx())
    
    with np.printoptions(threshold=np.inf):
        print(adc.rx())
    
    adc.rx_destroy_buffer()

    *NOTE* there is a line `time.sleep(5)` after `adc.rx_buffer_size = 400` I had to omit it because EZ doesn't let you post code blocks with sleep calls.

    Here is some console output where the issue happened sooner than normal, usually it happens after 10 or so script calls:

    root@HydraVibrationMonitor:/usr/bin# python3 man_cal.py
    adc.input_voltage = -3.59030089614
    adc.shift_voltage = 4894.945
    adc.sensor_voltage = 12877.285178729742
    [-131072   65512   65512   65512   65513   65512   65511   65511   65512
       65512   65513   65512   65511   65511   65512   65512   65512   65511
       65512   65512   65512   65512   65512   65512   65512   65512   65512
       65512   65511   65511   65512   65512   65512   65512   65511   65511
       65511   65511   65511   65512   65512   65512   65511   65511   65512
       65512   65512   65512   65512   65511   65511   65511   65511   65511
       65512   65513   65513   65512   65511   65511   65512   65512   65512
       65511   65511   65511   65512   65512   65511   65511   65512   65512
       65511   65511   65512   65511   65511   65511   65511   65512   65512
       65512   65512   65512   65511   65512   65511   65511   65512   65512
       65511   65511   65512   65512   65512   65511   65511   65511   65511
       65511   65511   65512   65512   65512   65511   65511   65511   65511
       65512   65511   65512   65512   65512   65513   65513   65513   65513
       65512   65512   65512   65512   65512   65512   65511   65511   65513
       65513   65512   65511   65511   65512   65512   65512   65512   65512
       65512   65512   65511   65512   65512   65513   65512   65512   65513
       65512   65512   65512   65511   65511   65511   65511   65512   65513
       65513   65512   65512   65511   65511   65511   65511   65511   65512
       65512   65511   65511   65511   65512   65513   65513   65512   65511
       65511   65512   65512   65512   65513   65513   65512   65512   65512
       65511   65511   65512   65512   65513   65513   65512   65512   65513
       65513   65512   65511   65512   65512   65512   65511   65512   65512
       65512   65512   65511   65512   65512   65511   65511   65511   65511
       65512   65512   65512   65512   65512   65512   65512   65512   65512
       65511   65511   65511   65512   65511   65511   65512   65512   65513
       65512   65512   65512   65512   65512   65512   65512   65512   65513
       65512   65512   65512   65512   65511   65511   65511   65512   65512
       65512   65512   65512   65512   65512   65512   65512   65512   65512
       65512   65512   65512   65512   65512   65511   65512   65512   65512
       65512   65511   65512   65511   65512   65512   65512   65512   65513
       65512   65512   65512   65512   65512   65512   65512   65512   65512
       65511   65511   65512   65512   65512   65512   65512   65512   65512
       65513   65512   65511   65511   65512   65512   65512   65511   65512
       65513   65513   65512   65511   65511   65511   65511   65512   65513
       65513   65512   65512   65513   65513   65513   65512   65511   65512
       65512   65512   65512   65512   65511   65511   65511   65512   65512
       65512   65511   65511   65511   65512   65512   65512   65512   65512
       65512   65513   65513   65512   65512   65512   65512   65512   65512
       65512   65512   65512   65512   65512   65512   65512   65512   65512
       65512   65512   65511   65512   65512   65511   65511   65512   65513
       65512   65512   65511   65512   65512   65512   65512   65513   65513
       65512   65512   65512   65512   65512   65512   65511   65512   65511
       65511   65511   65512   65513   65512   65511   65511   65512   65512
       65512   65512   65512   65512   65512   65513   65513   65513   65512
       65511   65511   65512   65512]
    root@HydraVibrationMonitor:/usr/bin# python3 man_cal.py
    adc.input_voltage = -0.22100574622000002
    adc.shift_voltage = 4894.945
    adc.sensor_voltage = 12878.190106532222
    [-131072   65534   65534   65534   65533   65534   65534   65534   65534
       65534   65534   65534   65533   65534   65534   65535   65534   65533
       65533   65532   65533   65534   65534   65534   65533   65533   65533
       65533   65534   65534   65534   65534   65534   65535   65534   65533
       65534   65534   65533   65533   65533   65533   65533   65533   65534
       65534   65534   65533   65533   65533   65533   65534   65534   65533
       65534   65534   65534   65534   65533   65533   65533   65534   65534
       65534   65534   65534   65534   65533   65533   65533   65534   65533
       65533   65533   65533   65534   65534   65534   65534   65534   65534
       65534   65533   65534   65534   65535   65534   65534   65534   65533
       65533   65533   65533   65534   65535   65535   65534   65534   65533
       65533   65533   65534   65535   65535   65534   65534   65534   65534
       65535   65535   65534   65534   65534   65533   65533   65533   65534
       65534   65534   65534   65534   65534   65533   65534   65535   65535
       65534   65534   65535   65535   65534   65534   65534   65534   65534
       65533   65533   65534   65535   65535   65534   65534   65534   65533
       65533   65534   65534   65535   65534   65534   65534   65534   65534
       65534   65534   65534   65534   65534   65534   65533   65533   65534
       65534   65534   65535   65534   65534   65534   65534   65533   65534
       65535   65535   65534   65534   65534   65534   65534   65534   65534
       65533   65533   65533   65533   65534   65535   65534   65534   65533
       65533   65534   65534   65535   65535   65535   65535   65535   65535
       65535   65534   65534   65535   65534   65534   65533   65534   65534
       65534   65534   65533   65533   65533   65534   65534   65534   65534
       65534   65534   65534   65534   65534   65534   65534   65534   65534
       65535   65535   65535   65535   65535   65534   65534   65534   65533
       65533   65534   65534   65534   65534   65534   65534   65535   65534
       65535   65535   65535   65534   65534   65534   65534   65533   65533
       65533   65534   65534   65534   65534   65533   65534   65535   65534
       65534   65533   65534   65534   65534   65534   65534   65534   65534
       65534   65534   65534   65534   65534   65534   65534   65534   65534
       65534   65534   65534   65534   65534   65534   65534   65534   65534
       65534   65534   65535   65535   65535   65535   65534   65534   65534
       65534   65534   65533   65534   65534   65535   65535   65534   65534
       65534   65533   65533   65533   65533   65533   65534   65533   65533
       65533   65534   65534   65534   65535   65534   65534   65533   65534
       65534   65534   65534   65534   65534   65533   65534   65534   65534
       65534   65534   65535   65535   65534   65534   65533   65533   65534
       65534   65535   65535   65535   65534   65534   65534   65535   65534
       65533   65534   65534   65534   65534   65535   65534   65533   65533
       65534   65534   65534   65534   65533   65533   65533   65534   65533
       65533   65534   65534   65534   65534   65534   65534   65535   65534
       65534   65533   65533   65533   65534   65534   65534   65535   65534
       65534   65534   65534   65534   65533   65533   65533   65533   65533
       65533   65533   65534   65534]
    root@HydraVibrationMonitor:/usr/bin# python3 man_cal.py
    adc.input_voltage = 0.68684535146
    adc.shift_voltage = 4894.945
    adc.sensor_voltage = 12878.209411421238
    [0 3 4 4 5 5 5 5 5 5 5 5 4 4 4 5 5 4 4 5 5 5 5 4 5 5 5 5 5 5 4 5 5 6 5 4 4
     5 6 6 5 4 4 4 5 5 5 5 5 5 4 4 5 5 4 4 5 5 5 5 4 4 4 5 5 5 4 4 5 4 4 4 6 6
     5 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 4 4 5 5 4 4 5 5 5 5 4 4 5 4 4 4 4 5 5 5 5
     5 5 4 4 5 5 5 5 5 5 4 5 5 5 4 4 5 5 5 5 5 6 6 5 5 5 5 5 5 5 5 5 4 4 4 4 5
     6 6 5 5 6 6 5 5 4 4 4 4 4 4 4 4 4 5 4 4 6 6 5 5 4 4 5 5 5 5 5 4 3 4 4 4 4
     5 5 4 4 4 4 5 4 4 5 4 4 4 5 5 5 5 6 5 5 5 5 4 4 5 5 5 4 5 5 5 5 4 4 4 3 4
     4 5 5 5 5 5 5 6 5 6 6 5 5 5 5 5 5 5 4 4 4 5 6 5 4 4 4 5 5 5 4 4 5 5 4 5 4
     4 4 4 5 4 4 4 5 5 5 4 4 5 5 5 5 5 5 5 5 5 4 4 3 4 4 4 5 5 6 5 5 6 5 4 3 4
     4 4 4 4 5 5 5 5 5 4 4 4 4 5 6 5 5 5 4 4 4 4 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4
     5 5 5 5 6 5 5 5 4 4 4 5 5 4 4 4 5 5 5 5 5 5 5 5 5 4 4 4 4 5 4 4 4 5 5 5 5
     5 4 4 4 5 5 5 5 5 5 6 6 5 4 5 5 5 5 5 5 4 4 4 5 5 5 5 5 5 5]
    root@HydraVibrationMonitor:/usr/bin# python3 man_cal.py
    adc.input_voltage = 1.36177664652
    adc.shift_voltage = 4894.945
    adc.sensor_voltage = 12878.32980024165
    [ 0  9  9  8  8  8  9  9  9  8  9  9  9  9  9  9  9  9  9  9  9 10 10  9
      9  9  9  9  8  8  8  9  9  9  9  8  8  8  9  8  7  8  8  8  8  8  7  7
      8 10  9  9  9  9  9  9  9  9  8  8  8  8  9 10  9  8  8  9  9  8  8  8
      8  8  8  8  9  9  9  9  9  9  9  9  8  8  7  8  9  9  9  9  9  9  9  9
      9  9  8  8  8  8  8  8  9  9  9  9  9  8  9  9  9  9  9  8  8  9  9  9
      9  9  9  9  9  8  8  8 10 10  9  8  9  9  9  9  8  8  9  9  9 10 10 10
     10 10  9  8  8  8  8  8  8  8  7  8  8  8  8  8  9  9  9  9  9  9  8  8
      8  9  9  9  9  9  8  8  9  9  9  9  9  8  8  9  9  9  9  9  9  9  9  8
      9  9  8  8  9  9  9  9  9  9  9  8  8  8  8  9  9  9  9  9  9  9  9  9
     10  9  9  9  8  8  8  9  9  9  9  9  9  8  9 10 10 10  9  9  9  9 10 10
      9  8  8  9 10 10  8  8  9  9  9  8  9  9  9  8  8  9  9  9  8  8  9  9
      9  9 10  9  9  8  8  9  9  9  9  9  9  9  8  8  9  9 10  9  9  9  9 10
     10  9  9  9  9  9  9  8  8  8  9  9 10  9  9  9  9  9  9  9  8  9 10 10
      9  9  9  9  9 10 10 10  9  9  9  9  9  9  8  8  8  9  9  9  9  9  9  9
      8  8  9  9  9  8  8  9  9  9  9 10 10 10 10  9  9  8  9  9 10 10  9  9
     10 10  9  9  9  9  9  9 10 10  9  9 10 10  9  9  8  8  8  9  9  9  9  9
      9  8  7  7  8  9  9  9  9  9  9 10 10  9  9  9]
    root@HydraVibrationMonitor:/usr/bin# python3 man_cal.py
    adc.input_voltage = 1.8240420348400002
    adc.shift_voltage = 4894.945
    adc.sensor_voltage = 12878.463066168979
    [ 0 12 12 11 11 12 12 11 11 12 12 12 11 11 10 11 12 11 11 11 11 11 11 11
     11 11 11 12 12 12 11 11 11 11 11 11 11 12 11 10 10 11 11 10 10 11 11 11
     10 10 11 11 11 11 11 10 10 10 11 11 11 11 11 11 12 12 11 11 11 11 11 11
     10 10 11 11 12 11 11 11 11 10 11 11 11 11 11 12 12 11 10 10 11 11 10 10
     10 11 11 11 11 10 10 10 10 11 11 11 11 11 11 11 11 12 12 12 11 11 11 11
     11 12 12 12 11 11 10 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 10 10
     10 10 11 11 11 11 11 11 11 11 11 10 10 11 12 12 12 11 11 11 11 11 11 11
     11 11 11 11 11 11 11 11 11 11 11 11 10 11 12 11 11 11 11 11 11 11 10 10
     10 10 10 10 11 12 12 11 11 11 11 11 11 11 12 12 11 11 11 11 11 10 11 11
     11 10 10 10 11 11 12 11 11 11 12 12 11 11 11 11 10 10 10 11 11 11 12 12
     11 11 11 11 11 11 11 11 11 12 12 11 11 11 11 11 11 11 11 10 10 11 11 11
     10 10 11 11 11 11 11 11 11 11 11 11 11 11 10 10 10 10 10 10 11 11 11 11
     12 12 12 11 11 11 11 11 11 10 11 12 11 11 11 11 11 11 12 12 11 10 11 11
     11 11 12 11 10 10 10 11 12 11 11  9 10 11 11 11 12 11 11 12 12 12 12 11
     10 11 12 12 12 12 11 11 11 11 11 11 10 11 11 10 10 11 11 11 12 12 12 12
     11 10 10 11 10 10 11 12 12 12 11 11 11 12 12 12 11 11 11 11 11 10 10 11
     12 12 12 11 11 11 12 12 12 11 11 12 12 12 11 11]
    

    Thank you,

    --- Wyatt

  • Hi ,

    I believe I've found where the problem is, although I'm not sure what the cause is.

    I set up pyadi-iio on my desktop, and remotely read from the device. If the device has booted the Kuiper image from ADI, pyadi-iio is able to get good data from it, however if the device boots from my custom image, the issue occurs.

    I'm not sure what could be different about my image that would cause this, my image shows nothing to make me think I'm missing a driver, and the device tree is the same used in the Kuiper image, just modified to have extra GPIO added to one-bit-adc-dac.

    Is there any documentation about needed components for linux?

    Thank you,

    --- Wyatt

  • Hi Wyatt, I forgot about the fact that you're using a custom image - I'll have to defer to the software team that's much more knowledgeable about that process.

    But this does exonerate the hardware, correct?

    Also - looking back through this thread and your other query, it would be helpful to have a summary or table of what works and what doesn't, and what's intermittent, on your image vs. Kuiper, IIO Oscilloscope vs. Python, and whether scripts are running locally or on a remote host. It sounds like in some circumstances, you get correct results for a few buffers, then something goes wrong?

    You also want to take out as many variables as possible in this debugging process - on hint would be to use a signal generator instead of your sensor, with a fixed offset such that you can blindly program a value into the offsetting DAC that centers the ADC data around zero. This eliminates the calibration routine. Then on top of the offset, superimpose a known, 1Vp-p, 1 kHz sinewave, or something that's very easy to recognize in both time and frequency domain.

    Also for the SW team - what Kuiper artifacts are you using directly, vs. building on your own? (Kernel, boot files, device tree, etc.)

    -Mark

  • Hello,

    The issue was found!

    Reverting this commit (4d4e293) from the adi kernel repo, causes the data received to behave normally.

    I'm not sure what should (or can) be done to solve this issue more permanently, especially since the commit is a year old.

    And thank you   for your help with troubleshooting.

    --- Wyatt

  • Thanks for posting your find!

      does this warrant further investigation? (And does it make sense that this would fix Wyatt's issue?)

    -Mark