From 83731f77e0bf7363e5def58d50974dba6c819da3 Mon Sep 17 00:00:00 2001 From: Hubald Verzijl Date: Thu, 28 Aug 2025 11:33:33 +0200 Subject: [PATCH] Minor improvements --- src/impedance.rs | 4 ++-- src/main.rs | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/impedance.rs b/src/impedance.rs index 5163bba..8a37544 100644 --- a/src/impedance.rs +++ b/src/impedance.rs @@ -47,7 +47,7 @@ impl ImpedanceSetup { .adc_mux_n(MUXSELN::HsTiaNeg) .adc_mux_p(MUXSELP::HsTiaPos) .ctiacon(CTIACON::C32) - .rtiacon(RTIACON::R5k) + .rtiacon(RTIACON::R1k) .sinc3osr(SINC3OSR::R5) .sinc2osr(SINC2OSR::R178) .adcsamplerate(ADCSAMPLERATE::R800kHz) @@ -92,7 +92,7 @@ impl ImpedanceSetup { self.ad5940.sequencer_enable(true).await; self.ad5940.wgfcw(frequency).await; - let wg_amplitude = 557; // 2047 is the maximum amplitude for a 12-bit DAC --> 1.62V peak-to-peak + let wg_amplitude = 2047; // 2047 is the maximum amplitude for a 12-bit DAC --> 1.62V peak-to-peak self.ad5940.write_reg(Register::WGAMPLITUDE, wg_amplitude).await.unwrap(); // Rcal diff --git a/src/main.rs b/src/main.rs index 8a62ebe..e41114a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -230,12 +230,7 @@ const RCAL_VAL: f32 = 1000.0; /// Convert raw 18-bit 2's complement value to signed i32 fn sign_extend_18bit(val: u32) -> i32 { - let masked = val & 0x3FFFF; - if masked & (1 << 17) != 0 { - (masked | 0xFFFC0000) as i32 - } else { - masked as i32 - } + ((val << 14) as i32) >> 14 } /// Calculate magnitude and phase of Rz using Rcal reference