forked from M-Labs/kirdy
MAX1968: Improve STM32 ADC calibration consistency
This commit is contained in:
parent
b330f45260
commit
c5efc6ca57
|
@ -125,7 +125,17 @@ impl MAX1968 {
|
|||
.default_sample_time(config::SampleTime::Cycles_480);
|
||||
// Do not set reset RCCs as it causes other ADCs' clock to be disabled
|
||||
let mut pins_adc1 = Adc::adc1(adc1, false, adc_config);
|
||||
pins_adc1.calibrate();
|
||||
|
||||
// adc1.calibrate() fn only read REFINT once to assign the calibration value.
|
||||
// It does not take the STM32F4's ADC Precision Limitation into account.
|
||||
// AN4073: ADC Reading Dispersion can be reduced through Averaging
|
||||
let mut vdda_mv: u32 = 0;
|
||||
for _ in (0..512).rev() {
|
||||
pins_adc1.calibrate();
|
||||
vdda_mv += pins_adc1.reference_voltage();
|
||||
}
|
||||
vdda_mv = vdda_mv / 512 as u32;
|
||||
pins_adc1.apply_config(adc_config.reference_voltage(vdda_mv));
|
||||
|
||||
let adc_config = AdcConfig::default()
|
||||
.clock(config::Clock::Pclk2_div_8)
|
||||
|
|
Loading…
Reference in New Issue