comparison src/cs/drivers/drv_app/fchg/fchg_process.c @ 363:cce24b9de6db

FCHG: CV control loop implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 29 Dec 2017 07:28:29 +0000
parents 4c3d05866531
children 44795dbadbae
comparison
equal deleted inserted replaced
362:4c3d05866531 363:cce24b9de6db
176 176
177 static int overvoltage_end_charge_check(void) 177 static int overvoltage_end_charge_check(void)
178 { 178 {
179 if (pwr_ctrl->batt_mv < pwr_ctrl->config.overvoltage) 179 if (pwr_ctrl->batt_mv < pwr_ctrl->config.overvoltage)
180 return 0; 180 return 0;
181 if (pwr_ctrl->cv_dac_curr >= pwr_ctrl->cv_dac_init) 181 if (pwr_ctrl->cv_dac_curr !=
182 return 0; 182 (pwr_ctrl->cv_dac_init - pwr_ctrl->config.cv_dac_max_decr))
183 if ((pwr_ctrl->cv_dac_init - pwr_ctrl->cv_dac_curr) < 183 return;
184 pwr_ctrl->config.cv_dac_max_decr)
185 return 0;
186 rvf_send_trace("Stopping charge by overvoltage condition", 40, 184 rvf_send_trace("Stopping charge by overvoltage condition", 40,
187 NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, FCHG_USE_ID); 185 NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, FCHG_USE_ID);
188 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0); 186 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0);
189 pwr_init_discharge(); 187 pwr_init_discharge();
190 pwr_ctrl->state = FCHG_STATE_READY_TO_RECHARGE; 188 pwr_ctrl->state = FCHG_STATE_READY_TO_RECHARGE;
191 return 1; 189 return 1;
192 } 190 }
193 191
192 static void cv_ctrl_loop_high_check(void)
193 {
194 if (pwr_ctrl->batt_mv < pwr_ctrl->config.cv_ctrl_loop_high) {
195 pwr_ctrl->cv_high_vbat_count = 0;
196 return;
197 }
198 pwr_ctrl->cv_high_vbat_count++;
199 if (pwr_ctrl->cv_high_vbat_count < pwr_ctrl->config.cv_samples_needed)
200 return;
201 if (pwr_ctrl->cv_dac_curr ==
202 (pwr_ctrl->cv_dac_init - pwr_ctrl->config.cv_dac_max_decr))
203 return;
204 pwr_ctrl->cv_dac_curr--;
205 ABB_Write_Register_on_page(PAGE0, CHGREG, pwr_ctrl->cv_dac_curr);
206 rvf_send_trace("Sub CV DAC", 10, pwr_ctrl->cv_dac_curr,
207 RV_TRACE_LEVEL_DEBUG_MEDIUM, FCHG_USE_ID);
208 pwr_ctrl->cv_high_vbat_count = 0;
209 }
210
211 static void cv_ctrl_loop_low_check(void)
212 {
213 if (pwr_ctrl->batt_mv >= pwr_ctrl->config.cv_ctrl_loop_low) {
214 pwr_ctrl->cv_low_vbat_count = 0;
215 return;
216 }
217 pwr_ctrl->cv_low_vbat_count++;
218 if (pwr_ctrl->cv_low_vbat_count < pwr_ctrl->config.cv_samples_needed)
219 return;
220 if (pwr_ctrl->cv_dac_curr ==
221 (pwr_ctrl->cv_dac_init + pwr_ctrl->config.cv_dac_max_incr))
222 return;
223 pwr_ctrl->cv_dac_curr++;
224 ABB_Write_Register_on_page(PAGE0, CHGREG, pwr_ctrl->cv_dac_curr);
225 rvf_send_trace("Add CV DAC", 10, pwr_ctrl->cv_dac_curr,
226 RV_TRACE_LEVEL_DEBUG_MEDIUM, FCHG_USE_ID);
227 pwr_ctrl->cv_low_vbat_count = 0;
228 }
229
194 void pwr_process_adc(struct pwr_adc_ind_s *msg) 230 void pwr_process_adc(struct pwr_adc_ind_s *msg)
195 { 231 {
196 pwr_ctrl->batt_mv = madc_vbat_2_physical(msg->data[0]); 232 pwr_ctrl->batt_mv = madc_vbat_2_physical(msg->data[0]);
197 233
198 switch (pwr_ctrl->state) { 234 switch (pwr_ctrl->state) {
261 } 297 }
262 if (cv_ichg_process(msg->data[2])) 298 if (cv_ichg_process(msg->data[2]))
263 return; 299 return;
264 if (overvoltage_end_charge_check()) 300 if (overvoltage_end_charge_check())
265 return; 301 return;
266 /* DAC control loop will go here */ 302 cv_ctrl_loop_high_check();
303 cv_ctrl_loop_low_check();
267 return; 304 return;
268 default: 305 default:
269 rvf_send_trace("Invalid state in pwr_process_adc()", 32, 306 rvf_send_trace("Invalid state in pwr_process_adc()", 32,
270 pwr_ctrl->state, RV_TRACE_LEVEL_ERROR, 307 pwr_ctrl->state, RV_TRACE_LEVEL_ERROR,
271 FCHG_USE_ID); 308 FCHG_USE_ID);