Post Go back to editing

Using iio_readdev with ADALM2000 (M2K) and analog trigger

Thread Summary

The user is trying to capture ADC data from ADALM2000 using iio_readdev with an analog trigger configured through sysfs. The final answer suggests using m2kcli on the target itself to configure the trigger and capture data, with specific commands for setting the trigger level, hysteresis, and other parameters. The user successfully configured and captured data using m2kcli, confirming the solution.
AI Generated Content
Category: Hardware
Product Number: ADALM2000

I’m trying to capture ADC data from ADALM2000 using iio_readdev with an analog trigger configured through sysfs.
The goal is to start acquisition when the signal on channel 0 crosses a defined level.

I tried this without success:

echo 0 > /sys/bus/iio/devices/iio:device11/streaming
echo edge-rising > /sys/bus/iio/devices/iio:device11/in_voltage0_trigger
echo 10 > /sys/bus/iio/devices/iio:device11/in_voltage0_trigger_level
echo 0 > /sys/bus/iio/devices/iio:device11/in_voltage0_trigger_hysteresis
echo analog > /sys/bus/iio/devices/iio:device11/in_voltage4_trigger_logic_mode
echo out > /sys/bus/iio/devices/iio:device11/in_voltage4_trigger_logic_out_direction
echo trigger-adc > /sys/bus/iio/devices/iio:device11/in_voltage4_trigger_logic_out_select
echo a > /sys/bus/iio/devices/iio:device11/in_voltage6_trigger_logic_mode
echo 0 > /sys/bus/iio/devices/iio:device11/in_voltage6_trigger_delay
( iio_readdev -b 1200 m2k-adc voltage0 > evento.bin ) & PID=$!
sleep 0.3
echo 1 > /sys/bus/iio/devices/iio:device11/streaming
wait $PID

What is the correct way to associate the analog trigger (m2k-adc-trigger) with the ADC (m2k-adc) so that iio_readdev works?
Are there any working examples for ADC acquisition with analog trigger?

Additional context:

Hardware: ADALM2000 Rev.D
Firmware: latest available
Backend: libiio via IP (ip:m2k.local)
Final goal: capture fast pulses (~2000 ns) using analog trigger, without relying on Scopy.

  • m2k-adc-trigger is not an IIO trigger and cannot be used with iio_readdev with the -t option. You need to configure m2k-adc-trigger using iio_attr and then use iio_readdev with m2k-adc. We have also built a command line tool that handles all of this - m2kcli https://wiki.analog.com/university/tools/m2k/libm2k/m2kcli 

  • Thanks for your reply. I believe m2kcli is not a suitable option for my application, since I need to perform the acquisition and processing directly on the ADALM2000 to avoid the USB transfer rate bottleneck. I tried configuring the trigger using iio_attr as follows:


    cd /sys/bus/iio/devices/iio:device13
    echo 0 > buffer/enable
    echo 1 > scan_elements/in_voltage0_en
    echo 1400 > buffer/length
    iio_attr -q -c m2k-adc-trigger voltage0 trigger edge-rising
    iio_attr -q -c m2k-adc-trigger voltage0 trigger_level 2060
    iio_attr -q -c m2k-adc-trigger voltage0 trigger_hysteresis 10
    iio_attr -q -c m2k-adc-trigger voltage6 logic_mode a
    iio_attr -q -c m2k-adc-trigger voltage5 out_direction out
    iio_attr -q -c m2k-adc-trigger voltage5 out_select trigger-adc
    iio_attr -q -d m2k-adc-trigger streaming 0
    iio_attr -q -d m2k-adc-trigger streaming 1
    echo 1 > buffer/enable
    iio_readdev -b 1400 -s 1400 m2k-adc voltage0 > /tmp/pulse_trig.raw

    However, the acquired samples are still centered around 2048 (i.e., zero volts), which indicates that the trigger is not working as expected. The input pulses are positive, up to 1 V in amplitude, and approximately 2 µs in duration. Could you please point out what might be wrong with this configuration or suggest how to properly set up the trigger for this case?

  • m2kcli works on the target itself in one of the later firmware versions. 

    If you want to go the iio_attr route, I'd suggest the following:

    • iio_info the ADALM2000 and save the output to a file.
    • go to Scopy, set up the trigger the desired way and iio_info again to another file. If you are using the ip URI (ip:192.168.2.1) you cna have a connection from both Scopy and iio_info at the same time
    • check out the m2k-adc-trigger config or diff the files and find out the correct settings.

    -Adrian

  • I did not know it was possible to use m2kcli on the target itself. I am running firmware version 0.33, but I was not able to use m2kcli.

    First, I use ssh to conect to ADALM2000:
    ssh root@192.168.2.1

    Then, I used this commands without success:

    # m2kcli -v
    v0.8.0

    # m2kcli -s
    # m2kcli -i 127.0.0.1
    Could not establish a connection to m2k. Please check the URI
    # m2kcli -i 192.168.2.1
    Could not establish a connection to m2k. Please check the URI

    What am I doing wrong?

  • By the way, I tried using iio with this command based on scopy and it did not worked. The output seems to be the baseline.

    cd /sys/bus/iio/devices/iio:device13
    echo 0 > buffer/enable
    echo 0 > scan_elements/in_voltage1_en || true
    echo 1 > scan_elements/in_voltage0_en
    echo 1400 > buffer/length
    iio_attr -q -c m2k-fabric voltage0 powerdown 0
    iio_attr -q -c m2k-fabric voltage1 powerdown 0
    iio_attr -q -c m2k-fabric voltage0 gain high
    iio_attr -q -c m2k-fabric voltage1 gain high
    iio_attr -q -d m2k-adc oversampling_ratio 1
    iio_attr -q -d m2k-adc calibrate true
    iio_attr -d m2k-adc-trigger streaming 0
    iio_attr -q -c m2k-adc-trigger voltage4 mode analog
    iio_attr -q -c m2k-adc-trigger voltage6 logic_mode a
    iio_attr -q -c m2k-adc-trigger voltage6 delay -10
    iio_attr -q -c m2k-adc-trigger voltage0 trigger edge-rising
    iio_attr -q -c m2k-adc-trigger voltage0 trigger_hysteresis 6
    iio_attr -q -c m2k-adc-trigger voltage0 trigger_level 78
    iio_attr -q -c m2k-adc-trigger voltage5 out_direction out
    iio_attr -q -c m2k-adc-trigger voltage5 out_select trigger-adc
    echo 1 > buffer/enable
    iio_attr -d m2k-adc-trigger streaming 1
    iio_readdev -b 1400 -s 1400 m2k-adc voltage0 > /tmp/pulse_trig.raw

    hexdump -v -e '1/2 "%d\n"' /tmp/pulse_trig.raw | awk '{print $1+2048}' > /tmp/file.txt

    2061
    2051
    2060
    2050
    2061
    2049
    2060
    2049
    2059
    2048
    2059
    2049
    2059
    2049
    2061
    2049
    2059
    2051
    2059
    2049
    2059
    2050
    2061
    2050
    2058
    2050
    2058
    2051
    2058
    2051
    2059
    2050
    2059
    2049
    2058
    2051
    2059
    2050
    2059
    2050
    2058
    2050
    2059
    2049
    2059
    2049
    2059
    2049
    2057
    2049
    2060
    2051
    2058
    2050
    2059
    2051
    2058
    2050
    2060
    2049
    2060
    2051
    2059
    2050
    2059
    2049
    2060
    2050
    2059
    2050
    2060
    2049
    2058
    2050
    2059
    2050
    2058
    2049
    2058
    2050
    2060
    2050
    2059
    2049
    2057
    2049
    2059
    2050
    2060
    2049
    2059
    2049
    2060
    2049
    2059
    2050
    2059
    2050
    2059
    2051
    2059
    2049
    2059
    2050
    2059
    2050
    2059
    2051
    2059
    2050
    2059
    2050
    2060
    2049
    2059
    2048
    2059
    2051
    2060
    2051
    2060
    2052
    2058
    2050
    2058
    2050
    2060
    2050
    2059
    2049
    2058
    2051
    2059
    2050
    2057
    2050
    2058
    2049
    2058
    2048
    2059
    2050
    2059
    2049
    2059
    2050
    2057
    2048
    2059
    2048
    2060
    2049
    2057
    2050
    2059
    2049
    2059
    2050
    2060
    2050
    2059
    2050
    2061
    2050
    2059
    2050
    2060
    2052
    2059
    2049
    2058
    2048
    2059
    2048
    2060
    2050
    2060
    2049
    2060
    2050
    2059
    2050
    2059
    2049
    2061
    2049
    2059
    2050
    2059
    2049
    2060
    2048
    2059
    2050
    2061
    2051
    2058
    2048
    2059
    2051
    2058
    2050
    2060
    2049
    2059
    2049
    2060
    2052
    2059
    2049
    2060
    2051
    2059
    2051
    2059
    2049
    2059
    2050
    2060
    2050
    2058
    2050
    2060
    2049
    2059
    2050
    2059
    2050
    2059
    2050
    2059
    2052
    2059
    2051
    2060
    2050
    2059
    2050
    2060
    2050
    2059
    2048
    2059
    2050
    2060
    2049
    2060
    2050
    2058
    2048
    2058
    2050
    2059
    2049
    2059
    2051
    2060
    2050
    2060
    2050
    2059
    2049
    2059
    2050
    2058
    2049
    2058
    2051
    2058
    2049
    2059
    2050
    2059
    2049
    2060
    2050
    2060
    2049
    2059
    2050
    2059
    2050
    2061
    2051
    2060
    2050
    2060
    2052
    2059
    2050
    2059
    2051
    2058
    2050
    2058
    2051
    2058
    2050
    2058
    2050
    2057
    2049
    2059
    2050
    2058
    2049
    2059
    2050
    2057
    2051
    2059
    2050
    2058
    2049
    2059
    2049
    2058
    2050
    2058
    2050
    2059
    2049
    2059
    2050
    2059
    2049
    2058
    2050
    2059
    2051
    2059
    2049
    2058
    2049
    2059
    2051
    2057
    2049
    2057
    2050
    2057
    2050
    2058
    2051
    2059
    2048
    2058
    2050
    2058
    2049
    2059
    2050
    2057
    2049
    2057
    2049
    2058
    2051
    2059
    2049
    2059
    2050
    2060
    2050
    2058
    2049
    2059
    2050
    2059
    2048
    2059
    2049
    2060
    2049
    2059
    2050
    2059
    2049
    2058
    2051
    2058
    2050
    2058
    2050
    2057
    2050
    2059
    2050
    2060
    2049
    2058
    2051
    2060
    2050
    2058
    2051
    2059
    2050
    2058
    2050
    2058
    2050
    2059
    2051
    2058
    2050
    2058
    2048
    2059
    2048
    2058
    2050
    2058
    2051
    2057
    2050
    2058
    2049
    2059
    2049
    2058
    2050
    2059
    2051
    2059
    2048
    2058
    2050
    2059
    2051
    2059
    2050
    2059
    2050
    2058
    2050
    2057
    2049
    2060
    2049
    2058
    2048
    2060
    2048
    2060
    2048
    2059
    2050
    2059
    2048
    2057
    2050
    2058
    2049
    2060
    2050
    2060
    2050
    2060
    2050
    2061
    2048
    2061
    2050
    2060
    2049
    2058
    2050
    2060
    2050
    2060
    2051
    2060
    2051
    2060
    2049
    2058
    2049
    2059
    2049
    2059
    2049
    2059
    2050
    2059
    2049
    2060
    2050
    2058
    2050
    2059
    2051
    2058
    2049
    2059
    2050
    2060
    2049
    2060
    2049
    2059
    2050
    2059
    2051
    2060
    2050
    2058
    2051
    2059
    2051
    2059
    2051
    2059
    2051
    2059
    2050
    2060
    2049
    2059
    2049
    2059
    2049
    2060
    2050
    2060
    2049
    2061
    2050
    2060
    2049
    2058
    2050
    2059
    2049
    2058
    2050
    2060
    2049
    2059
    2050
    2060
    2050
    2061
    2051
    2060
    2051
    2060
    2050
    2060
    2050
    2060
    2051
    2061
    2050
    2059
    2051
    2061
    2049
    2061
    2051
    2061
    2050
    2060
    2049
    2060
    2051
    2059
    2050
    2058
    2049
    2059
    2050
    2059
    2051
    2058
    2051
    2058
    2050
    2059
    2050
    2058
    2050
    2059
    2051
    2060
    2050
    2061
    2051
    2058
    2051
    2059
    2051
    2058
    2048
    2060
    2050
    2060
    2048
    2061
    2050
    2060
    2051
    2059
    2050
    2058
    2050
    2059
    2051
    2059
    2049
    2059
    2049
    2059
    2050
    2059
    2050
    2059
    2048
    2059
    2051
    2060
    2049
    2060
    2049
    2061
    2050
    2059
    2051
    2060
    2049
    2059
    2050
    2059
    2051
    2059
    2049
    2059
    2050
    2059
    2050
    2059
    2049
    2057
    2049
    2059
    2049
    2059
    2050
    2058
    2050
    2061
    2050
    2059
    2050
    2058
    2051
    2060
    2052
    2061
    2050
    2060
    2050
    2059
    2051
    2059
    2050
    2058
    2049
    2059
    2049
    2059
    2050
    2059
    2050
    2058
    2050
    2057
    2050
    2058
    2052
    2058
    2051
    2059
    2050
    2059
    2051
    2059
    2051
    2061
    2050
    2060
    2050
    2059
    2051
    2059
    2050
    2059
    2051
    2060
    2051
    2058
    2050
    2059
    2050
    2058
    2051
    2058
    2049
    2060
    2050
    2059
    2051
    2059
    2049
    2058
    2050
    2059
    2050
    2061
    2051
    2060
    2051
    2061
    2050
    2058
    2050
    2059
    2049
    2058
    2049
    2059
    2049
    2060
    2050
    2060
    2051
    2059
    2049
    2059
    2050
    2059
    2049
    2060
    2049
    2060
    2049
    2058
    2050
    2059
    2049
    2059
    2051
    2059
    2050
    2061
    2050
    2060
    2050
    2060
    2050
    2060
    2049
    2061
    2050
    2060
    2051
    2059
    2052
    2059
    2049
    2058
    2050
    2059
    2050
    2059
    2050
    2059
    2050
    2058
    2050
    2059
    2049
    2059
    2049
    2058
    2050
    2060
    2050
    2058
    2049
    2057
    2049
    2058
    2049
    2060
    2051
    2059
    2052
    2059
    2050
    2058
    2050
    2060
    2050
    2059
    2050
    2060
    2048
    2058
    2048
    2060
    2049
    2058
    2050
    2059
    2051
    2058
    2050
    2060
    2049
    2058
    2049
    2060
    2051
    2058
    2049
    2059
    2049
    2059
    2049
    2060
    2051
    2059
    2048
    2060
    2050
    2059
    2049
    2061
    2051
    2060
    2050
    2059
    2050
    2060
    2050
    2059
    2051
    2059
    2052
    2058
    2051
    2059
    2049
    2059
    2050
    2059
    2048
    2060
    2049
    2059
    2049
    2059
    2050
    2058
    2051
    2059
    2051
    2059
    2051
    2059
    2049
    2058
    2051
    2058
    2051
    2059
    2051
    2058
    2049
    2059
    2050
    2058
    2051
    2059
    2051
    2058
    2050
    2059
    2049
    2058
    2050
    2059
    2049
    2058
    2049
    2058
    2049
    2058
    2052
    2059
    2050
    2059
    2050
    2059
    2050
    2059
    2051
    2058
    2048
    2059
    2050
    2058
    2050
    2059
    2050
    2058
    2051
    2059
    2050
    2059
    2048
    2060
    2050
    2059
    2050
    2059
    2050
    2060
    2048
    2059
    2052
    2058
    2050
    2059
    2051
    2058
    2051
    2059
    2050
    2057
    2050
    2060
    2049
    2059
    2050
    2058
    2051
    2059
    2051
    2057
    2052
    2059
    2050
    2059
    2051
    2058
    2051
    2059
    2051
    2060
    2050
    2059
    2051
    2059
    2050
    2059
    2052
    2059
    2051
    2058
    2050
    2058
    2051
    2059
    2050
    2059
    2050
    2058
    2050
    2058
    2050
    2057
    2051
    2059
    2051
    2059
    2051
    2059
    2050
    2059
    2049
    2057
    2049
    2059
    2051
    2059
    2050
    2059
    2051
    2058
    2050
    2059
    2052
    2059
    2051
    2059
    2050
    2059
    2050
    2059
    2051
    2058
    2051
    2059
    2050
    2058
    2049
    2058
    2051
    2059
    2051
    2059
    2052
    2059
    2049
    2059
    2049
    2059
    2050
    2059
    2050
    2059
    2052
    2059
    2052
    2059
    2050
    2060
    2051
    2059
    2050
    2058
    2050
    2057
    2050
    2059
    2051
    2059
    2048
    2059
    2050
    2059
    2048
    2057
    2051
    2058
    2050
    2059
    2050
    2059
    2049
    2059
    2050
    2058
    2050
    2059
    2049
    2059
    2048
    2059
    2051
    2059
    2050
    2059
    2049
    2060
    2050
    2058
    2050
    2059
    2051
    2059
    2050
    2059
    2052
    2060
    2050
    2057
    2049
    2058
    2051
    2059
    2051
    2060
    2050
    2058
    2050
    2061
    2050
    2059
    2049
    2060
    2050
    2059
    2050
    2059
    2050
    2059
    2051
    2060
    2050
    2059
    2050
    2059
    2051
    2060
    2050
    2058
    2051
    2058
    2051
    2059
    2050
    2058
    2049
    2058
    2050
    2058
    2051
    2060
    2051
    2060
    2051
    2059
    2050
    2060
    2050
    2058
    2051
    2059
    2049
    2058
    2050
    2059
    2050
    2059
    2050
    2057
    2051
    2059
    2051
    2059
    2051
    2060
    2049
    2060
    2049
    2059
    2051
    2060
    2051
    2059
    2051
    2059
    2050
    2057
    2050
    2059
    2052
    2059
    2051
    2058
    2049
    2058
    2049
    2059
    2050
    2059
    2050
    2059
    2049
    2059
    2050
    2060
    2051
    2059
    2050
    2059
    2052
    2059
    2050
    2058
    2050
    2057
    2051
    2059
    2049
    2058
    2049
    2059
    2050
    2060
    2050
    2059
    2050
    2058
    2050
    2057
    2049
    2059
    2050
    2058
    2051
    2058
    2049
    2058
    2049
    2060
    2050
    2060
    2050
    2058
    2050
    2058
    2050
    2059
    2050
    2058
    2050
    2060
    2051
    2058
    2050
    2058
    2051
    2060
    2050
    2060
    2050
    2060
    2050
    2059
    2049
    2059
    2049
    2060
    2051
    2060
    2050
    2060
    2051
    2060
    2050
    2058
    2049
    2060
    2049
    2059
    2050
    2060
    2050
    2058
    2049
    2059
    2049
    2060
    2050
    2059
    2051
    2059
    2051
    2058
    2050
    2059
    2052
    2059
    2050
    2059
    2050
    2060
    2050
    2059
    2050
    2060
    2050
    2061
    2050
    2059
    2050
    2059
    2049
    2059
    2050
    2059
    2050
    2058
    2050
    2059
    2050
    2059
    2051
    2060
    2050
    2059
    2048
    2059
    2049
    2059
    2048
    2058
    2049
    2057
    2050
    2060
    2049
    2058
    2048
    2059
    2050
    2058
    2050
    2059
    2050
    2060
    2049
    2058
    2050
    2059
    2049
    2058
    2050
    2058
    2049
    2059
    2050
    2058
    2050
    2060
    2050
    2059
    2048
    2061
    2050
    2059
    2050
    2060
    2050
    2060
    2048
    2060
    2049
    2059
    2049
    2059
    2050
    2059
    2048
    2059
    2050
    2058
    2049
    2058
    2050
    2059
    2050
    2060
    2050
    2057
    2050
    2060
    2049
    2059
    2049
    2059
    2050
    2060
    2048
    2059
    2049
    2060
    2048
    2059
    2049
    2060
    2050
    2060
    2049
    2058
    2051
    2060
    2049
    2058
    2049
    2059
    2051
    2059
    2049
    2059
    2050
    

  • Hi,

    The "-i" is the identify command which would only blink the LED of your ADALM2000.
    The structure of a command is the following:

    m2kcli analog-in ip:x.x.x.x -c channel=1 buffer_size=1024 raw=0

    The above command is used for continuous samples capturing as stated in the documentation: Command line utility — System Level Documentation documentation .

    The URI is the only thing that needs changing. If you are running this on target you can use one of the following: ip:localhost or ip:127.0.0.1 or local: 

    -Alexandra

  • Dear Alexandra, these commands worked fine in ADALM2000.

    m2kcli analog-in ip:localhost -C

    m2kcli analog-in ip:localhost --get all

    m2kcli analog-in ip:localhost --get-channel channel=0,1 all

    m2kcli analog-in ip:localhost --set sampling_frequency=100000000 trigger_source=channel_1 trigger_delay=10

    m2kcli analog-in ip:localhost --set-channel channel=0 range=high trigger_mode=analog trigger_condition=rising_edge trigger_level=0.1 trigger_hysteresis=0.01

    m2kcli analog-in ip:localhost -c channel=0 buffer_size=1024 nb_samples=1024 raw=0

    m2kcli analog-in ip:localhost --capture channel=0 buffer_size=1024 nb_samples=1024 raw=0 format=binary > file.bin

    Thanks!