analogdevicesinc / ad936x-filter-wizard

MATLAB-based FIR filter design
Other
51 stars 40 forks source link

Catching errors in writeAttributeString #13

Closed darenlee closed 6 years ago

darenlee commented 8 years ago

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.

tfcollins commented 6 years ago

Moved to https://github.com/analogdevicesinc/libiio-matlab/issues/3. That code lives there.