Skip to content

Commit

Permalink
fix: prescaler for ADC (#347)
Browse files Browse the repository at this point in the history
Fix prescaler for ADC
  • Loading branch information
cassio-lazaro committed Jun 28, 2024
1 parent 8629391 commit 0d083aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
8 changes: 2 additions & 6 deletions hal_st/stm32fxxx/AnalogToDigitalPinStm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace hal
adc.Measure(onDone);
}

AdcStm::AdcStm(uint8_t oneBasedIndex)
AdcStm::AdcStm(uint8_t oneBasedIndex, const Config& config)
: index(oneBasedIndex - 1)
#if defined(STM32WB) || defined(STM32G0)
, interruptHandler(ADC1_IRQn, [this]()
Expand All @@ -136,11 +136,7 @@ namespace hal
EnableClockAdc(index);

handle.Instance = peripheralAdc[index];
#ifdef ADC_CLOCK_ASYNC_DIV4
handle.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;
#else
handle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV4;
#endif
handle.Init.ClockPrescaler = config.clockPrescaler;
handle.Init.Resolution = ADC_RESOLUTION_12B;
handle.Init.ScanConvMode = DISABLE;
handle.Init.ContinuousConvMode = DISABLE;
Expand Down
13 changes: 12 additions & 1 deletion hal_st/stm32fxxx/AnalogToDigitalPinStm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ namespace hal
uint32_t samplingTime{ ADC_SAMPLETIME_3CYCLES_5 };
#else
uint32_t samplingTime{ ADC_SAMPLETIME_3CYCLES };
#endif
};

struct AdcStmConfig
{
#ifdef STM32WBA
uint32_t clockPrescaler{ ADC_CLOCK_ASYNC_DIV4 };
#else
uint32_t clockPrescaler{ ADC_CLOCKPRESCALER_PCLK_DIV4 };
#endif
};
}
Expand Down Expand Up @@ -61,7 +70,9 @@ namespace hal
class AdcStm
{
public:
explicit AdcStm(uint8_t adcIndex);
using Config = detail::AdcStmConfig;

explicit AdcStm(uint8_t adcIndex, const Config& config = Config());
~AdcStm();

protected:
Expand Down

0 comments on commit 0d083aa

Please sign in to comment.