Commit 03433833 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

softpll: enable dithering for the helper PLL

parent 284ea791
......@@ -291,6 +291,10 @@ void spll_very_init(void)
spll_n_chan_out = 3;
softpll.mpll.gain_sched = NULL;
helper_very_init((struct spll_helper_state *) &softpll.helper); // set up default PI gains/lock thresholds
}
void spll_init(int mode, int slave_ref_channel, int flags)
......
......@@ -14,25 +14,22 @@
#include <wrc.h>
#include "softpll_ng.h"
static int gen_dither( int pi_shift )
static int gen_dither_lfsr( int pi_shift )
{
static const uint32_t lcg_m = 1103515245;
static const uint32_t lcg_i = 12345;
static uint32_t seed = 0;
static uint16_t lfsr = 0xACE1u;
uint16_t bit; /* Must be 16-bit to allow bit<<15 later in the code */
seed *= lcg_m;
seed += lcg_i;
seed &= 0x7fffffffUL;
/* taps: 16 14 13 11; feedback polynomial: x^16 + x^14 + x^13 + x^11 + 1 */
bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5)) & 1u;
lfsr = (lfsr >> 1) | (bit << 15);
int d = seed & (( 1<<pi_shift) - 1);
if ( seed & (1<<pi_shift))
int d = (uint32_t)lfsr & (( 1<<pi_shift) - 1);
if ( lfsr & (1<<pi_shift))
return -d;
else
return d;
}
int pi_update(spll_pi_t *pi, int x)
{
int64_t i_new;
......@@ -42,7 +39,7 @@ int pi_update(spll_pi_t *pi, int x)
int64_t y_preround = (i_new + (int64_t) x * pi->kp) + ( 1 << (pi->shift - 1) );
int dither = pi->dithered ? gen_dither( pi->shift ) : 0;
int dither = pi->dithered ? gen_dither_lfsr( pi->shift - 1 ) : 0;
y = ( (y_preround + dither) >> pi->shift) + pi->bias;
/* clamping (output has to be in <y_min, y_max>) and
......
......@@ -9,13 +9,11 @@
/* spll_helper.c - implmentation of the Helper PLL servo algorithm. */
#include <wrc.h>
#include "softpll_ng.h"
void helper_init(struct spll_helper_state *s, int ref_channel)
void helper_very_init( struct spll_helper_state *s )
{
/* Phase branch PI controller */
/* Phase branch PI controller */
s->pi.y_min = 5;
s->pi.y_max = (1 << DAC_BITS) - 5;
#if defined(CONFIG_WR_NODE)
......@@ -32,6 +30,10 @@ void helper_init(struct spll_helper_state *s, int ref_channel)
s->ld.threshold = 200;
s->ld.lock_samples = 10000;
s->ld.delock_samples = 100;
}
void helper_init(struct spll_helper_state *s, int ref_channel)
{
s->ref_src = ref_channel;
}
......@@ -106,7 +108,6 @@ void helper_start(struct spll_helper_state *s)
s->sample_n = 0;
s->tag_d0 = -1;
board_dbg("Helper PLL PI Values: Kp %i\t Ki %i\n",s->pi.kp,s->pi.ki);
pi_init((spll_pi_t *)&s->pi);
ld_init((spll_lock_det_t *)&s->ld);
......
......@@ -35,6 +35,7 @@ struct spll_helper_state {
spll_lock_det_t ld;
};
void helper_very_init( struct spll_helper_state *s );
void helper_init(struct spll_helper_state *s, int ref_channel);
void helper_update(struct spll_helper_state *s, int tag, int source);
......
......@@ -69,6 +69,7 @@ void mpll_init(struct spll_main_state *s, int id_ref, int id_out)
}
pi_init((spll_pi_t *)&s->pi);
s->pi.dithered = 0;
ld_init((spll_lock_det_t *)&s->ld);
}
......@@ -116,7 +117,6 @@ static inline void mpll_handle_gain_schedule( struct spll_main_state *s )
s->ld.lock_changed = 0;
s->ld.locked = 0;
s->gain_sched->locked_d = 0;
board_dbg("Gain schedule stage: %d, Kp: %d, ki: %d, shift: %d\n",s->gain_sched->current_stage, stage->kp,stage->ki, stage->shift);
}
s->gain_sched->locked_d = s->ld.locked;
......@@ -159,8 +159,8 @@ void mpll_start(struct spll_main_state *s)
s->ld.lock_cnt = 0;
}
board_dbg("Main PLL PI Values: Kp %i\t Ki %i\n",s->pi.kp,s->pi.ki);
pi_init((spll_pi_t *)&s->pi);
s->pi.dithered = 0;
ld_init((spll_lock_det_t *)&s->ld);
spll_enable_tagger(s->id_ref, 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment