Skip to content

Commit

Permalink
Support non v6 boards
Browse files Browse the repository at this point in the history
  • Loading branch information
kimble4 committed Sep 24, 2024
1 parent 8a97e9e commit 9a2b46b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 19 deletions.
47 changes: 33 additions & 14 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,24 +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_GFCI_TEST
//volatile uint8_t *dcreg = DC_TEST_REG;
//volatile uint8_t dcidx = DCTEST_IDX;
#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
}
#else
//pinDCTest.init(reg,idx,DigitalPin::OUT);
#endif // OEV6
#endif //DC_GFCI_TEST
#endif //DC_GFI_TEST
#endif //GFI_SELFTEST

Reset();
}
Expand Down Expand Up @@ -105,22 +108,38 @@ uint8_t Gfi::SelfTest()
}
if (i == 40) return 3;

#ifdef DC_GFCI_TEST
#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);
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
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();
Expand All @@ -130,7 +149,7 @@ uint8_t Gfi::SelfTest()
if (i == 40) return 4;
}
//if testSuccess == 1 at this point then both tests were successful
#endif //DC_GFCI_TEST
#endif //DC_GFI_TEST

#ifndef OPENEVSE_2
// sometimes getting spurious GFI faults when testing just before closing
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
6 changes: 3 additions & 3 deletions firmware/open_evse/open_evse.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ extern AutoCurrentCapacityController g_ACCController;
#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_GFCI_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 @@ -495,7 +495,7 @@ extern AutoCurrentCapacityController g_ACCController;
#define CHARGING_REG &PINB
#define CHARGING_IDX 0

#ifdef DC_GFCI_TEST
#ifdef DC_GFI_TEST
// 6ma DC leakage test when this pin is high
#define V6_DC_TEST_PIN 6
#define DC_TEST_REG &PIND
Expand All @@ -505,7 +505,7 @@ extern AutoCurrentCapacityController g_ACCController;
#define V6_CHARGING_PIN2 6
#define CHARGING2_REG &PIND
#define CHARGING2_IDX 7
#endif //DC_GFCI_TEST
#endif //DC_GFI_TEST

//digital Charging pin for AC relay
#define CHARGINGAC_REG &PINB
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ build_src_flags=
extends = env:openevse
build_src_flags=
${common.eu_build_flags}
-D DC_GFCI_TEST
-D DC_GFI_TEST
-D MV_FOR_L2=240000L
-D 'VERSION="${common.version}.EUDC"'

Expand Down

0 comments on commit 9a2b46b

Please sign in to comment.