From cdf15e184b66ce829a6253cc0ef393464e28b0a1 Mon Sep 17 00:00:00 2001 From: JP Stringham Date: Sat, 24 Jan 2026 09:46:26 -0500 Subject: [PATCH] BIG CAP testing --- .cargo/config.toml | 2 +- src/main.rs | 45 +++++++++++++++++++++++++++-- tests/draw.html | 72 ++++++++++++++++++++++++++++++++++------------ 3 files changed, 97 insertions(+), 22 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index a492de7..3da2a5f 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -35,5 +35,5 @@ rustflags = [ runner = "probe-rs run --chip RP2040 --protocol swd" [env] -DEFMT_RTT_BUFFER_SIZE = { value = "4096", force = true } +DEFMT_RTT_BUFFER_SIZE = { value = "16384", force = true } DEFMT_LOG = { value = "info", force = true } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index ca1d514..8c0aa1d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,7 @@ pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_GENERIC_03H; /// if your board has a different frequency const XTAL_FREQ_HZ: u32 = 12_000_000u32; -const NUM_ADC_SAMPLES: usize = 1024; +const NUM_ADC_SAMPLES: usize = 8192; /// Entry point to our bare-metal application. /// @@ -95,13 +95,15 @@ fn main() -> ! { MyPin::new(MyPinMode::Input, pins.gpio13.into_dyn_pin()), ]; + let mut brute_force_pin: MyPin = MyPin::new(MyPinMode::Floating, pins.gpio9.into_dyn_pin()); + let dma = pac.DMA.split(&mut pac.RESETS); let mut adc = hal::Adc::new(pac.ADC, &mut pac.RESETS); let mut adc_pin = hal::adc::AdcPin::new(pins.gpio26.into_floating_input()).unwrap(); let mut adc_fifo = adc .build_fifo() - .clock_divider(24000, 0) + .clock_divider(192, 0) .set_channel(&mut adc_pin) .enable_dma() .start_paused(); @@ -158,6 +160,7 @@ fn main() -> ! { adc_fifo.resume(); let (ch, adc_read_target, buf_for_samples) = dma_transfer.wait(); let avg = avg_fifo(buf_for_samples, false); + let max_v = avg; println!("Avg: {}", avg); adc_fifo.pause(); @@ -170,12 +173,18 @@ fn main() -> ! { test_pins[2].switch_into_output(); test_pins[2].set_low(); delay.delay_ms(200); + // this needs to resume before we start floating the other pin, + // otherwise we're often too slow to catch the initial drop + // some data post-processing will be needed anyway to trim begin/end adc_fifo.resume(); test_pins[0].switch_to_floating(); let (ch, adc_read_target, buf_for_samples) = dma_transfer.wait(); - let avg = avg_fifo(buf_for_samples, true); delay.delay_ms(10); + let avg = avg_fifo(buf_for_samples, true); println!("Avg: {}", avg); + if avg >= (max_v * 9) / 10 { + println!("Probably a large capacitor, alt test recommended"); + } adc_fifo.pause(); adc_fifo.clear(); @@ -183,6 +192,36 @@ fn main() -> ! { // TEST 4 delay.delay_ms(1000); + println!("Alt Testing floating"); + brute_force_pin.switch_into_output(); + brute_force_pin.set_high(); + // test_pins[0].set_high(); + test_pins[2].switch_into_output(); + test_pins[2].set_low(); + delay.delay_ms(200); + // this needs to resume before we start floating the other pin, + // otherwise we're often too slow to catch the initial drop + // some data post-processing will be needed anyway to trim begin/end + adc_fifo.resume(); + brute_force_pin.set_low(); + test_pins[0].switch_into_output(); + test_pins[0].set_low(); + let (ch, adc_read_target, buf_for_samples) = dma_transfer.wait(); + delay.delay_ms(10); + let avg = avg_fifo(buf_for_samples, true); + println!("Avg: {}", avg); + if avg >= (max_v * 9) / 10 { + println!("Probably a HUGE capacitor, alt test recommended"); + } + + // cleanup + brute_force_pin.switch_to_floating(); + adc_fifo.pause(); + adc_fifo.clear(); + dma_transfer = single_buffer::Config::new(ch, adc_read_target, buf_for_samples).start(); + + // TEST 5 + delay.delay_ms(1000); println!("Testing resistance"); test_pins[0].switch_into_output(); test_pins[2].switch_into_output(); diff --git a/tests/draw.html b/tests/draw.html index e7013e4..266d28e 100644 --- a/tests/draw.html +++ b/tests/draw.html @@ -22,6 +22,8 @@