2017-09-11 07:49 AM
Hello!
I have external oscillator with frequency 384 MHz. I want to sample MEMSPDM microphone with 512 kHz frequency and get 16 kHz audio with oversampling ratio.
Here is my initialization:
__HAL_DFSDM_CHANNEL_RESET_HANDLE_STATE(&DfsdmLeftChannelHandle);
DfsdmLeftChannelHandle.Instance = DFSDM1_Channel2;
DfsdmLeftChannelHandle.Init.OutputClock.Activation = ENABLE;
DfsdmLeftChannelHandle.Init.OutputClock.Selection = DFSDM_CHANNEL_OUTPUT_CLOCK_AUDIO;
DfsdmLeftChannelHandle.Init.OutputClock.Divider = 32; /* 384MHz/32 = 512 kHz */
DfsdmLeftChannelHandle.Init.Input.Multiplexer = DFSDM_CHANNEL_EXTERNAL_INPUTS;
DfsdmLeftChannelHandle.Init.Input.DataPacking = DFSDM_CHANNEL_STANDARD_MODE; /* N.U. */
DfsdmLeftChannelHandle.Init.Input.Pins = DFSDM_CHANNEL_SAME_CHANNEL_PINS;
DfsdmLeftChannelHandle.Init.SerialInterface.Type = DFSDM_CHANNEL_SPI_FALLING;
DfsdmLeftChannelHandle.Init.SerialInterface.SpiClock = DFSDM_CHANNEL_SPI_CLOCK_INTERNAL;
DfsdmLeftChannelHandle.Init.Awd.FilterOrder = DFSDM_CHANNEL_FASTSINC_ORDER; /* N.U. */
DfsdmLeftChannelHandle.Init.Awd.Oversampling = 10; /* N.U. */
DfsdmLeftChannelHandle.Init.Offset = 0;
DfsdmLeftChannelHandle.Init.RightBitShift = 2;
if(HAL_OK != HAL_DFSDM_ChannelInit(&DfsdmLeftChannelHandle))
{
while( 1 );
}
/* Initialize filter 0 (left channel) */
__HAL_DFSDM_FILTER_RESET_HANDLE_STATE(&DfsdmLeftFilterHandle);
DfsdmLeftFilterHandle.Instance = DFSDM1_Filter0;
DfsdmLeftFilterHandle.Init.RegularParam.Trigger = DFSDM_FILTER_SW_TRIGGER;
DfsdmLeftFilterHandle.Init.RegularParam.FastMode = ENABLE;
DfsdmLeftFilterHandle.Init.RegularParam.DmaMode = ENABLE;
DfsdmLeftFilterHandle.Init.InjectedParam.Trigger = DFSDM_FILTER_SW_TRIGGER; /* N.U. */
DfsdmLeftFilterHandle.Init.InjectedParam.ScanMode = ENABLE; /* N.U. */
DfsdmLeftFilterHandle.Init.InjectedParam.DmaMode = DISABLE; /* N.U. */
DfsdmLeftFilterHandle.Init.InjectedParam.ExtTrigger = DFSDM_FILTER_EXT_TRIG_TIM1_TRGO; /* N.U. */
DfsdmLeftFilterHandle.Init.InjectedParam.ExtTriggerEdge = DFSDM_FILTER_EXT_TRIG_RISING_EDGE; /* N.U. */
DfsdmLeftFilterHandle.Init.FilterParam.SincOrder = DFSDM_FILTER_SINC3_ORDER;
DfsdmLeftFilterHandle.Init.FilterParam.Oversampling = 32; /* 384MHz/32/32 = 16 kHz */
DfsdmLeftFilterHandle.Init.FilterParam.IntOversampling = 1;
if(HAL_OK != HAL_DFSDM_FilterInit(&DfsdmLeftFilterHandle))
{
while( 1 );
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
But every conversion I receive buffer full of numbers '-2097152'. If I change parameter 'DfsdmLeftChannelHandle.Init.OutputClock.Divider' to 4 and 'DfsdmLeftFilterHandle.Init.FilterParam.Oversampling' to 256, my buffer is full of different values, so it's ok. I'm very bad in digital filtering, so my question may be stupid. But why I can't use oversampling 32 in my situation and what parameters should I change to make my filter work?
#dfsdm #filter #digital-filter2017-11-08 03:02 AM
Hello,
Generally PDM digital MEMES microphones output data when given a clock with a frequency between 1 MHz and 3.25 MHz.If the clock frequency is below 1 MHz the microphone will be in sleep mode and won't output data.So to get a 16 Khz audio you need to set the DFSDM output clock divider to 16 and the DFSDM filter oversampling ratio to 64.