Skip to content

Commit

Permalink
implement over current protection
Browse files Browse the repository at this point in the history
  • Loading branch information
lincomatic committed May 18, 2018
1 parent 1c51eea commit 60b5083
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 2 deletions.
3 changes: 3 additions & 0 deletions firmware/open_evse/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Change Log
-> don't allow PP to set current capacity higher than EEPROM
- PP code cleanup
- don't allow SetCurrentCapacity() to go above PP value
- implement over current protection. if OVERCURRENT_THRESHOLD is set,
then if EV draws >= OVERCURRENT_THRESHOLD amps for >=
OVERCURRENT_TIMEOUT ms -> hard fault

20180417 SCL
- fix compile errors when no GFI and ADVPWR. Must also undef UL_COMPLIANT,
Expand Down
26 changes: 25 additions & 1 deletion firmware/open_evse/J1772EvseController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,10 @@ void J1772EVSEController::Init()

m_AmmeterReading = 0;
m_ChargingCurrent = 0;
// m_LastAmmeterReadMs = 0;
#ifdef OVERCURRENT_THRESHOLD
m_OverCurrentStartMs = 0;
#endif //OVERCURRENT_THRESHOLD

#endif // AMMETER

#ifdef VOLTMETER
Expand Down Expand Up @@ -1607,6 +1610,27 @@ if (TempChkEnabled()) {
m_ElapsedChargeTimePrev = m_ElapsedChargeTime;
m_ElapsedChargeTime = now() - m_ChargeOnTime;

#ifdef OVERCURRENT_THRESHOLD
//testing m_ChargingCurrent = (m_CurrentCapacity+OVERCURRENT_THRESHOLD+12)*1000L;
if (m_ChargingCurrent >= ((m_CurrentCapacity+OVERCURRENT_THRESHOLD)*1000L)) {
if (m_OverCurrentStartMs) { // already in overcurrent state
if ((millis()-m_OverCurrentStartMs) >= OVERCURRENT_TIMEOUT) {
//
// overcurrent for too long. stop charging and hard fault
//
// spin until EV is disconnected
m_EvseState = EVSE_STATE_OVER_CURRENT;
HardFault();

m_OverCurrentStartMs = 0; // clear overcurrent
}
}
else {
m_OverCurrentStartMs = millis();
}
}
#endif // OVERCURRENT_THRESHOLD

#ifdef TEMPERATURE_MONITORING
if(TempChkEnabled()) {
if (m_ElapsedChargeTime != m_ElapsedChargeTimePrev) {
Expand Down
6 changes: 5 additions & 1 deletion firmware/open_evse/J1772EvseController.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
#define EVSE_STATE_STUCK_RELAY 0x08 //stuck relay
#define EVSE_STATE_GFI_TEST_FAILED 0x09 // GFI self-test failure
#define EVSE_STATE_OVER_TEMPERATURE 0x0A // over temperature error shutdown
#define EVSE_FAULT_STATE_END EVSE_STATE_OVER_TEMPERATURE
#define EVSE_STATE_OVER_CURRENT 0x0B // over current error shutdown
#define EVSE_FAULT_STATE_END EVSE_STATE_OVER_CURRENT

#define EVSE_STATE_SLEEPING 0xfe // waiting for timer
#define EVSE_STATE_DISABLED 0xff // disabled
Expand Down Expand Up @@ -172,6 +173,9 @@ class J1772EVSEController {
#ifdef MENNEKES_LOCK
MennekesLock m_MennekesLock;
#endif // MENNEKES_LOCK
#ifdef OVERCURRENT_THRESHOLD
unsigned long m_OverCurrentStartMs;
#endif // OVERCURRENT_THRESHOLD

#ifdef ADVPWR
// power states for doPost() (active low)
Expand Down
1 change: 1 addition & 0 deletions firmware/open_evse/Language_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@
#define STR_LEVEL_2 "Level 2 (240V)"
#define STR_L1 "L1"
#define STR_L2 "L2"
#define STR_OVER_CURRENT "OVERCURRENT"
//#endif
11 changes: 11 additions & 0 deletions firmware/open_evse/open_evse.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ extern AutoCurrentCapacityController g_ACCController;
// not yet #define TEMPERATURE_MONITORING_NY

#ifdef AMMETER

// if OVERCURRENT_THRESHOLD is defined, then EVSE will hard fault in
// the event that the EV is pulling more current than it's allowed to
// declare overcurrent when charging amps > pilot amps + OVERCURRENT_THRESHOLD
#define OVERCURRENT_THRESHOLD 5 // A
// go to error state overcurrent by OVERCURRENT_THRESHOLD amps
// for OVERCURRENT_TIMEOUT ms
#define OVERCURRENT_TIMEOUT 5000UL // ms



// kWh Recording feature depends upon #AMMETER support
// comment out KWH_RECORDING to have the elapsed time and time of day displayed on the second line of the LCD
#define KWH_RECORDING
Expand Down
13 changes: 13 additions & 0 deletions firmware/open_evse/open_evse.ino
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,19 @@ void OnboardDisplay::Update(int8_t updmode)
#endif
break;
#endif //TEMPERATURE_MONITORING
#ifdef OVERCURRENT_THRESHOLD
case EVSE_STATE_OVER_CURRENT:
SetGreenLed(0);
SetRedLed(1);
#ifdef LCD16X2 //Adafruit RGB LCD
LcdSetBacklightColor(RED);
LcdPrint_P(0,g_psSvcReq);
strcpy_P(g_sTmp,g_psOverCurrent);
sprintf(g_sTmp+strlen(g_sTmp)," %dA",(int)(g_EvseController.GetChargingCurrent()/1000-g_EvseController.GetCurrentCapacity()));
LcdPrint(1,g_sTmp);
#endif
break;
#endif // OVERCURRENT_THRESHOLD
case EVSE_STATE_NO_GROUND:
SetGreenLed(0);
SetRedLed(1);
Expand Down
4 changes: 4 additions & 0 deletions firmware/open_evse/strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,7 @@ const char *g_sMaxCurrentFmt = STRF_MAX_CURRENT;
const char g_psSetDateTime[] PROGMEM = STR_SET_DATE_TIME;
const char *g_DelayMenuItems[] = STR_YESNO_SETSTART_SETSTOP;
#endif // DELAYTIMER_MENU

#ifdef OVERCURRENT_THRESHOLD
const char g_psOverCurrent[] PROGMEM = STR_OVER_CURRENT;
#endif // OVERCURRENT_THRESHOLD
4 changes: 4 additions & 0 deletions firmware/open_evse/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,7 @@ extern const char *g_sMaxCurrentFmt;
extern const char g_psSetDateTime[] PROGMEM;
extern const char *g_DelayMenuItems[];
#endif // DELAYTIMER_MENU

#ifdef OVERCURRENT_THRESHOLD
extern const char g_psOverCurrent[] PROGMEM;
#endif // OVERCURRENT_THRESHOLD

0 comments on commit 60b5083

Please sign in to comment.