Skip to content

Commit

Permalink
run at max clock, delay before deep sleep, document weird behaviours
Browse files Browse the repository at this point in the history
to prevent the back and forth after I forget.
  • Loading branch information
alevinval committed Jun 29, 2024
1 parent 4fde8e2 commit 9f2780d
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions humidity-monitor-c6/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ fn main() -> ! {

let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

// Ideally we would like to run at minimum clock (boot_defaults) but there
// appear to be issues with low clock speeds. Like getting stuck without
// serial comms to reflash the program, or getting weird readings on the ADC
// after a few iterations of deep sleep.
let clocks = ClockControl::max(system.clock_control).freeze();

let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

let mut rtc = Rtc::new(peripherals.LPWR, None);
Expand All @@ -80,20 +86,13 @@ fn main() -> ! {
let mut warmup = || delay.delay_millis(HYGROMETER_WARMUP);
let mut read_adc = || hygrometer_adc1.read_oneshot(hygrometer_adc1_pin).unwrap();

// loop {
// let summary = sample::perform_sampling(
// 255,
// &mut toggle,
// &mut warmup,
// &mut read_adc,
// Hygrometer::HW390,
// );
// println!("avg: {} min: {} max: {}", summary.avg, summary.min, summary.max);
// delay.delay_millis(1000);
// }

let summary =
sample::perform_sampling(HYGROMETER_SAMPLES, &mut toggle, &mut warmup, &mut read_adc, Hygrometer::HW390);
let summary = sample::perform_sampling(
HYGROMETER_SAMPLES,
&mut toggle,
&mut warmup,
&mut read_adc,
Hygrometer::HW390,
);

unsafe { SAMPLE_HISTORY.store(summary) };

Expand Down Expand Up @@ -141,5 +140,11 @@ fn main() -> ! {
pulse!(alarm, delay, 100);

let timer = TimerWakeupSource::new(Duration::from_millis(MEASURE_DELAY));

// Not sure if this delay is needed, I certainly notice weird behaviours when
// going to sleep and waking up. Such as ADC readings working well for the first
// two or three cycles, and then suddenly become uncalibrated.
delay.delay_millis(1000);

rtc.sleep_deep(&[&timer], delay);
}

0 comments on commit 9f2780d

Please sign in to comment.