@@ -65,6 +65,15 @@ void OvmsVehicleSmartEQ::Ticker10(uint32_t ticker)
6565
6666 if (m_enable_LED_state)
6767 OnlineState ();
68+
69+ // check 12V charging state for powermgmt system
70+ bool charge_12v = StdMetrics.ms_v_bat_12v_voltage ->AsFloat (0 .0f ) > 13 .1f ? true : false ;
71+ if (charge_12v != StdMetrics.ms_v_env_charging12v ->AsBool (false ))
72+ {
73+ StdMetrics.ms_v_env_charging12v ->SetValue (charge_12v);
74+ m_ADCfactor_recalc_timer = 2 ;
75+ m_ADCfactor_recalc = charge_12v;
76+ }
6877 }
6978
7079void OvmsVehicleSmartEQ::Ticker60 (uint32_t ticker) {
@@ -105,30 +114,44 @@ void OvmsVehicleSmartEQ::Ticker60(uint32_t ticker) {
105114 mt_bus_awake->SetValue (true );
106115 smartChargeStart ();
107116 }
108- // check 12V charging state for powermgmt system
109- bool charge_12v = StdMetrics.ms_v_bat_12v_voltage ->AsFloat (0 .0f ) > 13 .1f ? true : false ;
110- if (charge_12v != StdMetrics.ms_v_env_charging12v ->AsBool ())
111- {
112- StdMetrics.ms_v_env_charging12v ->SetValue (charge_12v);
113- }
114117
115118 #ifdef CONFIG_OVMS_COMP_ADC
116- if (m_enable_calcADCfactor && m_ADCfactor_recalc)
119+ if ( IsOnEQ () || IsChargingEQ ())
117120 {
118- if (--m_ADCfactor_recalc_timer == 0 )
121+ // check for 12V voltage difference between CAN and ADC when the car is rebooted, to detect if ADC factor recalibration is needed
122+ if (m_check12vadc)
119123 {
120- m_ADCfactor_recalc = false ;
121- m_ADCfactor_recalc_timer = 4 ;
122- // calculate new ADC factor
123- float can12V = mt_evc_dcdc-> GetElemValue ( 1 ); // DCDC voltage
124- if (StdMetrics. ms_v_env_charging12v -> AsBool ( false ))
124+ float can12V = mt_evc_dcdc-> GetElemValue ( 1 ) ;
125+ float adc12V = StdMetrics. ms_v_bat_12v_voltage -> AsFloat ( 0 . 0f ) ;
126+ float diff = fabs (can12V - adc12V);
127+ bool charging12v = StdMetrics. ms_v_env_charging12v -> AsBool ( false );
128+ if (diff > 0 . 1f && !m_ADCfactor_recalc && charging12v)
125129 {
126- ReCalcADCfactor (can12V, nullptr ); // nullptr = no Log-Output
127- ESP_LOGI (TAG , " Auto ADC recalibration started (%.2fV)" , can12V);
128- }
129- else
130+ ESP_LOGW (TAG , " 12V voltage difference detected: CAN=%.2fV, ADC=%.2fV, diff=%.2fV" , can12V, adc12V, diff);
131+ m_ADCfactor_recalc_timer = 2 ; // wait at least 2 min. before recalculation
132+ m_enable_calcADCfactor = true ;
133+ m_ADCfactor_recalc = true ; // recalculate ADC factor when 12V voltage difference detected
134+ }
135+ m_check12vadc = false ;
136+ }
137+ // if ADC factor recalculation is enabled, then check if it's time to recalculate the factor
138+ if (m_enable_calcADCfactor && m_ADCfactor_recalc)
139+ {
140+ if (--m_ADCfactor_recalc_timer == 0 )
130141 {
131- ESP_LOGW (TAG , " Error: Auto ADC recalibration, 12V voltage is not stable for ADC calibration! (%.2fV)" , can12V);
142+ m_ADCfactor_recalc = false ;
143+ m_ADCfactor_recalc_timer = 2 ;
144+ // calculate new ADC factor
145+ float can12V = mt_evc_dcdc->GetElemValue (1 ); // DCDC voltage
146+ if (StdMetrics.ms_v_env_charging12v ->AsBool (false ))
147+ {
148+ ReCalcADCfactor (can12V, nullptr ); // nullptr = no Log-Output
149+ ESP_LOGI (TAG , " Auto ADC recalibration started (%.2fV)" , can12V);
150+ }
151+ else
152+ {
153+ ESP_LOGW (TAG , " Error: Auto ADC recalibration, 12V voltage is not stable for ADC calibration! (%.2fV)" , can12V);
154+ }
132155 }
133156 }
134157 }
0 commit comments