Skip to content

Commit

Permalink
gfi clear timeout attempts implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlyubimov committed Jul 5, 2017
1 parent 8828fef commit 765cd45
Show file tree
Hide file tree
Showing 3 changed files with 1,437 additions and 1,396 deletions.
12 changes: 12 additions & 0 deletions Hydra_EVSE/Hydra_EVSE.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@

#endif


#ifdef QUICK_CYCLING_WORKAROUND

// How many minutes do we wait after one car finishes before raising the other pilot?
Expand Down Expand Up @@ -130,6 +131,7 @@
#define STATUS_ERR_MASK ( -1u >> UINT_BITS - 3 << 6)
#define STATUS_ERR_F ( 0x0u << 6 )
#define STATUS_ERR_O ( 0x1u << 6 )
// gfi
#define STATUS_ERR_G ( 0x2u << 6 )
#define STATUS_ERR_T ( 0x3u << 6 )
#define STATUS_ERR_R ( 0x4u << 6 )
Expand All @@ -151,6 +153,14 @@
#define GFI_TEST_CLEAR_TIME 100 // Takes the GFCI this long to clear
#define GFI_TEST_DEBOUNCE_TIME 400 // Delay extra time after GFCI clears to make sure it stays.

//After each GFCI event we will retry charging up to 4 times after a 15 minute
// delay per event. (UL 2231)
#define GFI_CLEAR_MS (15 * 60)
// debug
//#define GFI_CLEAR_MS (3 * 60)
#define GFI_CLEAR_ATTEMPTS 4


// These are the expected analogRead() ranges for pilot read-back from the cars.
// These are calculated from the expected voltages seen through the dividor network,
// then scaling those voltages for 0-1024.
Expand Down Expand Up @@ -345,6 +355,8 @@ struct timeouts_struct {
unsigned long sequential_pilot_timeout;
unsigned long button_press_time, button_debounce_time;
volatile unsigned long relay_change_time;
// last gfi time
unsigned long gfi_time;

timeout_struct() {
clear();
Expand Down
51 changes: 37 additions & 14 deletions Hydra_EVSE/Hydra_EVSE.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ unsigned char currentMenuChoices[] = { 12, 16, 20, 24, 28, 30, 32, 36, 40, 44, 5
#define LAST_YEAR 2020


// Time zone rules.
// Time zone rules.
// Use US_DST_RULES macro for US, EU_... for EU, and AU_... for Australia. Uncomment only one of
// those as applicabble.
US_DST_RULES(dstRules);
Expand Down Expand Up @@ -96,6 +96,9 @@ car_struct cars[] =
// TODO: in theory once we remove symmetry duplication in the code, we won't need this.
car_struct &car_a(cars[0]), &car_b(cars[1]);
timeouts_struct timeouts;
// We cannot make it part of timeouts since errors clear all pending timeouts.
unsigned char gfi_count;


unsigned long last_state_log;
unsigned char &operatingMode(persisted.operatingMode), sequential_mode_tiebreak;
Expand Down Expand Up @@ -429,8 +432,14 @@ void error(unsigned int status)
// (that is, turn off the oscillator) whenever we want.
// Stop flipping, one way or another
unsigned int car = status & CAR_MASK;
timeouts.sequential_pilot_timeout = 0;
if (car == BOTH || car == CAR_A)
timeouts.clear();

// kick off gfi timer
if ( (status & STATUS_MASK) == STATUS_ERR_G && gfi_count++ < GFI_CLEAR_ATTEMPTS) {
timeouts.gfi_time = millis();
}

if ( car == BOTH || car == CAR_A)
{
car_a.setPilot(HIGH);
if (car_a.last_state != STATE_E)
Expand Down Expand Up @@ -1171,7 +1180,7 @@ void doClockMenu(boolean initialize)
// The underlying system clock is always winter time.
// Note that setting the time during the repeated hour in
// the fall will assume winter time - the hour will NOT repeat.
// if (enable_dst) toSet = dst.toUTC(toSet);
// if (enable_dst) toSet = dst.toUTC(toSet);
setTime(toSet);
RTC.set(toSet);
doMenuFunc = doMenu;
Expand Down Expand Up @@ -1758,6 +1767,7 @@ void setup()
car_b.setRelay(LOW);

timeouts.clear();
gfi_count = 0;
last_minute = 99;
#ifdef QUICK_CYCLING_WORKAROUND
pilot_release_holdoff_time = 0;
Expand Down Expand Up @@ -1842,6 +1852,11 @@ void car_struct::loopCheckPilot(unsigned int car_state) {
// will take us back to state A.
last_state = DUNNO;
logInfo(P("Car %c disconnected, clearing error"), carLetter());
timeouts.clear();

// clear gfi counts only if both cars are disconnected.
if (them.last_state == STATE_A) gfi_count = 0;

}
else
{
Expand Down Expand Up @@ -1886,6 +1901,10 @@ void car_struct::loopCheckPilot(unsigned int car_state) {
sequential_mode_transition(car_state);
break;
}
} else if ( ! paused && timeouts.gfi_time > 0 && timeouts.gfi_time + GFI_CLEAR_MS < millis()) {
timeouts.clear();
// enable transition next iteration
for (int i = 0; i < 2; i++ ) cars[i].last_state = DUNNO;
}

}
Expand Down Expand Up @@ -1989,18 +2008,18 @@ void car_struct::loopCheckDelayedTransition() {
}
}

// This switches offer, sequential mode only, from a current car in mode B to the other car currently
// This switches offer, sequential mode only, from a current car in mode B to the other car currently
// also in mode B, based on offer timeout.
void car_struct::loopSeqHandover(unsigned long nowMs) {
{
logInfo(P("Sequential mode offer timeout, moving offer to %s"), car_str(CAR_B));
// move the pilot offer.
setPilot(HIGH);
them.setPilot(FULL);
timeouts.sequential_pilot_timeout = nowMs;
displayStatus(car | (seq_done ? STATUS_DONE : STATUS_WAIT));
displayStatus(them.car | STATUS_OFF );
}
{
logInfo(P("Sequential mode offer timeout, moving offer to %s"), car_str(CAR_B));
// move the pilot offer.
setPilot(HIGH);
them.setPilot(FULL);
timeouts.sequential_pilot_timeout = nowMs;
displayStatus(car | (seq_done ? STATUS_DONE : STATUS_WAIT));
displayStatus(them.car | STATUS_OFF );
}
}

///////////////////////////////////////////////////////////
Expand All @@ -2023,6 +2042,7 @@ void loop()
if (gfiTriggered)
{
logInfo(P("GFI fault detected"));
timeouts.clear();
error(BOTH | STATUS_ERR | STATUS_ERR_G);
gfiTriggered = false;
}
Expand Down Expand Up @@ -2107,6 +2127,7 @@ void loop()
{
if (!paused)
{
timeouts.clear();
if (operatingMode == MODE_SEQUENTIAL)
{
// remember which car was active
Expand Down Expand Up @@ -2136,6 +2157,8 @@ void loop()
{
car_a.last_state = DUNNO;
car_b.last_state = DUNNO;
// clear all pending events.
timeouts.clear();
}
paused = false;
}
Expand Down
Loading

0 comments on commit 765cd45

Please sign in to comment.