diff --git a/firmware/open_evse/Gfi.cpp b/firmware/open_evse/Gfi.cpp index 470f2ab4..bf2cb30f 100644 --- a/firmware/open_evse/Gfi.cpp +++ b/firmware/open_evse/Gfi.cpp @@ -30,6 +30,7 @@ void gfi_isr() void Gfi::Init(uint8_t v6) { + is_v6 = v6; pin.init(GFI_REG,GFI_IDX,DigitalPin::INP); // GFI triggers on rising edge attachInterrupt(GFI_INTERRUPT,gfi_isr,RISING); @@ -38,13 +39,26 @@ void Gfi::Init(uint8_t v6) volatile uint8_t *reg = GFITEST_REG; volatile uint8_t idx = GFITEST_IDX; #ifdef OEV6 - if (v6) { + if (is_v6) { reg = V6_GFITEST_REG; - idx = V6_GFITEST_IDX; + idx = V6_GFITEST_IDX; } #endif // OEV6 pinTest.init(reg,idx,DigitalPin::OUT); -#endif +#ifdef DC_GFI_TEST +#ifdef OEV6 + if (v6) { + pinMode(V6_DC_TEST_PIN,OUTPUT); + } else { +#endif // OEV6 + volatile uint8_t *dcreg = DC_TEST_REG; + volatile uint8_t dcidx = DC_TEST_IDX; + pinDCTest.init(dcreg,dcidx,DigitalPin::OUT); +#ifdef OEV6 + } +#endif // OEV6 +#endif //DC_GFI_TEST +#endif //GFI_SELFTEST Reset(); } @@ -94,6 +108,49 @@ uint8_t Gfi::SelfTest() } if (i == 40) return 3; +#ifdef DC_GFI_TEST + if (testSuccess) { //no point continuing unless AC test was successful + testSuccess = 0; + // turn on DC test pin +#ifdef OEV6 + if (is_v6) { +#ifdef V6_DC_TEST_PIN + digitalWrite(V6_DC_TEST_PIN,HIGH); +#endif + } else { +#endif //OEV6 + pinDCTest.write(1); +#ifdef OEV6 + } +#endif //OEV6 + for(int i=0; !testSuccess && (i < GFI_TEST_CYCLES); i++) { + //just wait this time... + delayMicroseconds(GFI_PULSE_ON_US); + delayMicroseconds(GFI_PULSE_OFF_US); + } + //turn off the DC test pin +#ifdef OEV6 + if (is_v6) { +#ifdef V6_DC_TEST_PIN + digitalWrite(V6_DC_TEST_PIN,LOW); +#endif + } else { +#endif //OEV6 + pinDCTest.write(0); +#ifdef OEV6 + } +#endif //OEV6 + // wait for GFI pin to clear + for (i=0;i < 40;i++) { + WDT_RESET(); + if (!pin.read()) break; + delay(50); + } + if (i == 40) return 4; + } + //if testSuccess == 1 at this point then both tests were successful +#endif //DC_GFI_TEST + #ifndef OPENEVSE_2 // sometimes getting spurious GFI faults when testing just before closing // relay. diff --git a/firmware/open_evse/Gfi.h b/firmware/open_evse/Gfi.h index c3bcd2c9..deb8d013 100644 --- a/firmware/open_evse/Gfi.h +++ b/firmware/open_evse/Gfi.h @@ -25,6 +25,7 @@ class Gfi { DigitalPin pin; uint8_t m_GfiFault; + uint8_t is_v6; #ifdef GFI_SELFTEST uint8_t testSuccess; uint8_t testInProgress; @@ -32,7 +33,10 @@ class Gfi { public: #ifdef GFI_SELFTEST DigitalPin pinTest; -#endif +#ifdef DC_GFI_TEST + DigitalPin pinDCTest; +#endif //DC_GFI_TEST +#endif //GFI_SELFTEST Gfi() {} diff --git a/firmware/open_evse/J1772EvseController.cpp b/firmware/open_evse/J1772EvseController.cpp index cc971c0c..01f1119c 100644 --- a/firmware/open_evse/J1772EvseController.cpp +++ b/firmware/open_evse/J1772EvseController.cpp @@ -275,15 +275,27 @@ void J1772EVSEController::chargingOn() Serial.print("\nrelayCloseMs: ");Serial.println(m_relayCloseMs); Serial.print("relayHoldPwm: ");Serial.println(m_relayHoldPwm); // turn on charging pin to close relay +#ifdef V6_CHARGING_PIN digitalWrite(V6_CHARGING_PIN,HIGH); +#endif +#ifdef V6_CHARGING_PIN2 digitalWrite(V6_CHARGING_PIN2,HIGH); +#endif delay(m_relayCloseMs); // switch to PWM to hold closed +#ifdef V6_CHARGING_PIN analogWrite(V6_CHARGING_PIN,m_relayHoldPwm); +#endif +#ifdef V6_CHARGING_PIN2 analogWrite(V6_CHARGING_PIN2,m_relayHoldPwm); +#endif #else // !RELAY_PWM +#ifdef V6_CHARGING_PIN digitalWrite(V6_CHARGING_PIN,HIGH); +#endif +#ifdef V6_CHARGING_PIN2 digitalWrite(V6_CHARGING_PIN2,HIGH); +#endif #endif // RELAY_PWM } else { @@ -323,8 +335,12 @@ void J1772EVSEController::chargingOff() #ifdef RELAY_AUTO_PWM_PIN digitalWrite(RELAY_AUTO_PWM_PIN,LOW); #else // !RELAY_AUTO_PWM_PIN +#ifdef V6_CHARGING_PIN digitalWrite(V6_CHARGING_PIN,LOW); +#endif +#ifdef V6_CHARGING_PIN2 digitalWrite(V6_CHARGING_PIN2,LOW); +#endif #endif // RELAY_AUTO_PWM_PIN } else { @@ -967,8 +983,12 @@ void J1772EVSEController::Init() #ifdef OEV6 if (isV6()) { +#ifdef V6_CHARGING_PIN pinMode(V6_CHARGING_PIN,OUTPUT); +#endif +#ifdef V6_CHARGING_PIN2 pinMode(V6_CHARGING_PIN2,OUTPUT); +#endif } else { // !V6 #endif // OEV6 diff --git a/firmware/open_evse/open_evse.h b/firmware/open_evse/open_evse.h index ffecb5ba..acfd6279 100644 --- a/firmware/open_evse/open_evse.h +++ b/firmware/open_evse/open_evse.h @@ -175,6 +175,9 @@ extern AutoCurrentCapacityController g_ACCController; // If you loop a wire from the third GFI pin through the CT a few times and then to ground, // enable this. ADVPWR must also be defined. #define GFI_SELFTEST +// If you loop a single turn of wire from the 12V supply through a 2k resistor to the +// second DC relay pin, enable this for DC fault test +//#define DC_GFI_TEST // behavior specified by UL // 1) if enabled, POST failure will cause a hard fault until power cycled. @@ -487,15 +490,23 @@ extern AutoCurrentCapacityController g_ACCController; #define ACLINE2_REG &PIND #define ACLINE2_IDX 4 -#define V6_CHARGING_PIN 5 -#define V6_CHARGING_PIN2 6 - // digital Relay trigger pin +#define V6_CHARGING_PIN 5 #define CHARGING_REG &PINB #define CHARGING_IDX 0 + +#ifdef DC_GFI_TEST +// 6ma DC leakage test when this pin is high +#define V6_DC_TEST_PIN 6 +#define DC_TEST_REG &PIND +#define DC_TEST_IDX 7 +#else // digital Relay trigger pin for second relay +#define V6_CHARGING_PIN2 6 #define CHARGING2_REG &PIND #define CHARGING2_IDX 7 +#endif //DC_GFI_TEST + //digital Charging pin for AC relay #define CHARGINGAC_REG &PINB #define CHARGINGAC_IDX 1 diff --git a/platformio.ini b/platformio.ini index 608d3a9a..8ad4d9ed 100644 --- a/platformio.ini +++ b/platformio.ini @@ -40,7 +40,6 @@ eu_build_flags = -D MAX_CURRENT_CAPACITY_L2=32 -D OVERCURRENT_THRESHOLD=5 -D OVERCURRENT_TIMEOUT=10000UL - -D DEFAULT_SERVICE_LEVEL=2 [env:openevse_1-8-3] platform = atmelavr@3.4.0 @@ -76,6 +75,15 @@ build_src_flags= -D MV_FOR_L2=230000L -D 'VERSION="${common.version}.EU"' +# EU OpenEVSE with DC RCD +[env:openevse_eudc] +extends = env:openevse +build_src_flags= + ${common.eu_build_flags} + -D DC_GFI_TEST + -D MV_FOR_L2=240000L + -D 'VERSION="${common.version}.EUDC"' + # Non-tethered T2 EmonEVSE single-phase [env:emonevse] extends = env:openevse