Skip to content

Commit

Permalink
Update minor changes and with comments in code
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto Aldea committed Jun 28, 2023
1 parent 9e2803c commit fd894b0
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions firmware/Sources/APP/APP_CTRL/app_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ APP_CTRL_result_e APP_CtrlUpdate (MID_REG_control_s * mode, const MID_REG_meas_p
const MID_REG_limit_s * limits){
APP_CTRL_result_e res = APP_CTRL_RESULT_ERROR_INT;
MID_PWR_result_e internalRes = MID_PWR_RESULT_SUCCESS;
// internalRes = MID_PwrCalculateD0(meas->hsVolt, meas->lsVolt);
updateCtrlTime(&ctrl_time);
ctrl_status = checkLimit(mode, meas, ctrl_action, ctrl_time);

if (ctrl_status == limit_not_reached && internalRes == MID_PWR_RESULT_SUCCESS){
//check if limit is reached
//check if limit is reached, if not apply control
switch(mode->mode)
{
case MID_REG_MODE_WAIT:
// If change output to disable change also register to disable
internalRes = MID_PwrSetOutput(MID_PWR_Disable);
mode->outStatus = MID_PWR_Disable;
res = (internalRes == MID_PWR_RESULT_SUCCESS) ? APP_CTRL_RESULT_SUCCESS : APP_CTRL_RESULT_ERROR_INT;
Expand All @@ -278,29 +278,33 @@ APP_CTRL_result_e APP_CtrlUpdate (MID_REG_control_s * mode, const MID_REG_meas_p
res = (internalRes == MID_PWR_RESULT_SUCCESS) ? APP_CTRL_RESULT_SUCCESS : APP_CTRL_RESULT_ERROR_INT;
break;
default:
// If change output to disable change also register to disable
internalRes = MID_PwrSetOutput(MID_PWR_Disable);
mode->outStatus = MID_PWR_Disable;
res = APP_CTRL_RESULT_ERROR_INT;
break;
}
}else if(ctrl_status == limit_reached && internalRes == MID_PWR_RESULT_SUCCESS){

MID_REG_control_s newMode = {
MID_REG_DISABLED, // outStatus
MID_REG_MODE_IDLE, // mode
MID_REG_LIMIT_TIME, // limitType
0, // modeRef
0 // limRef
};

//First change output
// If change output to disable change also register to disable
internalRes = MID_PwrSetOutput(MID_PWR_Disable);
mode->outStatus = MID_PWR_Disable;
res = (internalRes == MID_PWR_RESULT_SUCCESS) ? APP_CTRL_RESULT_SUCCESS : APP_CTRL_RESULT_ERROR_INT;

//Then change the mode
if (res == APP_CTRL_RESULT_SUCCESS){
res = APP_CtrlApplyNewMode(&newMode, mode, meas);
ctrl_status = limit_already_reached;
}
}else if(ctrl_status == limit_already_reached){
//If no operation needed is success
res = APP_CTRL_RESULT_SUCCESS;
}else{
res = APP_CTRL_RESULT_ERROR_INT;
Expand All @@ -316,17 +320,22 @@ APP_CTRL_result_e APP_CtrlApplyNewMode (const MID_REG_control_s * newMode, MID_R
if (newMode->outStatus == MID_REG_DISABLED){
internalRes = MID_PwrSetOutput(MID_PWR_Disable);
}
//ctrl_action will receive if mode is charging or discharging
ctrl_action = calcNewAction(newMode, meas);
ctrl_status = limit_not_reached;
ctrl_time = 0;
memcpy(mode, newMode, sizeof(MID_REG_control_s));
//Enable PWR output for the modes that require power transfer
if ((newMode->mode == MID_REG_MODE_CV || newMode->mode == MID_REG_MODE_CP || newMode->mode == MID_REG_MODE_CC) &&
newMode->outStatus == MID_REG_ENABLED){
//Update DO when new mode is applied
internalRes = MID_PwrCalculateD0(meas->hsVolt, meas->lsVolt);
if (internalRes == MID_PWR_RESULT_SUCCESS){
internalRes = MID_PwrSetOutput(MID_PWR_Enable);
}
}else {
//If not in control mode, the output is always disabled
mode->outStatus == MID_REG_DISABLED;
}
res = (internalRes == MID_PWR_RESULT_SUCCESS) ? APP_CTRL_RESULT_SUCCESS : APP_CTRL_RESULT_ERROR_INT;

Expand Down

0 comments on commit fd894b0

Please sign in to comment.