 higher the decimation rate, the lower the effective sample rate for a given resolution (bit depth).
The integration rate is the number of times the output is oversampled. The effective sample rate and resolution are affected by the integration rate in the same manner as the decimation rate: higher integration rates will decrease the sample rate, but increase the resolution.
To determine the effective output sample rate, the frequency of the clock is divided by the product of the decimation and integration rates:
For example, if a 48kHz output sample rate (fo) is required, a clock of 3,072,000Hz could be driven to the CLK input pin (fCLK), and the filter could be configured with a decimation rate (dOSR) of 32 and an integration rate (iOSR) of 2.
Since CLK is not configured by the API, and may be coming from an external source, the sample rate cannot be determined prior to commencing operation. However, once at least one sample has been collected, the effective sample rate can be retrieved via dfsdm.getsampleratehz().
Three additional parameters are provided in the API when configuring dfsdm: the DC offset correction applied to the sample, the clock edge (rising or falling) on which the bit stream is sampled through DATA, and the number of bits by which the resulting sample is shifted right in the output.
When using DFSDM without any of the optional audio processing filters, the signed samples are provided in the least significant 24 bits of a 32-bit word. The effective bit-depth of these samples is determined by the filter parameters passed to dfsdm.configure() by the following relationship:
Where Afs denotes the maximum value that can be sampled by DFSDM, dOSR is the decimation rate, fORD is the filter order and iOSR is the integration rate.
For example, if we choose a fORD = 4, we get a fourth-order filter. The maximum value that can be sampled is calculated by raising the decimation rate dOSR to the power of the filter order, then multiplying by the integration rate iOSR. Let’s say we choose decimation rate 64 and integration rate 1:
The filter parameters should be carefully selected to achieve the desired output bit-depth and sampling frequency.
When using DFSDM for audio applications, in conjunction with the optional audio processing filters, care should be taken to ensure that samples result in a 24-bit value. The ‘audio packing’ filter DFSDM_PACK_AUDIO assumes a 24-bit signed input, and will produce confusing results if this is not the case.
The following table shows how choice of the filter order and decimation rate affect the maximum value that can be sampled:
|dOSR||fORD = 0||fORD = 1||fORD = 2||fORD = 3||fORD = 4||fORD = 5|
The integration parameter iOSR also has an effect on the maximum sample value, and values from the table should be multiplied by iOSR to determine this value. For example, a third-order filter with a decimation rate of 64 and an integration rate of 64 would achieve the following maximum sample value:
Note that the right-shift parameter can be useful when large maximum values are achieved, in order to bring the result back into the range of a 24-bit value. For example, a fifth-order filter with decimation rate 32 and integration rate 2 will produce a maximum value of 67,108,864. By specifying 2 as the right-shift value, after the integration rate has been applied, samples will be divided by 4, resulting in a maximum sample of 16,777,216.
Please note that if you wish to make use of dfsdm, you will not be able to make simultaneous use of spiAHSR, and vice versa. This is due to the way these objects make use of DMA. The imp004m’s spiGJKL is unaffected by this limitation. It is possible to use the two objects within your application, but your code will need to ensure they are not used at the same time.
You cannot call dfsdm.configure() while spiAHSR is configured and enabled, so if you are making use of this SPI bus, you should call spiAHSR.disable() before calling dfsdm.configure(). Equally, if you are using dfsdm and need to then make use of spiAHSR, you will need to call dfsdm.stop() (to send