1
0
Fork 0

Thermostat: Add fn to calibrate ADC's VDDA

- ADC1 exclusive feature
- Calibrated VDDA val can be passed to other ADCs to adjust gain error
This commit is contained in:
linuswck 2024-01-22 12:24:19 +08:00
parent 0d12c902fc
commit c768bdc93a
2 changed files with 19 additions and 2 deletions

View File

@ -115,11 +115,17 @@ impl<C: ChannelPins> MAX1968Phy<C> {
impl MAX1968 {
pub fn new(phy_ch0: MAX1968Phy<Channel0>, adc1: ADC1) -> Self {
// Set ADC to a slowest sampling interval for more accurate calibration
let config = AdcConfig::default()
.clock(config::Clock::Pclk2_div_2)
.clock(config::Clock::Pclk2_div_8)
.default_sample_time(config::SampleTime::Cycles_480);
let mut pins_adc = Adc::adc1(adc1, true, config);
pins_adc.calibrate();
let pins_adc = Adc::adc1(adc1, true, config);
let config = AdcConfig::default()
.clock(config::Clock::Pclk2_div_8)
.default_sample_time(config::SampleTime::Cycles_480);
pins_adc.apply_config(config);
MAX1968 {
phy: phy_ch0,
@ -127,6 +133,12 @@ impl MAX1968 {
}
}
// Return the calibrated VDDA Voltage
// Can be used to set reference voltage for other ADC
pub fn get_calibrated_vdda(&mut self) -> u32 {
self.pins_adc.reference_voltage()
}
pub fn power_down(&mut self) {
self.phy.shdn.set_low();
}

View File

@ -301,6 +301,11 @@ impl Thermostat{
max_i_neg: TecSettingsSummaryField { value: self.tec_setting.max_i_neg_set, max: TecSettings::MAX_I_NEG_CURRENT },
}
}
pub fn get_calibrated_vdda(&mut self) -> u32 {
self.max1968.get_calibrated_vdda()
}
}
#[derive(Miniconf)]