mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
change the pll logic a bit
This commit is contained in:
2
.vscode/.server-controller-port.log
vendored
2
.vscode/.server-controller-port.log
vendored
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"port": 13452,
|
"port": 13452,
|
||||||
"time": 1742742025054,
|
"time": 1742831052343,
|
||||||
"version": "0.0.3"
|
"version": "0.0.3"
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,6 @@ void init_pll(PLL *pll, float freq, float loop_filter_bandwidth, float damping,
|
|||||||
pll->loop_filter_state = 0.0f;
|
pll->loop_filter_state = 0.0f;
|
||||||
pll->kp = M_2PI * loop_filter_bandwidth;
|
pll->kp = M_2PI * loop_filter_bandwidth;
|
||||||
pll->ki = (4.0f*damping*damping) * pll->kp * pll->kp;
|
pll->ki = (4.0f*damping*damping) * pll->kp * pll->kp;
|
||||||
pll->last_output = 0.0f;
|
|
||||||
pll->sample_rate = sample_rate;
|
pll->sample_rate = sample_rate;
|
||||||
pll->quadrature_mode = quadrature_mode;
|
pll->quadrature_mode = quadrature_mode;
|
||||||
}
|
}
|
||||||
@@ -31,7 +30,7 @@ float apply_pll(PLL *pll, float ref_sample) {
|
|||||||
float vco_output = sinf(pll->phase);
|
float vco_output = sinf(pll->phase);
|
||||||
if (pll->quadrature_mode) vco_output = sinf(pll->phase + (M_PI / 2.0f));
|
if (pll->quadrature_mode) vco_output = sinf(pll->phase + (M_PI / 2.0f));
|
||||||
|
|
||||||
phase_error = ref_sample * pll->last_output;
|
phase_error = ref_sample * vco_output;
|
||||||
|
|
||||||
pll->loop_filter_state += pll->ki * phase_error / pll->sample_rate;
|
pll->loop_filter_state += pll->ki * phase_error / pll->sample_rate;
|
||||||
float loop_output = pll->loop_filter_state + pll->kp * phase_error;
|
float loop_output = pll->loop_filter_state + pll->kp * phase_error;
|
||||||
@@ -48,7 +47,5 @@ float apply_pll(PLL *pll, float ref_sample) {
|
|||||||
pll->phase += M_2PI;
|
pll->phase += M_2PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
pll->last_output = vco_output;
|
|
||||||
|
|
||||||
return vco_output;
|
return vco_output;
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,6 @@ typedef struct {
|
|||||||
float loop_filter_state;
|
float loop_filter_state;
|
||||||
float kp;
|
float kp;
|
||||||
float ki;
|
float ki;
|
||||||
float last_output;
|
|
||||||
int sample_rate;
|
int sample_rate;
|
||||||
int quadrature_mode;
|
int quadrature_mode;
|
||||||
} PLL;
|
} PLL;
|
||||||
|
|||||||
Reference in New Issue
Block a user