Skip to content

Commit

Permalink
Added StandAlone AC charge mode
Browse files Browse the repository at this point in the history
Removed redundant public functions
Replaced magic numbers by enum
Small formatting changes
  • Loading branch information
jsphuebner committed Nov 20, 2024
1 parent 64f3b03 commit 907a922
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 31 deletions.
46 changes: 22 additions & 24 deletions ccs/acOBC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,6 @@ static uint8_t debounceCounterFivePercentPwm = 0;
static bool ButtonStopAC = false;
static uint16_t StopAcTimer = 0;

void acOBC_activateBasicAcCharging(void)
{
/* This function shall be called if we detect a CP PWM in the "analog range". */
isBasicAcCharging = 1;
}

void acOBC_deactivateBasicAcCharging(void)
{
/* This function shall be called whenever there is an hint that we are connected to something else that an analog AC charger. */
isBasicAcCharging = 0;
}

uint8_t acOBC_isBasicAcCharging(void)
{
return isBasicAcCharging;
Expand All @@ -56,7 +44,7 @@ static void evaluateProximityPilot(void)
float U_refAdc, U_pull, U_meas, Rv, R;
float iLimit;
uint8_t blPlugPresent;

if (wakecontrol_isPpMeasurementInvalid()) {
/* in case there are conditions which corrupt the PP resistance measurement, we discard the measurement,
and just live with the last valid value. Strategy: Better an old, valid value than a corrupted value. */
Expand Down Expand Up @@ -138,7 +126,7 @@ static void evaluateProximityPilot(void)
iLimit = 63; /* 100ohm is 63A */
}
Param::SetFloat(Param::CableCurrentLimit, iLimit);

/* Step 4: Provide the PlugPresent (e.g. for the feature "driveInhibit") */
blPlugPresent = R < 5000; /* Design decision: The plug is considered as present if the PP resistance is below 5kohms. */
Param::SetInt(Param::PlugPresent, blPlugPresent); /* 0: no plug present. 1: plug detected. */
Expand Down Expand Up @@ -218,7 +206,12 @@ void acOBC_calculateCurrentLimit(void)
}
else
{
acOBC_deactivateBasicAcCharging(); /* in case we have stable 5% PWM, this is no basic AC charging. */
isBasicAcCharging = false; /* in case we have stable 5% PWM, this is no basic AC charging. */

// If the charger or VCU does not communicate with Foccci go straight to complete mode
// as soon as an invalid/zero AC current limit is detected
if (Param::GetInt(Param::AcChargeControl) == ACM_STANDALONE)
Param::SetInt(Param::AcObcState, OBC_COMPLETE);
}
}
else if (cpDuty_Percent<10)
Expand Down Expand Up @@ -256,7 +249,12 @@ void acOBC_calculateCurrentLimit(void)
}
else
{
acOBC_activateBasicAcCharging(); /* in case of valid AC charging PWM, we switch to the AC charging mode. */
isBasicAcCharging = true; /* in case of valid AC charging PWM, we switch to the AC charging mode. */

// If the charger or VCU does not communicate with Foccci go straight to charge mode
// as soon as valid AC current limit is detected
if (Param::GetInt(Param::AcChargeControl) == ACM_STANDALONE)
Param::SetInt(Param::AcObcState, OBC_CHARGE);
}
}
else
Expand All @@ -283,7 +281,7 @@ static void triggerActions()
}
}

if(ButtonStopAC == true)
if (ButtonStopAC)
{
requestedState = OBC_IDLE; // force idle when we are stopped due to button
StopAcTimer++; //increase very 100ms
Expand All @@ -306,9 +304,9 @@ static void triggerActions()
case OBC_IDLE:
//always turn off stateB here
hardwareInterface_setStateB();
Param::SetInt(Param::PortState,0x2); //set PortState to Ready, combined with CP current limit signaling to VCU for AC charging
Param::SetInt(Param::PortState, PS_READY); //set PortState to Ready, combined with CP current limit signaling to VCU for AC charging
//Unlock connector when coming here from any other state
if (Param::GetInt(Param::LockState) == LOCK_CLOSED && Param::GetInt(Param::AllowUnlock) == 1)//only unlock if allowed and lock is locked
if (Param::GetInt(Param::LockState) == LOCK_CLOSED && Param::GetBool(Param::AllowUnlock))//only unlock if allowed and lock is locked
{
if(Param::GetInt(Param::ActuatorTest) == 0)
{
Expand All @@ -328,7 +326,7 @@ static void triggerActions()
case OBC_PAUSE:
break;
case OBC_ERROR:
Param::SetInt(Param::PortState,0x7); //set PortState to Error
Param::SetInt(Param::PortState, PS_PORTERROR); //set PortState to Error
break;
case OBC_COMPLETE:
//always turn off stateC in these states
Expand All @@ -347,7 +345,7 @@ static void triggerActions()
if(Param::GetInt(Param::LockState) == LOCK_CLOSED) //Do not allow Request for AC power without locking
{
hardwareInterface_setStateC();
Param::SetInt(Param::PortState,0x3); //set PortState to AcCharging
Param::SetInt(Param::PortState, PS_CHARGING_AC); //set PortState to AcCharging
}
break;
}
Expand All @@ -368,8 +366,8 @@ static void triggerActions()
uint8_t cpDuty_Percent = (uint8_t)Param::GetFloat(Param::ControlPilotDuty);
if(cpDuty_Percent<3)
{
Param::SetInt(Param::PortState,0x1); //set PortState to Plugged In due to dropping way of valid CP - !!!Should not interfere with CCS charging
if (Param::GetInt(Param::LockState) == LOCK_CLOSED && Param::GetInt(Param::AllowUnlock) == 1)//only unlock if allowed and lock is locked
Param::SetInt(Param::PortState, PS_PLUGGEDIN); //set PortState to Plugged In due to dropping way of valid CP - !!!Should not interfere with CCS charging
if (Param::GetInt(Param::LockState) == LOCK_CLOSED && Param::GetBool(Param::AllowUnlock))//only unlock if allowed and lock is locked
{
if(Param::GetInt(Param::ActuatorTest) == 0)
{
Expand All @@ -379,7 +377,7 @@ static void triggerActions()
}
else if(Param::GetFloat(Param::CableCurrentLimit) < 1)
{
Param::SetInt(Param::PortState,0x0); //set PortState to Idle NO PP or CP present thus unplugged
Param::SetInt(Param::PortState, PS_IDLE); //set PortState to Idle NO PP or CP present thus unplugged
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions ccs/acOBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

extern void acOBC_mainfunction(void);
extern uint8_t acOBC_getRGB(void);
extern void acOBC_activateBasicAcCharging(void);
extern void acOBC_deactivateBasicAcCharging(void);
extern uint8_t acOBC_isBasicAcCharging(void);


Expand Down
30 changes: 25 additions & 5 deletions include/param_prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

#include "myLogging.h"

//Next param id (increase when adding new parameter!): 33
//Next param id (increase when adding new parameter!): 34
//Next value Id: 2035
/* category name unit min max default id */
#define PARAM_LIST \
Expand All @@ -65,12 +65,13 @@
PARAM_ENTRY(CAT_CHARGE, MaxVoltage, "V", 0, 1000, 410, 18 ) \
PARAM_ENTRY(CAT_CHARGE, MaxCurrent, "A", 0, 500, 125, 19 ) \
PARAM_ENTRY(CAT_CHARGE, MaxPinTemperature, "°C", 0, 120, 70, 31 ) \
PARAM_ENTRY(CAT_CHARGE, AcChargeControl, ACMODES, 0, 1, 0, 33 ) \
TESTP_ENTRY(CAT_CHARGE, TargetVoltage, "V", 0, 1000, 0, 3 ) \
TESTP_ENTRY(CAT_CHARGE, ChargeCurrent, "A", 0, 500, 0, 4 ) \
TESTP_ENTRY(CAT_CHARGE, soc, "%", 0, 100, 0, 5 ) \
TESTP_ENTRY(CAT_CHARGE, BatteryVoltage, "V", 0, 1000, 0, 6 ) \
TESTP_ENTRY(CAT_CHARGE, enable, OFFON, 0, 1, 1, 23 ) \
TESTP_ENTRY(CAT_CHARGE, AcObcState, ACOBCSTT, 0, 2, 0, 29 ) \
TESTP_ENTRY(CAT_CHARGE, AcObcState, ACOBCSTT, 0, 5, 0, 29 ) \
PARAM_ENTRY(CAT_TEST, DemoVoltage, "V", 0, 500, 0, 20 ) \
PARAM_ENTRY(CAT_TEST, DemoControl, DEMOCTRL, 0, 511, 0, 25 ) \
TESTP_ENTRY(CAT_TEST, ActuatorTest, ACTEST, 0, 7, 0, 9 ) \
Expand All @@ -84,7 +85,7 @@
VALUE_ENTRY(EvseCurrent, "A", 2010 ) \
VALUE_ENTRY(TempLimitedCurrent, "A", 2027 ) \
VALUE_ENTRY(EVTargetCurrent, "A", 2029 ) \
VALUE_ENTRY(LimitationReason, LIMITATIONREASONS, 2028 ) \
VALUE_ENTRY(LimitationReason, LIMITREASONS, 2028 ) \
VALUE_ENTRY(InletVoltage, "V", 2007 ) \
VALUE_ENTRY(EvseMaxCurrent, "A", 2008 ) \
VALUE_ENTRY(EvseMaxVoltage, "V", 2009 ) \
Expand All @@ -107,7 +108,7 @@
VALUE_ENTRY(StopReason, STOPREASONS, 2017 ) \
VALUE_ENTRY(checkpoint, "dig", 2015 ) \
VALUE_ENTRY(CanWatchdog, "dig", 2016 ) \
VALUE_ENTRY(CanAwake, OFFON, 2032 ) \
VALUE_ENTRY(CanAwake, OFFON, 2032 ) \
VALUE_ENTRY(ButtonPushed, OFFON, 2033 ) \
VALUE_ENTRY(cpuload, "%", 2094 )

Expand All @@ -120,13 +121,14 @@
#define CANSPEEDS "0=125k, 1=250k, 2=500k, 3=800k, 4=1M"
#define OFFON "0=Off, 1=On"
#define DEMOCTRL "0=CAN, 234=StandAlone"
#define ACMODES "0=CANRemoteControlled, 1=StandAlone"
#define STOPREASONS "0=None, 1=Button, 2=MissingEnable, 3=CANTimeout, 4=ChargerShutdown, 5=AccuFull, 6=ChargerEmergency, 7=InletOverheat, 8=EvseMalfunction"
#define WAKEUP "0=Level, 1=Pulse, 2=LevelOnValidCp, 3=PulseOnValidCp, 4=LevelOnValidPP"
#define CAT_HARDWARE "Hardware Config"
#define CAT_CHARGE "Charge parameters"
#define CAT_COMM "Communication"
#define CAT_TEST "Testing"
#define LIMITATIONREASONS "0=None, 1=InletHot"
#define LIMITREASONS "0=None, 1=InletHot"
#define PPVARIANT "0=Foccci4.1_3V3_1k, 1=Foccci4.2_5V_330up_3000down, 2=Foccci4.5_5V_330up_no_down"
#define ACOBCSTT "0=Idle, 1=Lock, 2=Charging, 3=Pause, 4=Complete, 5=Error"
#define PORTSTAT "0=Idle, 1=PluggedIn, 2=Ready, 3=ChargingAC, 4=ChargingDC, 5=Stopping, 6=Unlock, 7=PortError"
Expand Down Expand Up @@ -155,6 +157,24 @@ enum acobcstate
OBC_ERROR = 5
};

enum portstate
{
PS_IDLE = 0,
PS_PLUGGEDIN = 1,
PS_READY = 2,
PS_CHARGING_AC = 3,
PS_CHARGING_DC = 4,
PS_STOPPING = 5,
PS_UNLOCK = 6,
PS_PORTERROR = 7
};

enum acmodes
{
ACM_CANCONTROLLED = 0,
ACM_STANDALONE = 1
};

enum _wakeupfuncs
{
WAKEUP_LEVEL = 0,
Expand Down

0 comments on commit 907a922

Please sign in to comment.