diff --git a/firmware/open_evse/Adafruit_TMP007.cpp b/firmware/open_evse/Adafruit_TMP007.cpp index 5e16ca47..83892e6c 100644 --- a/firmware/open_evse/Adafruit_TMP007.cpp +++ b/firmware/open_evse/Adafruit_TMP007.cpp @@ -15,6 +15,8 @@ ****************************************************/ #include "open_evse.h" + +#ifdef TMP007_IS_ON_I2C #include //#define TESTDIE 0x0C78 @@ -149,3 +151,4 @@ void Adafruit_TMP007::write16(uint8_t a, uint16_t d) { #endif Wire.endTransmission(); // end transmission } +#endif // TMP007_IS_ON_I2C diff --git a/firmware/open_evse/CHANGELOG b/firmware/open_evse/CHANGELOG index 3a90301d..f4425307 100644 --- a/firmware/open_evse/CHANGELOG +++ b/firmware/open_evse/CHANGELOG @@ -1,5 +1,14 @@ Change Log +D5.0.1 20181018 SCL +- fix Issue #94. Overcurrent caused lockup. Merge fixes from test1 branch + +20180823 SCL +- merged PR#94: doesn't affect functionality, only to correct compile errors on minimal builds + +20180724 SCL +- added RELAY_AUTO_PWM code - not tested - needs PWM-capable pin to function + 20180523 SCL - when RTC not defined, g++ bug pops out: open_evse:2384: error: unable to find a register to spill in class 'NO_REGS' diff --git a/firmware/open_evse/J1772EvseController.cpp b/firmware/open_evse/J1772EvseController.cpp index bd8530fe..cc8a3565 100644 --- a/firmware/open_evse/J1772EvseController.cpp +++ b/firmware/open_evse/J1772EvseController.cpp @@ -258,6 +258,13 @@ void J1772EVSEController::ShowDisabledTests() void J1772EVSEController::chargingOn() { // turn on charging current +#ifdef RELAY_AUTO_PWM_PIN + // turn on charging pin to close relay + digitalWrite(RELAY_AUTO_PWM_PIN,HIGH); + delay(m_relayCloseMs); + // switch to PWM to hold closed + analogWrite(RELAY_AUTO_PWM_PIN,m_relayHoldPwm); +#else // !RELAY_AUTO_PWM_PIN #ifdef CHARGING_REG pinCharging.write(1); #endif @@ -267,6 +274,8 @@ void J1772EVSEController::chargingOn() #ifdef CHARGINGAC_REG pinChargingAC.write(1); #endif +#endif // RELAY_AUTO_PWM_PIN + m_bVFlags |= ECVF_CHARGING_ON; if (m_bVFlags2 & ECVF2_SESSION_ENDED) { @@ -283,6 +292,9 @@ void J1772EVSEController::chargingOn() void J1772EVSEController::chargingOff() { // turn off charging current +#ifdef RELAY_AUTO_PWM_PIN + digitalWrite(RELAY_AUTO_PWM_PIN,LOW); +#else // !RELAY_AUTO_PWM_PIN #ifdef CHARGING_REG pinCharging.write(0); #endif @@ -292,6 +304,8 @@ void J1772EVSEController::chargingOff() #ifdef CHARGINGAC_REG pinChargingAC.write(0); #endif +#endif // RELAY_AUTO_PWM_PIN + m_bVFlags &= ~ECVF_CHARGING_ON; m_ChargeOffTime = now(); @@ -847,12 +861,29 @@ void J1772EVSEController::Init() } #endif // RGBLCD +#ifdef RELAY_AUTO_PWM_PIN_TESTING + m_relayHoldPwm = eeprom_read_byte((uint8_t*)EOFS_RELAY_HOLD_PWM); + m_relayCloseMs = eeprom_read_dword((uint32_t*)EOFS_RELAY_CLOSE_MS); + if (m_relayCloseMs > 5000) { + m_relayCloseMs = 0; + m_relayHoldPwm = 248; + } + Serial.print("\nrelayCloseMs: ");Serial.println(m_relayCloseMs); + Serial.print("relayHoldPwm: ");Serial.println(m_relayHoldPwm); +#endif + + +#ifdef RELAY_AUTO_PWM_PIN + pinMode(RELAY_AUTO_PWM_PIN,OUTPUT); +#else // !RELAY_AUTO_PWM_PIN #ifdef CHARGING_REG pinCharging.init(CHARGING_REG,CHARGING_IDX,DigitalPin::OUT); #endif #ifdef CHARGING2_REG pinCharging2.init(CHARGING2_REG,CHARGING2_IDX,DigitalPin::OUT); #endif +#endif // RELAY_AUTO_PWM_PIN + #ifdef CHARGINGAC_REG pinChargingAC.init(CHARGINGAC_REG,CHARGINGAC_IDX,DigitalPin::OUT); #endif @@ -914,7 +945,6 @@ void J1772EVSEController::Init() m_AmmeterReading = 0; m_ChargingCurrent = 0; - #ifdef OVERCURRENT_THRESHOLD m_OverCurrentStartMs = 0; #endif //OVERCURRENT_THRESHOLD @@ -1606,12 +1636,9 @@ if (TempChkEnabled()) { } #endif // !FAKE_CHARGING_CURRENT } -#endif // AMMETER - if (m_EvseState == EVSE_STATE_C) { - m_ElapsedChargeTimePrev = m_ElapsedChargeTime; - m_ElapsedChargeTime = now() - m_ChargeOnTime; #ifdef OVERCURRENT_THRESHOLD + if (m_EvseState == EVSE_STATE_C) { //testing m_ChargingCurrent = (m_CurrentCapacity+OVERCURRENT_THRESHOLD+12)*1000L; if (m_ChargingCurrent >= ((m_CurrentCapacity+OVERCURRENT_THRESHOLD)*1000L)) { if (m_OverCurrentStartMs) { // already in overcurrent state @@ -1619,8 +1646,16 @@ if (TempChkEnabled()) { // // overcurrent for too long. stop charging and hard fault // - // spin until EV is disconnected m_EvseState = EVSE_STATE_OVER_CURRENT; + + m_Pilot.SetState(PILOT_STATE_P12); // Signal the EV to pause + curms = millis(); + while ((millis()-curms) < 1000) { // give EV 1s to stop charging + wdt_reset(); + } + chargingOff(); // open the EVSE relays hopefully the EV has already discon + + // spin until EV is disconnected HardFault(); m_OverCurrentStartMs = 0; // clear overcurrent @@ -1630,7 +1665,19 @@ if (TempChkEnabled()) { m_OverCurrentStartMs = millis(); } } + else { + m_OverCurrentStartMs = 0; // clear overcurrent + } + } + else { + m_OverCurrentStartMs = 0; // clear overcurrent + } #endif // OVERCURRENT_THRESHOLD +#endif // AMMETER + if (m_EvseState == EVSE_STATE_C) { + m_ElapsedChargeTimePrev = m_ElapsedChargeTime; + m_ElapsedChargeTime = now() - m_ChargeOnTime; + #ifdef TEMPERATURE_MONITORING if(TempChkEnabled()) { @@ -1881,4 +1928,4 @@ void J1772EVSEController::SetTimeLimit15(uint8_t mind15) } #endif // TIME_LIMIT -//-- end J1772EVSEController +//-- end J1772EVSEController \ No newline at end of file diff --git a/firmware/open_evse/J1772EvseController.h b/firmware/open_evse/J1772EvseController.h index b01b1c3c..b0dd7205 100644 --- a/firmware/open_evse/J1772EvseController.h +++ b/firmware/open_evse/J1772EvseController.h @@ -148,6 +148,10 @@ class J1772EVSEController { unsigned long m_StuckRelayStartTimeMS; uint8_t m_StuckRelayTripCnt; // contains tripcnt-1 #endif // ADVPWR +#ifdef RELAY_AUTO_PWM_PIN_TESTING + unsigned long m_relayCloseMs; // #ms for DC pulse to close relay + uint8_t m_relayHoldPwm; // PWM duty cycle to hold relay closed +#endif // RELAY_AUTO_PWM_PIN_TESTING uint16_t m_wFlags; // ECF_xxx uint8_t m_bVFlags; // ECVF_xxx uint8_t m_bVFlags2; // ECVF2_xxx @@ -268,6 +272,13 @@ class J1772EVSEController { return ((m_EvseState >= EVSE_FAULT_STATE_BEGIN) && (m_EvseState <= EVSE_FAULT_STATE_END)); } +#ifdef RELAY_AUTO_PWM_PIN_TESTING + void setPwmPinParms(uint32_t delayms,uint8_t pwm) { + m_relayCloseMs = delayms; + m_relayHoldPwm = pwm; + } +#endif + void SetHardFault() { m_bVFlags |= ECVF_HARD_FAULT; } void ClrHardFault() { m_bVFlags &= ~ECVF_HARD_FAULT; } int8_t InHardFault() { return (m_bVFlags & ECVF_HARD_FAULT) ? 1 : 0; } diff --git a/firmware/open_evse/open_evse.h b/firmware/open_evse/open_evse.h index 57f475e0..4f61f3b7 100644 --- a/firmware/open_evse/open_evse.h +++ b/firmware/open_evse/open_evse.h @@ -42,7 +42,7 @@ #define clrBits(flags,bits) (flags &= ~(bits)) // See platformio.ini -// #define VERSION "D5.0.0" +// #define VERSION "D5.0.1" #include "Language_default.h" //Default language should always be included as bottom layer @@ -300,6 +300,21 @@ extern AutoCurrentCapacityController g_ACCController; // certification.. redraw display periodically when enabled #define PERIODIC_LCD_REFRESH_MS 120000UL +// when closing DC relay set to HIGH for m_relayCloseMs, then +// switch to m_relayHoldPwm +// ONLY WORKS PWM-CAPABLE PINS!!! +// use Arduino pin number PD5 = 5, PD6 = 6 +//#define RELAY_AUTO_PWM_PIN 5 +// enables RAPI $Z0 for tuning PWM (see rapi_proc.h for $Z0 syntax) +// PWM parameters written to/loaded from EEPROM +// when done tuning, put hardcoded parameters into m_relayCloseMs +// and m_relayHoldPwm below +//#define RELAY_AUTO_PWM_PIN_TESTING +#ifndef RELAY_AUTO_PWM_PIN_TESTING +#define m_relayCloseMs 250UL +#define m_relayHoldPwm 50 // duty cycle 0-255 +#endif //RELAY_AUTO_PWM_PIN_TESTING + //-- end features #ifndef DEFAULT_LCD_BKL_TYPE @@ -334,6 +349,10 @@ extern AutoCurrentCapacityController g_ACCController; #error INVALID CONFIG - GFI SELF TEST NEEDED FOR UL COMPLIANCE #endif +#if defined(GFI_SELFTEST) && !defined(GFI) +#error INVALID_CONFIG - GFI NEEDED FOR GFI SELF TEST +#endif + // for testing print various diagnostic messages to the UART //#define SERDBG @@ -413,6 +432,7 @@ extern AutoCurrentCapacityController g_ACCController; #define MAX_CURRENT_CAPACITY_L2 32 // J1772 Max for L2 = 80 //J1772EVSEController + #define CURRENT_PIN 0 // analog current reading pin ADCx #define PILOT_PIN 1 // analog pilot voltage reading pin ADCx #define PP_PIN 2 // PP_READ - ADC2 @@ -440,6 +460,7 @@ extern AutoCurrentCapacityController g_ACCController; #define ACLINE2_REG &PIND #define ACLINE2_IDX 4 +#ifndef RELAY_AUTO_PWM_PIN // digital Relay trigger pin #define CHARGING_REG &PINB #define CHARGING_IDX 0 @@ -449,6 +470,7 @@ extern AutoCurrentCapacityController g_ACCController; //digital Charging pin for AC relay #define CHARGINGAC_REG &PINB #define CHARGINGAC_IDX 1 +#endif // !RELAY_AUTO_PWM_PIN // obsolete LED pin //#define RED_LED_REG &PIND @@ -519,6 +541,19 @@ extern AutoCurrentCapacityController g_ACCController; #define EOFS_GROUP_CURRENT_CAPACITY 31 // 1 byte // non-volatile flags #define EOFS_DUO_NVFLAGS 32 // 1 byte +#define EOFS_DUO_SHARED_AMPS 33 // 1 byte + +//- start TESTING ONLY +#ifdef RELAY_AUTO_PWM_PIN_TESTING +#define EOFS_RELAY_HOLD_PWM 512 +#define EOFS_RELAY_CLOSE_MS 513 +#endif // RELAY_AUTO_PWM_PIN_TESTING +#ifdef RELAY_HOLD_DELAY_TUNING +#define EOFS_RELAY_HOLD_DELAY 512 +#endif // RELAY_HOLD_DELAY_TUNING +//- end TESTING ONLY + + // must stay within thresh for this time in ms before switching states #define DELAY_STATE_TRANSITION 250 diff --git a/firmware/open_evse/rapi_proc.cpp b/firmware/open_evse/rapi_proc.cpp index ad8df0fb..49b05064 100644 --- a/firmware/open_evse/rapi_proc.cpp +++ b/firmware/open_evse/rapi_proc.cpp @@ -248,11 +248,13 @@ int EvseRapiProcessor::processCmd() rc = 0; } break; + #ifdef BTN_MENU case '1': // simulate front panel short press g_BtnHandler.DoShortPress(g_EvseController.InFaultState()); g_OBD.Update(OBD_UPD_FORCE); rc = 0; break; +#endif // BTN_MENU #ifdef LCD16X2 case 'B': // LCD backlight if (tokenCnt == 2) { @@ -726,6 +728,23 @@ int EvseRapiProcessor::processCmd() } break; #endif //RAPI_T_COMMANDS +#if defined(RELAY_HOLD_DELAY_TUNING) + case 'Z': // reserved op + switch(*s) { + case '1': // set relayCloseMs + if (tokenCnt == 2) { + u1.u32 = dtou32(tokens[1]); + g_EvseController.setRelayHoldDelay(u1.u32); + sprintf(g_sTmp,"\nZ1 %ld",u1.u32); + Serial.println(g_sTmp); + eeprom_write_dword((uint32_t*)EOFS_RELAY_HOLD_DELAY,u1.u32); + } + rc = 0; + break; + + } + break; +#endif // RELAY_AUTO_PWM_PIN_TESTING default: ; // do nothing diff --git a/firmware/open_evse/rapi_proc.h b/firmware/open_evse/rapi_proc.h index e8b51cf7..8c5ab827 100644 --- a/firmware/open_evse/rapi_proc.h +++ b/firmware/open_evse/rapi_proc.h @@ -265,6 +265,12 @@ T0 amps - set fake charging current response: $OK $T0 75 +Z0 FOR TESTING RELAY_AUTO_PWM_PIN ONLY +Z0 closems holdpwm + closems(dec) = # ms to apply DC to relay pin + holdpwm(dec) = pwm duty cycle for relay hold 0-255 + + * */ diff --git a/platformio.ini b/platformio.ini index 07562115..fa997c75 100644 --- a/platformio.ini +++ b/platformio.ini @@ -24,7 +24,7 @@ upload_flags = -p m328p # Enable PP_AUTO_AMPACITY (don't exceed max current capacity of non-tethered cable) src_build_flags= -D PP_AUTO_AMPACITY - -D 'VERSION="5.0.0.T2"' + -D 'VERSION="5.0.1.T2"' # Non-tethered T2 EmonEVSE three-phase [env:emonevse-3ph] @@ -38,7 +38,7 @@ upload_flags = -p m328p src_build_flags= -D PP_AUTO_AMPACITY -D THREEPHASE - -D 'VERSION="5.0.0.3P"' + -D 'VERSION="5.0.1.3P"' # EU OpenEVSE # Level 2 default, max 32A @@ -49,4 +49,4 @@ framework = arduino upload_protocol = usbasp ; upload_protocol = stk500v2 upload_flags = -p m328p -src_build_flags = -D 'VERSION="5.0.0.EU"' +src_build_flags = -D 'VERSION="5.0.1.EU"'