cancel
Showing results for 
Search instead for 
Did you mean: 

Calculating CLK dividers for MEMS microphones, SAI implemented through BSP for correct input audio

ALiss
Associate II

Hello,

I am using the BSP resources (stm32746g_discovery_audio) in order to get input audio from the MEMS digital microphones. The ingoing audio quality is good but it sounds like the signal itself is pitch-raised. Voices speaking sound like chipmunks. I have gathered that the audio input from SAI is dependent on dividing the clock frequency correctly, but I'm having a hard time finding resources for how to calculate the divisions. With ADC, the calculations are simpler with the sampling frequency relating to system clock frequency divided by periodlength.

How should I calculcate the clock division for SAI? My system clock frequency is 216MHz and target sampling frequency is 44.1kHz.

Thank you,

1 REPLY 1
Eleon BORLINI
ST Employee

Hi @ALiss​ , this clock configuration is not so simple and, in general, it depends from 2 factors: the PLL setting, which generates the clock used as input for the SAI; and the SAI setting itself. The clock tree steps are: from the system clock (or from an external source), the PLL generates the SAI input clock (usually around some tenth MHz) which is then divided from the SAI itself, depending on its own configuration (the detailed procedure depends on the specific SAI). In addition, for the digital mics the SAI or I2S peripheral is not used in a standard way, but only for the bit clock generation and the bit stream acquisition (without the word clock line, the mclk, etc...).

So you have to find a proper SAI bit clock frequency that fits the microphone needs. For example, 44.1kHz, with a 64x decimation means you have to generate a clock of 2.822.400 Hz. To implement this requirement you can set, for example, the SAI for a 2-channel acquisition in 32 bits at 44.1kHz, supposing the PLL well-configured.

To summarize, you have to use the CubeMX tool: you can graphically set the clock tree, you can manually tune the decimation factor settings, and you can set the SAI and generate the configuration code, being aware that, as explained before, the SAI peripheral is not used in a standard way for MEMS PDM digital mics.

Regards