Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to use Relay2 output for DC GFI test #43

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 60 additions & 3 deletions firmware/open_evse/Gfi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion firmware/open_evse/Gfi.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@
class Gfi {
DigitalPin pin;
uint8_t m_GfiFault;
uint8_t is_v6;
#ifdef GFI_SELFTEST
uint8_t testSuccess;
uint8_t testInProgress;
#endif // GFI_SELFTEST
public:
#ifdef GFI_SELFTEST
DigitalPin pinTest;
#endif
#ifdef DC_GFI_TEST
DigitalPin pinDCTest;
#endif //DC_GFI_TEST
#endif //GFI_SELFTEST

Gfi() {}

Expand Down
20 changes: 20 additions & 0 deletions firmware/open_evse/J1772EvseController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions firmware/open_evse/open_evse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [email protected]
Expand Down Expand Up @@ -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
Expand Down