From 9a6cccaf4a9bb08f712b105ba54b855b272821d5 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 16 Nov 2019 14:38:08 +0800 Subject: [PATCH] wavemeter: decimate wavelength output --- src/wavemeter.rs | 21 +++++++++++++++------ wavemeter.json | 4 +++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/wavemeter.rs b/src/wavemeter.rs index 2d4e069..b5877da 100644 --- a/src/wavemeter.rs +++ b/src/wavemeter.rs @@ -40,7 +40,9 @@ struct Config { position_mon_time: f64, // The time during which position is monitored to compute min/max duty_cycle: f64, // Fraction of the scan used for counting input laser fringes + debug: bool, // Enable debug output of wavelength determination code motion_cutoff: f64, // Cut-off frequency of the motion filter + decimation: u32, // Decimation/averaging factor for the final wavelength output } fn read_config_from_file>(path: P) -> Result> { @@ -145,6 +147,7 @@ fn do_wavemeter(config: &Config) { let mut first_fringe = 0; let mut fringe_count = 0; + let mut decimator = noptica::Decimator::new(config.decimation); noptica::sample(&config.sample_command, |rising, _falling| { refpll.tick(rising & (1 << config.bit_ref) != 0); @@ -176,13 +179,19 @@ fn do_wavemeter(config: &Config) { } if !in_duty & prev_in_duty { let wavelength = (fringe_position - first_fringe).abs()/fringe_count; - let displacement = ((fringe_position - first_fringe).abs() as f64)/(noptica::Dpll::TURN as f64)*config.ref_wavelength; - println!("{:.4} {} {} {:.1}", - (wavelength as f64)/(noptica::Dpll::TURN as f64)*1.0e9*config.ref_wavelength, - fringe_count, - if fringe_position > first_fringe { "UP " } else { "DOWN" }, - 1.0e9*displacement); + let wavelength_nm = (wavelength as f64)/(noptica::Dpll::TURN as f64)*1.0e9*config.ref_wavelength; + if config.debug { + let displacement = ((fringe_position - first_fringe).abs() as f64)/(noptica::Dpll::TURN as f64)*config.ref_wavelength; + println!("DEBUG: {:.4} {} {} {:.1}", + wavelength_nm, + fringe_count, + if fringe_position > first_fringe { "UP " } else { "DOWN" }, + 1.0e9*displacement); + } fringe_count = 0; + if let Some(wavelength_nm) = decimator.input(wavelength_nm) { + println!("{:.4} nm", wavelength_nm); + } } fringe_count += 1; prev_in_duty = in_duty; diff --git a/wavemeter.json b/wavemeter.json index 0ca983e..09c65da 100644 --- a/wavemeter.json +++ b/wavemeter.json @@ -15,5 +15,7 @@ "position_mon_time": 0.25, "duty_cycle": 0.9, - "motion_cutoff": 100e3 + "debug": false, + "motion_cutoff": 100e3, + "decimation": 50 }