better naming/config organization
This commit is contained in:
parent
34cf0037ea
commit
66df439848
@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"sample_command": "glasgow run logic -V 3.3 --pins-d 0,1",
|
"sample_command": "glasgow run logic -V 3.3 --pins-d 0,1",
|
||||||
"sample_rate": 48e6,
|
"sample_rate": 48e6,
|
||||||
"freq_min": 1.9e6,
|
|
||||||
"freq_max": 2.1e6,
|
|
||||||
"bit_ref": 0,
|
"bit_ref": 0,
|
||||||
"bit_meas": 1,
|
"bit_meas": 1,
|
||||||
|
|
||||||
|
"ref_min": 1.9e6,
|
||||||
|
"ref_max": 2.1e6,
|
||||||
"refpll_ki": 4294967,
|
"refpll_ki": 4294967,
|
||||||
"refpll_kp": 85899345,
|
"refpll_kp": 85899345,
|
||||||
|
|
||||||
|
@ -52,14 +52,14 @@ impl Dpll {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Tracker {
|
pub struct PositionTracker {
|
||||||
last_phase: i64,
|
last_phase: i64,
|
||||||
current_position: i64
|
current_position: i64
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tracker {
|
impl PositionTracker {
|
||||||
pub fn new() -> Tracker {
|
pub fn new() -> PositionTracker {
|
||||||
Tracker {
|
PositionTracker {
|
||||||
last_phase: 0,
|
last_phase: 0,
|
||||||
current_position: 0
|
current_position: 0
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,10 @@ mod noptica;
|
|||||||
struct Config {
|
struct Config {
|
||||||
sample_command: String,
|
sample_command: String,
|
||||||
sample_rate: f64,
|
sample_rate: f64,
|
||||||
freq_min: f64,
|
|
||||||
freq_max: f64,
|
|
||||||
bit_ref: u8,
|
bit_ref: u8,
|
||||||
bit_meas: u8,
|
bit_meas: u8,
|
||||||
|
ref_min: f64,
|
||||||
|
ref_max: f64,
|
||||||
refpll_ki: i64,
|
refpll_ki: i64,
|
||||||
refpll_kp: i64,
|
refpll_kp: i64,
|
||||||
decimation: u32
|
decimation: u32
|
||||||
@ -34,16 +34,16 @@ fn read_config_from_file<P: AsRef<Path>>(path: P) -> Result<Config, Box<dyn Erro
|
|||||||
fn main() {
|
fn main() {
|
||||||
let config = read_config_from_file("simple-dmi.json").unwrap();
|
let config = read_config_from_file("simple-dmi.json").unwrap();
|
||||||
let mut refpll = noptica::Dpll::new(
|
let mut refpll = noptica::Dpll::new(
|
||||||
noptica::Dpll::frequency_to_ftw(config.freq_min, config.sample_rate),
|
noptica::Dpll::frequency_to_ftw(config.ref_min, config.sample_rate),
|
||||||
noptica::Dpll::frequency_to_ftw(config.freq_max, config.sample_rate),
|
noptica::Dpll::frequency_to_ftw(config.ref_max, config.sample_rate),
|
||||||
config.refpll_ki,
|
config.refpll_ki,
|
||||||
config.refpll_kp);
|
config.refpll_kp);
|
||||||
let mut tracker = noptica::Tracker::new();
|
let mut position_tracker = noptica::PositionTracker::new();
|
||||||
let mut decimator = noptica::Decimator::new(config.decimation);
|
let mut decimator = noptica::Decimator::new(config.decimation);
|
||||||
noptica::sample(&config.sample_command, |rising, _falling| {
|
noptica::sample(&config.sample_command, |rising, _falling| {
|
||||||
refpll.tick(rising & (1 << config.bit_ref) != 0);
|
refpll.tick(rising & (1 << config.bit_ref) != 0);
|
||||||
if rising & (1 << config.bit_meas) != 0 {
|
if rising & (1 << config.bit_meas) != 0 {
|
||||||
let position = tracker.edge(refpll.get_phase_unwrapped());
|
let position = position_tracker.edge(refpll.get_phase_unwrapped());
|
||||||
if let Some(position_avg) = decimator.input(position) {
|
if let Some(position_avg) = decimator.input(position) {
|
||||||
println!("{}", position_avg);
|
println!("{}", position_avg);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user