# External clock oscillator and MCU

I am creating this post as a second part to a recent post I have made: STM32F446 & External Oscillator

I have read other post about using a crystal that runs at 8 MHz rather than 25 MHz. Such as posts like this: Rectifying failed MCU crystal oscillator design

Could someone explain to me why is it preferable to use an 8 MHz crystal rather 25 Mhz? My project's sampling frequency is 44.1 kHz using I2S for the CODEC-MCU comms, I thought that having a 25 Mhz external clock would be fast enough to sample the signal by the guitar.

EDIT: How do you calculate the crystal frequency needed to hit the sampling frequency 44.1 kHz using I2S.

• Reading the other question and your comments there it sounds to me like what you actually want to know is how to calculate the crystal frequency needed to hit the sampling rate you want to use. Is that right? Apr 8, 2021 at 4:31
• To favour low frequency/speed PCB designing. Apr 8, 2021 at 7:53
• @user1850479 Correct, aside from finding a compatible crystal for the STM32 i want to also understand what would be an optimal frequency the crystal should run at in order to have a minute error % Apr 8, 2021 at 15:21
• @dcm Should edit your question to ask that, or maybe ask a new question. Briefly, you would look at the datasheet for your ADC/DAC to see what clock frequency it needs for your sampling rate. Then you would take that number and look at what frequencies your PLL can generate, and then calculate what input frequency the PLL needs to generate the correct output frequency. Finally you would buy a crystal matching that requirement. Apr 8, 2021 at 16:11
• @user1850479 So, the CODEC would be set to a sampling rate of at least 88.2 (to achieve the 44.1 kHz range based of Nyquist). Then, looking at the PLLSAI characteristics: PLLSAI input clock min: 0.95, max: 2.10 MHz & PLLSAI multiplier output clock max: 216 MHz. There's a note regarding the PLLSAI input clock: "Take care of using the appropriate division factor M to have the specified PLL input clock values". So if I want to use an 8 MHz crystal, then M = 8. PLLSAI input clk = 1 MHz, then if I want the sysclk to run at 180 MHz I would multiply 1 MHz * 180? Apr 8, 2021 at 17:13

The 8MHz crystal uses less power and is easier to route traces for since you aren't dealing with the faster rise/fall times required for higher frequency signals. The PLL in the MCU can then step up the 8MHz to whatever frequency you actually need.

You need very exacting frequencies for some applications though where getting close woth the PLL is not enough and it needs to be an integer multiple so can be cleanly divided down.

Using a 25 MHz crystal will gain nothing while it makes things just more complex. And there is an application note which says that if you use the internal bootloader for CAN or USB, user must use low frequency values than high for the bootloader to autodetect the frequency more reliably.

The MCU has a PLL so if you want to run the MCU at 180 MHz via the PLL, or generate a master audio clock with one of the audio PLLs, the clock will have to be divided down to 1 MHz anyway before it is input to the PLL, so regarding the MCU speed or audio frequency, it does not matter frequency-wise if the crystal frequency is 8 MHz or 25 MHz.

So because either frequency ends up being fed to PLL, it does not matter which one of the two is used. You can reach 44.1 kHz sampling rate that has no error larger than 0.04% just as well with any clock that is multiple of 1 MHz.

But for the oscillator that runs the crystal, is easier to find and select a crystal that satisfies all parameters that the MCU oscillator hardware circuit requires. Almost any 8 MHz crystal is suitable, as it allows for larger ESR for example, so the crystal oscillator will start up and run more stably. Finding a 25 MHz crystal with low enough ESR and load capacitance rating to allow good gain margin is much much more difficult, and there are far fewer places from where to buy them, if they even stock it.

If you need to hit 44100 Hz more precisely for some reason, then you should consider a crystal which can provide the required clock via PLL or simply use another oscillator just for the audio master clock to get the exact rate.