Post Go back to editing

Error -22 writing to channel "sampling_frequency" value may not be supported.

Hello,

I have used two examples https://github.com/analogdevicesinc/libad9361-iio/blob/master/ad9361_baseband_auto_rate.c and https://github.com/analogdevicesinc/libiio/blob/master/examples/ad9361-iiostream.c to load custom FIR and get samples with lowest sampling rate. My FIR config with taps from Matlab ADI Wizard is:

RX 3 GAIN -12 DEC 4 TX 3 GAIN -12 INT 4 RRX 800000000 25000000 8333333 4166666 2083333 520833 RTX 800000000 25000000 8333333 4166666 2083333 520833 BWRX 433256 BWTX 433256 114,114 -98,-98 157,157 -154,-154 -23,-23 -330,-330 -346,-346 -619,-619 -656,-656 -791,-791 -692,-692 -598,-598 -315,-315 -59,-59 257,257 440,440 542,542 443,443 239,239 -85,-85 -378,-378 -605,-605 -637,-637 -491,-491 -156,-156 245,245 625,625 830,830 803,803 502,502 17,17 -538,-538 -971,-971 -1147,-1147 -962,-962 -451,-451 273,273 987,987 1470,1470 1525,1525 1092,1092 241,241 -792,-792 -1704,-1704 -2172,-2172 -1990,-1990 -1118,-1118 250,250 1749,1749 2901,2901 3276,3276 2610,2610 932,932 -1410,-1410 -3790,-3790 -5440,-5440 -5628,-5628 -3869,-3869 -64,-64 5417,5417 11790,11790 17991,17991 22911,22911 25630,25630 25630,25630 22911,22911 17991,17991 11790,11790 5417,5417 -64,-64 -3869,-3869 -5628,-5628 -5440,-5440 -3790,-3790 -1410,-1410 932,932 2610,2610 3276,3276 2901,2901 1749,1749 250,250 -1118,-1118 -1990,-1990 -2172,-2172 -1704,-1704 -792,-792 241,241 1092,1092 1525,1525 1470,1470 987,987 273,273 -451,-451 -962,-962 -1147,-1147 -971,-971 -538,-538 17,17 502,502 803,803 830,830 625,625 245,245 -156,-156 -491,-491 -637,-637 -605,-605 -378,-378 -85,-85 239,239 443,443 542,542 440,440 257,257 -59,-59 -315,-315 -598,-598 -692,-692 -791,-791 -656,-656 -619,-619 -346,-346 -330,-330 -23,-23 -154,-154 157,157 -98,-98 114,114

The config loads just fine, I can see filter enabled and all settings as expected in:

root@analog:/sys/bus/iio/devices/iio:device2# cat in_voltage_sampling_frequency

520833

BUT: setting channel sampling frequency fails:

ret = iio_channel_attr_write_longlong(chan, "sampling_frequency", rate);

if (ret < 0) { printf("* Can't write sampling frequency: %d.\n", ret); return ret;

}

results in:

* Can't write sampling frequency: -22.

or:

// Configure phy and lo channels printf("* Acquiring AD9361 phy channel %d\n", chid);

if (!get_phy_chan(ctx, type, chid, &chn)) { return false; }

wr_ch_str(chn, "rf_port_select", cfg->rfport);

wr_ch_lli(chn, "rf_bandwidth", cfg->bw_hz);

wr_ch_lli(chn, "sampling_frequency", cfg->fs_hz);

in:

Error -22 writing to channel "sampling_frequency" value may not be supported.

What I am missing ?  Thanks !



Added second code example.
[edited by: MichalM at 11:02 PM (GMT 0) on 9 Mar 2020]
  • The first filter file was invalid, but the second one worked. Data streamed fine out of IIO-Scope when loaded.

    My guess is that you are running into a rounding problem since technically the part only supports rates down to 520833.33333333... and the attribute input only accepts ints. For example, 5208334 should work fine.

    However, if you want 520833.333 you have to use a filter file since these are interpreted as ratios in the driver and not actual values.

    -Travis

  • Hi Travis, 

    I think you absolutely right, setting sampling_frequenct below lowest value could not work. So I decided to change to to more "rounded" value of 600ksps. I generated FIR config with wizard (attached) and then uploaded programmatically to the filter using ret = iio_device_attr_write_raw(dev, "filter_fir_config", buf, len);

    The I enable FIR  configuration and sampling of 600ksps. This seems to be working fine. 

    Then I read configuration with  iio_device_attr_read(get_ad9361_phy(ctx), NULL, (char *)&cfg, 10240); and sampling rate is 599999 ? BBPLL:921599992 ADC:28799999 R2:9599999 R1:4799999 RF:2399999 RXSAMP:599999. Why there is a change comparing to original FIR config ? 

    Still this is fine, but when I want to pull samples with: nbytes_rx = iio_buffer_refill(rxbuf); I am getting error -110 and case closed. Shall I open separate thread for this problem ?

    Thanks

  • Why there is a change comparing to original FIR config ?

    This likely rounding the driver does. I believe it always rounds down (and MATLAB doesn't do that).

    Shall I open separate thread for this problem ?

    Yes, please do. If you could include more code around the buffer creation that would be helpful.

    -Travis

  • Ok, I took 599998 as sampling frequency from FIR settings, I can set it just fine. I opened new thread for error -110 on filling buffers.