Browse Source

better naming/config organization

master
parent
commit
66df439848
  1. 4
      simple-dmi.json
  2. 8
      src/noptica.rs
  3. 12
      src/simple-dmi.rs

4
simple-dmi.json

@ -1,11 +1,11 @@
{
"sample_command": "glasgow run logic -V 3.3 --pins-d 0,1",
"sample_rate": 48e6,
"freq_min": 1.9e6,
"freq_max": 2.1e6,
"bit_ref": 0,
"bit_meas": 1,
"ref_min": 1.9e6,
"ref_max": 2.1e6,
"refpll_ki": 4294967,
"refpll_kp": 85899345,

8
src/noptica.rs

@ -52,14 +52,14 @@ impl Dpll {
}
}
pub struct Tracker {
pub struct PositionTracker {
last_phase: i64,
current_position: i64
}
impl Tracker {
pub fn new() -> Tracker {
Tracker {
impl PositionTracker {
pub fn new() -> PositionTracker {
PositionTracker {
last_phase: 0,
current_position: 0
}

12
src/simple-dmi.rs

@ -15,10 +15,10 @@ mod noptica;
struct Config {
sample_command: String,
sample_rate: f64,
freq_min: f64,
freq_max: f64,
bit_ref: u8,
bit_meas: u8,
ref_min: f64,
ref_max: f64,
refpll_ki: i64,
refpll_kp: i64,
decimation: u32
@ -34,16 +34,16 @@ fn read_config_from_file<P: AsRef<Path>>(path: P) -> Result<Config, Box<dyn Erro
fn main() {
let config = read_config_from_file("simple-dmi.json").unwrap();
let mut refpll = noptica::Dpll::new(
noptica::Dpll::frequency_to_ftw(config.freq_min, config.sample_rate),
noptica::Dpll::frequency_to_ftw(config.freq_max, config.sample_rate),
noptica::Dpll::frequency_to_ftw(config.ref_min, config.sample_rate),
noptica::Dpll::frequency_to_ftw(config.ref_max, config.sample_rate),
config.refpll_ki,
config.refpll_kp);
let mut tracker = noptica::Tracker::new();
let mut position_tracker = noptica::PositionTracker::new();
let mut decimator = noptica::Decimator::new(config.decimation);
noptica::sample(&config.sample_command, |rising, _falling| {
refpll.tick(rising & (1 << config.bit_ref) != 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) {
println!("{}", position_avg);
}

Loading…
Cancel
Save