Skip to content

Support for ADC multichannel continuous conversion? #212

@yjh0502

Description

@yjh0502

Hi, I'm trying to run a ADC multichannel (scan mode) continuous conversion. I dig into the code to check current status:

Continuous conversion: set cont() bit on start()

stm32f1xx-hal/src/adc.rs

Lines 558 to 568 in 89600ec

impl<PINS> TransferPayload for AdcDma<PINS, Continuous> {
fn start(&mut self) {
self.channel.start();
self.payload.adc.rb.cr2.modify(|_, w| w.cont().set_bit());
self.payload.adc.rb.cr2.modify(|_, w| w.adon().set_bit());
}
fn stop(&mut self) {
self.channel.stop();
self.payload.adc.rb.cr2.modify(|_, w| w.cont().clear_bit());
}
}

Scan conversion: not setting cont() bit on start() clear cont() explicitly on initialization. It is definitely not intended for continuous conversion.

stm32f1xx-hal/src/adc.rs

Lines 608 to 617 in 89600ec

self.rb.cr2.modify(|_, w| {
w.adon()
.clear_bit()
.dma()
.clear_bit()
.cont()
.clear_bit()
.align()
.bit(self.align.into())
});

I think there are several ways to support continuous scan conversion mode:

  • I could add quick and dirty fix by introducing ContinuousScan struct (or struct Scan { continuous: bool } if it's okay to break API), but I'm not sure if it's a right way.
  • I could think of generalized struct/trait which covers single/multichannel one-shot/continuous conversion scenario. Single-channel conversion could be treated as a special case of multichannel conversion anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions