Skip to main content

dfsdm.configure(filterOrder, decimationRate, integrationRate, offset, rightShift, samplingEdge, bufferArray, callback, preprocessors)

Configures the imp004m for sampling

Availability

Device (from impOS™ 38)
Available on the imp004m only

Parameters

Name Type Description
filterOrder Integer The filter order between 0 and 5, where a value of 0 represents a ‘fast’ second-order filter, and values between 1 and 5 represent the corresponding filter order
decimationRate Integer The decimation rate between 0 and 1023, where 0 bypasses the filter entirely, and values between 1 and 1023 represent the decimation rate minus 1. For example, a decimation rate of 32 is achieved by passing the value 31
integrationRate Integer The integration rate between 0 and 255, where 0 bypasses the integrator, and values between 1 and 255 represent the integration rate minus 1. For example, an integration rate of 256 is achieved by passing the value 255
offset Integer The DC offset correction that will be applied to the 24-bit sample. This is a signed number between -8388607 and +8388607. The value will be added to each output sample
rightShift Integer The number of bits by which the output will be shifted right between 0 and 24. For example, a value of 4 will discard the least significant four bits and shift the remaining bits right by four places
samplingEdge String The CLK pin edge (rising or falling) on which the DATA pin is sampled, either "RISING-EDGE" or "FALLING-EDGE". An empty string ("") is equivalent to "RISING-EDGE"
bufferArray Array An array of blobs (up to eight), each a buffer for sampled data. The size of each blob must be a multiple of four bytes
callback Function A function to be called when a sample buffer is full
preprocessors Constant Optional pre-processing filters

Returns

Nothing

Description

This method configures the imp004m’s dfsdm object in preparation for sampling.

Since the DFSDM clock may be provided externally, it is not configured by this method. If you are using a sigma delta modulator that requires a clock input, a PWM-capable imp pin can be configured as a clock and routed to both the SDM peripheral and the DFSDM CLK pin (pin R).

The Callback

The callback passed into to dfsdm.configure() is called automatically by the dfsdm object when there is a filled or partially-filled buffer of data to be processed. The callback has two parameters: the first, sampleBuffer, is a blob containing the sampled data. The second parameter, byteCount, indicates how much data the buffer contains, ie. whether the buffer is full or not.

Buffers and Over-runs

While a buffer is being processed by the callback, it can’t be used by the dfsdm. An over-run can therefore occur when the processing of a buffer within the callback code takes longer than the dfsdm takes to fill the next buffer and there are no other buffers available to fill.

For example, there are three buffers in the buffer array and buffers 0 and 1 have been filled and passed to the callback. Buffer 0 is being processed, and buffer 1 is queued for processing. If, when buffer 2 is full, the processing of buffer 0 has not yet been completed, dfsdm has no buffer free for the incoming data — an over-run has taken place.

When this occurs, the callback is executed with its sampleBuffer parameter set to null and byteCount to 0. These values can thus be used by your code to determine that an over-run has taken place.

Pre-processing filters

A number of pre-processing filters can be used to format the dfsdm output data into the same data format as the sampler outputs, normalize the samples, and perform A-Law compression.

Constant Value Description
NORMALISE 1 Normalize the data, using an infinite impulse response method with a window size of 256 samples
A_LAW_COMPRESS 2 Compress the data from 16-bit to 8-bit, using A-Law compression
DFSDM_PACK_AUDIO 4 Convert the samples from unsigned 24-bit to unsigned 16-bit, and pack them into 32-bit words (to match the sampler unprocessed output)

If you select either NORMALISE or A_LAW_COMPRESS, then DFSDM_PACK_AUDIO will also be used — it is implemented automatically by impOS. If you select A_LAW_COMPRESS, at least four buffers must be provided to avoid over-runs. If you select DFSDM_PACK_AUDIO alone, at least three buffers must be provided.

The format of the data provided to the callback, depends on the pre-processing filters used:

Pre-processing Filter Output Data Type
DFSDM_PACK_AUDIO Unsigned 16-bit, little endian, with two samples packed into each 32-bit word
NORMALISE Signed 16-bit, little endian
A_LAW_COMPRESS Signed 8-bit
None Unsigned 24-bit, little endian in 32-bit words with the data in the least significant bits

DFDSM and SPI

If you wish to make use of dfsdm, you will not be able to make simultaneous use of the imp004m’s spiAHSR, and vice versa. This is due to the way these objects make use of DMA. 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().