analogdevicesinc / libiio-matlab

MATLAB bindings for libiio
Other
13 stars 25 forks source link

Catching errors in writeAttributeString (From FilterWizard) #3

Open tfcollins opened 6 years ago

tfcollins commented 6 years ago

This issue was originally reported here: https://github.com/analogdevicesinc/ad936x-filter-wizard/issues/13

Currently libiio_if.m does not catch errors when writing to channel and device attributes. Enabling these error checks can actually catch errors that the Filter Wizard does not detect unless you examine kernel messages using dmesg.

Example:

      % Write the attribute
            if(ret > 0)
                status = calllib(obj.libname, 'iio_channel_attr_write', ch, attr, str);
                if status<0
                    err_msg = sprintf('Could not write attribute: %s \n',  attr);
                    error(err_msg);
                end
                clear ch;
                clear attr;
            else
                status = calllib(obj.libname, 'iio_device_attr_write', obj.iio_dev, attr_name, str);
                if status<0
                    err_msg = sprintf('Could not write attribute %s with value %s \n', attr_name, str);
                    error(err_msg);
                end
            end
        end

With the above modifications, try designing a filter with a sample-rate lower than 2.4 MHz. In my example I tried 540 Khz (0.54 in the text field). An error will appear both in the MATLAB prompt about not being able to write filter settings. In dmesg:

 [  174.028208] ad9361 spi32766.0: ad9361_calculate_rf_clock_chain: Failed to find suitable dividers: ADC clock below limit

This happens on a fresh boot. However, if you change to a higher frequency such as 2.4 MHz it works fine, then after that, try 540 KHz again, and it will accept that sample-rate. It seems on a fresh-boot if you try to immediately set a "lower" sample-rate we run into this error.