Skip to content

Added spread spectrum parameter calculation and setting #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added spread spectrum parameter calculation and setting
Fixed PLL reset (it was not working without some magic undocumented value)
  • Loading branch information
paolo-sz committed Jan 11, 2018
commit a7c21a6cc8442eda24440afb5d7c9c6bb500298d
83 changes: 81 additions & 2 deletions src/si5351.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,75 @@ void Si5351::set_pll(uint64_t pll_freq, enum si5351_pll target_pll)
pllb_freq = pll_freq;
}

// write the correct spread spectrum parameters in case that feature is enabled by physical pin
if(target_pll == SI5351_PLLA)
{
i = 0;

uint16_t ssudp = (uint16_t)((uint32_t)xtal_freq[(uint8_t)plla_ref_osc] / (4ULL * 31500ULL));
uint64_t ssud = ((uint64_t)32768 * (uint64_t)128 * (((uint64_t)pll_reg.a * (uint64_t)pll_reg.c) + (uint64_t)pll_reg.b) * (uint64_t)SI5351_SSCAMP_x1000) / (((uint64_t)1000 - (uint64_t)SI5351_SSCAMP_x1000) * (uint64_t)ssudp * (uint64_t)pll_reg.c);
uint16_t ssud_p1 = (uint16_t)((ssud >> 15) & 0x0fff);
uint16_t ssud_p2 = (uint16_t)((ssud >> 0) & 0x3fff);
uint16_t ssud_p3 = 0x7fff;

// Registers 149
// use "0x80 | ..." in order to enable the spread spectrum feature
// enable is the OR between bit 7 and physical pin
temp = (uint8_t)(0x00 | ((ssud_p2 >> 8) & 0x7f));
params[i++] = temp;

// Registers 150
temp = (uint8_t)(ssud_p2 & 0xFF);
params[i++] = temp;

// Register 151
temp = (uint8_t)(0x80 | ((ssud_p3 >> 8) & 0x7f));
params[i++] = temp;

// Registers 152
temp = (uint8_t)(ssud_p3 & 0xFF);
params[i++] = temp;

// Registers 153
temp = (uint8_t)(ssud_p1 & 0xFF);
params[i++] = temp;

// Register 154
temp = (uint8_t)((ssudp >> 4) & 0xF0);
temp += (uint8_t)((ssud_p1 >> 8) & 0x0F);
params[i++] = temp;

// Registers 155
temp = (uint8_t)(ssudp & 0xFF);
params[i++] = temp;

// Registers 156
temp = (uint8_t)((ssud_p2 >> 8) & 0x7f);
params[i++] = temp;

// Registers 157
temp = (uint8_t)(ssud_p2 & 0xff);
params[i++] = temp;

// Register 158
temp = (uint8_t)((ssud_p3 >> 8) & 0x7f);
params[i++] = temp;

// Registers 159
temp = (uint8_t)(ssud_p3 & 0xFF);
params[i++] = temp;

// Registers 160
temp = (uint8_t)(ssud_p1 & 0xFF);
params[i++] = temp;

// Registers 161
temp = (uint8_t)((ssud_p1 >> 8) & 0x0F);
params[i++] = temp;

si5351_write_bulk(SI5351_SSC_PARAM0, i, params);
}

delete params;
}

Expand Down Expand Up @@ -825,11 +894,15 @@ void Si5351::pll_reset(enum si5351_pll target_pll)
{
if(target_pll == SI5351_PLLA)
{
si5351_write(SI5351_PLL_RESET, SI5351_PLL_RESET_A);
// 0x0c is a datasheet undocumented value. It is only present in AN619.
// Without this value reset seems to be ignored...
si5351_write(SI5351_PLL_RESET, 0x0c | SI5351_PLL_RESET_A);
}
else if(target_pll == SI5351_PLLB)
{
si5351_write(SI5351_PLL_RESET, SI5351_PLL_RESET_B);
// 0x0c is a datasheet undocumented value. It is only present in AN619.
// Without this value reset seems to be ignored...
si5351_write(SI5351_PLL_RESET, 0x0c | SI5351_PLL_RESET_B);
}
}

Expand Down Expand Up @@ -1407,6 +1480,9 @@ uint64_t Si5351::pll_calc(enum si5351_pll pll, uint64_t freq, struct Si5351RegSe
freq = lltmp;
freq += ref_freq * a;

reg->a = a;
reg->b = b;
reg->c = c;
reg->p1 = p1;
reg->p2 = p2;
reg->p3 = p3;
Expand Down Expand Up @@ -1505,6 +1581,9 @@ uint64_t Si5351::multisynth_calc(uint64_t freq, uint64_t pll_freq, struct Si5351
p3 = c;
}

reg->a = a;
reg->b = b;
reg->c = c;
reg->p1 = p1;
reg->p2 = p2;
reg->p3 = p3;
Expand Down
5 changes: 5 additions & 0 deletions src/si5351.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define SI5351_PLL_FIXED 80000000000ULL
#define SI5351_FREQ_MULT 100ULL
#define SI5351_DEFAULT_CLK 1000000000ULL
#define SI5351_SSCAMP_x1000 1ULL

#define SI5351_PLL_VCO_MIN 600000000
#define SI5351_PLL_VCO_MAX 900000000
Expand Down Expand Up @@ -254,6 +255,10 @@ enum si5351_pll_input {SI5351_PLL_INPUT_XO, SI5351_PLL_INPUT_CLKIN};

struct Si5351RegSet
{
// a, b and c used for spread sectrum parameters calculation
uint32_t a;
uint32_t b;
uint32_t c;
uint32_t p1;
uint32_t p2;
uint32_t p3;
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy