Re: [PATCH v8 10/11] iio: adc: ad7768-1: add filter type and oversampling ratio attributes
From: Andy Shevchenko
Date: Fri May 16 2025 - 05:36:00 EST
On Thu, May 15, 2025 at 06:14:21PM -0300, Jonathan Santos wrote:
> Separate filter type and decimation rate from the sampling frequency
> attribute. The new filter type attribute enables sinc3, sinc3+rej60
> and wideband filters, which were previously unavailable.
>
> Previously, combining decimation and MCLK divider in the sampling
> frequency obscured performance trade-offs. Lower MCLK divider
> settings increase power usage, while lower decimation rates reduce
> precision by decreasing averaging. By creating an oversampling
> attribute, which controls the decimation, users gain finer control
> over performance.
>
> The addition of those attributes allows a wider range of sampling
> frequencies and more access to the device features. Sampling frequency
> table is updated after every digital filter parameter change.
>
> Changes in the sampling frequency are not allowed anymore while in
> buffered mode.
...
> + /*
> + * Maximum dec_rate is limited by the MCLK_DIV value and by the ODR.
> + * The edge case is for MCLK_DIV = 2, ODR = 50 SPS.
> + * max_dec_rate <= MCLK / (2 * 50)
> + */
> + max_dec_rate = st->mclk_freq / 100;
> + dec_rate = clamp(dec_rate, 32, max_dec_rate);
> + /*
> + * Calculate the equivalent value to sinc3 decimation ratio
> + * to be written on the SINC3_DEC_RATE register:
> + * Value = (DEC_RATE / 32) -1
- 1
(mind the space)
> + */
> + dec_rate = DIV_ROUND_UP(dec_rate, 32) - 1;
...
> {
> struct ad7768_state *st = iio_priv(indio_dev);
>
> - return st->dec_rate == 8 ? AD7768_SCAN_TYPE_HIGH_SPEED :
> + return st->oversampling_ratio == 8 ? AD7768_SCAN_TYPE_HIGH_SPEED :
> AD7768_SCAN_TYPE_NORMAL;
With the proposed change in the previous patches this change will become
clearer to read, i.e. no-one needs to check if the actual value was changed.
> }
--
With Best Regards,
Andy Shevchenko