wavemeter: decimate wavelength output

This commit is contained in:
Sebastien Bourdeauducq 2019-11-16 14:38:08 +08:00
parent c48a30bb9b
commit 9a6cccaf4a
2 changed files with 18 additions and 7 deletions

View File

@ -40,7 +40,9 @@ struct Config {
position_mon_time: f64, // The time during which position is monitored to compute min/max 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 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 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<P: AsRef<Path>>(path: P) -> Result<Config, Box<dyn Error>> { fn read_config_from_file<P: AsRef<Path>>(path: P) -> Result<Config, Box<dyn Error>> {
@ -145,6 +147,7 @@ fn do_wavemeter(config: &Config) {
let mut first_fringe = 0; let mut first_fringe = 0;
let mut fringe_count = 0; let mut fringe_count = 0;
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);
@ -176,13 +179,19 @@ fn do_wavemeter(config: &Config) {
} }
if !in_duty & prev_in_duty { if !in_duty & prev_in_duty {
let wavelength = (fringe_position - first_fringe).abs()/fringe_count; 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; let wavelength_nm = (wavelength as f64)/(noptica::Dpll::TURN as f64)*1.0e9*config.ref_wavelength;
println!("{:.4} {} {} {:.1}", if config.debug {
(wavelength as f64)/(noptica::Dpll::TURN as f64)*1.0e9*config.ref_wavelength, let displacement = ((fringe_position - first_fringe).abs() as f64)/(noptica::Dpll::TURN as f64)*config.ref_wavelength;
fringe_count, println!("DEBUG: {:.4} {} {} {:.1}",
if fringe_position > first_fringe { "UP " } else { "DOWN" }, wavelength_nm,
1.0e9*displacement); fringe_count,
if fringe_position > first_fringe { "UP " } else { "DOWN" },
1.0e9*displacement);
}
fringe_count = 0; fringe_count = 0;
if let Some(wavelength_nm) = decimator.input(wavelength_nm) {
println!("{:.4} nm", wavelength_nm);
}
} }
fringe_count += 1; fringe_count += 1;
prev_in_duty = in_duty; prev_in_duty = in_duty;

View File

@ -15,5 +15,7 @@
"position_mon_time": 0.25, "position_mon_time": 0.25,
"duty_cycle": 0.9, "duty_cycle": 0.9,
"motion_cutoff": 100e3 "debug": false,
"motion_cutoff": 100e3,
"decimation": 50
} }