Skip to content

Commit

Permalink
added RELAY_AUTO_PWM code (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
lincomatic committed Jul 24, 2018
1 parent 39197d6 commit a8a9d5f
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
3 changes: 3 additions & 0 deletions firmware/open_evse/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Change Log

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'
Expand Down
31 changes: 31 additions & 0 deletions firmware/open_evse/J1772EvseController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions firmware/open_evse/J1772EvseController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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; }
Expand Down
31 changes: 31 additions & 0 deletions firmware/open_evse/open_evse.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,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
Expand Down Expand Up @@ -404,6 +419,7 @@ extern AutoCurrentCapacityController g_ACCController;
#define MAX_CURRENT_CAPACITY_L2 80 // 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
Expand Down Expand Up @@ -431,6 +447,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
Expand All @@ -440,6 +457,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
Expand Down Expand Up @@ -510,6 +528,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
Expand Down
17 changes: 17 additions & 0 deletions firmware/open_evse/rapi_proc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,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
Expand Down
6 changes: 6 additions & 0 deletions firmware/open_evse/rapi_proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
*/

Expand Down

0 comments on commit a8a9d5f

Please sign in to comment.