afiskon / stm32-si5351

HAL-based Si5351 driver for STM32
https://eax.me/stm32-si5351/
MIT License
48 stars 13 forks source link

Fix Fclk instead of Fxtal #2

Closed tkuschel closed 2 years ago

tkuschel commented 2 years ago

Unfortunately I copy/pasted the wrong line, there should be Fclk instead of Fxtal in line 259. Sorry my fault. I didn't go through the code at line 278 upto 281; there is a similar calculation, but with Fxtal - is this okay there?

    // Valid for Fclk in 75..160 MHz range
    if(Fclk >= 150000000) {
        x = 4;
    } else if (Fclk >= 100000000) {
        x = 6;
    } else {
        x = 8;
    }
    y = 0;
    z = 1;

    int32_t numerator = xFclk;  // <<----
    a = numerator/Fxtal;  // <<--- Fclk ???
    t = (Fxtal >> 20) + 1;  // <<--- Fclk ???
    b = (numerator % Fxtal) / t;  // <<--- Fclk ???
    c = Fxtal / t;  // <<--- Fclk ???
afiskon commented 2 years ago

Thanks, fixed.

Yes, it should be Fxtal in the else branch. The idea of the algorithms is that for frequencies < 81 Mhz we say that PLL runs @ 900 Mhz. This gives us N = a + b / c, and knowing N we can calculate M = x + y / z. For frequencies > 81 Mhz we do the opposite, choose M and then calculate N. Here is an article that gives a little more details https://eax.me/stm32-si5351/ It's in Russian, but Google Translate should be able to translate it. Also it contains a block diagram that should clarify the meaning of N and M:

img

afiskon commented 2 years ago

Also here you will find the scripts that verify the algorithm: https://github.com/afiskon/stm32-si5351/tree/main/tests

tkuschel commented 2 years ago

For a project, I need a frequency of 3.5 MHz up to 4.0 MHz and I want to take into account that the output signal has as less jitter (see datasheet using only even integer multisynth). So I will do the generation between those frequencies like

/* 80-m-Band 3.5 -- 4.0 MHz */
if ( (frequency >= _80M_BAND_MIN) && (frequency <= _80M_BAND_MAX)) {
    x = _80M_BAND_X;    // 200u
    y = 0;
    z = 1;
    a = (_80M_BAND_X * frequency)/xtal;
    // t = (xtal >> 20) + 1;
    t = xtal / 1000000; // even divider and exactly 1 Hz grid
    b = (_80M_BAND_X * frequency)%xtal;
    b /= t;
    c = xtal/t;
    }

Instead of a crystal, a TCXO will be added to the circuit later. 15 years ago I studied Russian language (intensive 14 days course with native speakers in Vienna, only without any German or English words spoken - only pure Russian), but have already forgotten any vocabulary. However, I can still read the Cyrillic script and even realize the written script. Спасибо за информацию, Фома (they called me Фома instead of Thomas or Tomas); I will study your given links later.