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]
Parents
  • 0
    •  Analog Employees 
    on Mar 9, 2020 11:27 PM 8 months ago

    Loading the filter files generated from MATLAB will update the sample rate automatically. So you don't need to do this again.

    Also, to achieve certain rates you need to have a certain FIR loaded. It's not clear from your code snippets what you are doing before trying to set sample rate.

    -Travis

  • Hi Travis,

    I am loading the configuration of FIR as above using:

    ret = iio_device_attr_write_raw(dev, "filter_fir_config", buf, len);

    which is successful.

    The issue is that if I comment out rate settings or channel then 

    nbytes_rx = iio_buffer_refill(rxbuf);

    fails with:

    Error refilling buf -110

    This was working fine without filter.

  • fir.txt
    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

    uploaded

  • For some reason ADI Wizard do not allow me to save FIR file, I can only export to Matlab workspace.

  • 0
    •  Analog Employees 
    on Mar 10, 2020 12:04 AM 8 months ago in reply to MichalM

    Did you design TX and RX? Both must be designed before export is possible.

    -Travis

  • This is very good point ! I just wanted RX, but it seems I need both ? Also the example was saying it is better to enable both directions. Let me try it.

  • ad9631_fir.txt
    # Generated with AD9361 Filter Design Wizard 16.1.3
    # MATLAB 9.7.0.1296695 (R2019b) Update 4, 09-Mar-2020 17:12:10
    # Inputs:
    # Data Sample Frequency = 520833 Hz
    TX 3 GAIN 0 INT 4
    RX 3 GAIN -12 DEC 4
    RTX 800000000 25000000 8333333 4166667 2083333 520833
    RRX 800000000 25000000 8333333 4166667 2083333 520833
    BWTX 1253607
    BWRX 434750
    25,115
    -88,-99
    -26,157
    -226,-154
    -252,-24
    -473,-330
    -566,-346
    -744,-620
    -781,-657
    -803,-792
    -669,-693
    -483,-598
    -189,-315
    96,-59
    368,257
    518,440
    547,543
    408,443
    163,239
    -153,-85
    -428,-379
    -602,-605
    -594,-637
    -410,-492
    -76,-156
    304,245
    629,626
    781,831
    706,804
    394,502
    -70,17
    -565,-538
    -927,-971
    -1035,-1147
    -819,-963
    -319,-451
    342,274
    966,988
    1353,1471
    1345,1525
    902,1092
    110,242
    -815,-792
    -1595,-1704
    -1956,-2172
    -1726,-1990
    -896,-1119
    350,250
    1671,1749
    2647,2901
    2907,3276
    2238,2610
    689,932
    -1415,-1411
    -3504,-3791
    -4897,-5440
    -4957,-5629
    -3268,-3869
    237,-64
    5216,5418
    10960,11790
    16526,17992
    20930,22912
    23360,25630
    23360,25630
    20930,22912
    16526,17992
    10960,11790
    5216,5418
    237,-64
    -3268,-3869
    -4957,-5629
    -4897,-5440
    -3504,-3791
    -1415,-1411
    689,932
    2238,2610
    2907,3276
    2647,2901
    1671,1749
    350,250
    -896,-1119
    -1726,-1990
    -1956,-2172
    -1595,-1704
    -815,-792
    110,242
    902,1092
    1345,1525
    1353,1471
    966,988
    342,274
    -319,-451
    -819,-963
    -1035,-1147
    -927,-971
    -565,-538
    -70,17
    394,502
    706,804
    781,831
    629,626
    304,245
    -76,-156
    -410,-492
    -594,-637
    -602,-605
    -428,-379
    -153,-85
    163,239
    408,443
    547,543
    518,440
    368,257
    96,-59
    -189,-315
    -483,-598
    -669,-693
    -803,-792
    -781,-657
    -744,-620
    -566,-346
    -473,-330
    -252,-24
    -226,-154
    -26,157
    -88,-99
    25,115
    
    The TX looks diffrent but I am interested in RX anyway,

Reply
  • ad9631_fir.txt
    # Generated with AD9361 Filter Design Wizard 16.1.3
    # MATLAB 9.7.0.1296695 (R2019b) Update 4, 09-Mar-2020 17:12:10
    # Inputs:
    # Data Sample Frequency = 520833 Hz
    TX 3 GAIN 0 INT 4
    RX 3 GAIN -12 DEC 4
    RTX 800000000 25000000 8333333 4166667 2083333 520833
    RRX 800000000 25000000 8333333 4166667 2083333 520833
    BWTX 1253607
    BWRX 434750
    25,115
    -88,-99
    -26,157
    -226,-154
    -252,-24
    -473,-330
    -566,-346
    -744,-620
    -781,-657
    -803,-792
    -669,-693
    -483,-598
    -189,-315
    96,-59
    368,257
    518,440
    547,543
    408,443
    163,239
    -153,-85
    -428,-379
    -602,-605
    -594,-637
    -410,-492
    -76,-156
    304,245
    629,626
    781,831
    706,804
    394,502
    -70,17
    -565,-538
    -927,-971
    -1035,-1147
    -819,-963
    -319,-451
    342,274
    966,988
    1353,1471
    1345,1525
    902,1092
    110,242
    -815,-792
    -1595,-1704
    -1956,-2172
    -1726,-1990
    -896,-1119
    350,250
    1671,1749
    2647,2901
    2907,3276
    2238,2610
    689,932
    -1415,-1411
    -3504,-3791
    -4897,-5440
    -4957,-5629
    -3268,-3869
    237,-64
    5216,5418
    10960,11790
    16526,17992
    20930,22912
    23360,25630
    23360,25630
    20930,22912
    16526,17992
    10960,11790
    5216,5418
    237,-64
    -3268,-3869
    -4957,-5629
    -4897,-5440
    -3504,-3791
    -1415,-1411
    689,932
    2238,2610
    2907,3276
    2647,2901
    1671,1749
    350,250
    -896,-1119
    -1726,-1990
    -1956,-2172
    -1595,-1704
    -815,-792
    110,242
    902,1092
    1345,1525
    1353,1471
    966,988
    342,274
    -319,-451
    -819,-963
    -1035,-1147
    -927,-971
    -565,-538
    -70,17
    394,502
    706,804
    781,831
    629,626
    304,245
    -76,-156
    -410,-492
    -594,-637
    -602,-605
    -428,-379
    -153,-85
    163,239
    408,443
    547,543
    518,440
    368,257
    96,-59
    -189,-315
    -483,-598
    -669,-693
    -803,-792
    -781,-657
    -744,-620
    -566,-346
    -473,-330
    -252,-24
    -226,-154
    -26,157
    -88,-99
    25,115
    
    The TX looks diffrent but I am interested in RX anyway,

Children
No Data