Skip to content

Commit

Permalink
Move StartCurrent detection back to BalancedLeft block to fix overcur…
Browse files Browse the repository at this point in the history
…rent protection
  • Loading branch information
bobosch committed Jul 28, 2022
1 parent 0890c68 commit 901012e
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions SmartEVSE2.X/EVSE.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,41 +976,6 @@ void CalcBalancedCurrent(char mod) {
IsumImport = Isum;
#endif

MeasurementActive = false;
for (n = 0; n < NR_EVSES; n++) {
if (BalancedState[n] == STATE_C) {
// Automatic StartCurrent detection
if (!Node[n].MinCurrent) {
MeasurementActive = true;
if (Node[n].IntTimer >= STARTCURRENT_AUTO_TIMER && SolarChargeTimer >= STARTCURRENT_DECREASE_TIME) {
if (Node[n].EVMeter) {
// Request EV current measurement
EVMeasureNode = n;
} else if (!CMMeasureTimer) {
// Up to 3 cycles Mains current measurement
CMMeasureNode = n;
CMMeasureTimer = (STARTCURRENT_INCREASE_TIME + STARTCURRENT_DECREASE_TIME) * 3 + STARTCURRENT_DECREASE_TIME + 1;
}
}
}
// Start with MIN current when measurement active or when start Solar charging
if (MeasurementActive || Node[n].IntTimer < STARTCURRENT_AUTO_TIMER) {
// When EV EM is available, 8 A measured or no measurement active
if (Node[n].EVMeter || CMMeasured || !MeasurementActive) {
// charge with 6 A
Balanced[n] = MinCurrent * 10;
} else {
// else charge with 8 A
Balanced[n] = (MinCurrent + 2) * 10;
}
CurrentSet[n] = true; // mark this EVSE as set.
BalancedLeft--; // decrease counter of active EVSE's
MaxBalanced -= Balanced[n]; // Update total current to new (lower) value
IsetBalanced = TotalCurrent;
}
}
}

if (IsumImport < 0) {
// negative, we have surplus (solar) power available
if (IsumImport < -10) IsetBalanced = IsetBalanced + 5; // more then 1A available, increase Balanced charge current with 0.5A
Expand Down Expand Up @@ -1071,6 +1036,43 @@ void CalcBalancedCurrent(char mod) {

MaxBalanced = IsetBalanced; // convert to Amps

if (Mode == MODE_SOLAR) {
MeasurementActive = false;
for (n = 0; n < NR_EVSES; n++) {
if (BalancedState[n] == STATE_C) {
// Automatic StartCurrent detection
if (!Node[n].MinCurrent) {
MeasurementActive = true;
if (Node[n].IntTimer >= STARTCURRENT_AUTO_TIMER && SolarChargeTimer >= STARTCURRENT_DECREASE_TIME) {
if (Node[n].EVMeter) {
// Request EV current measurement
EVMeasureNode = n;
} else if (!CMMeasureTimer) {
// Up to 3 cycles Mains current measurement
CMMeasureNode = n;
CMMeasureTimer = (STARTCURRENT_INCREASE_TIME + STARTCURRENT_DECREASE_TIME) * 3 + STARTCURRENT_DECREASE_TIME + 1;
}
}
}
// Start with MIN current when measurement active or when start Solar charging
if (MeasurementActive || Node[n].IntTimer < STARTCURRENT_AUTO_TIMER) {
// When EV EM is available, 8 A measured or no measurement active
if (Node[n].EVMeter || CMMeasured || !MeasurementActive) {
// charge with 6 A
Balanced[n] = MinCurrent * 10;
} else {
// else charge with 8 A
Balanced[n] = (MinCurrent + 2) * 10;
}
CurrentSet[n] = true; // mark this EVSE as set.
BalancedLeft--; // decrease counter of active EVSE's
MaxBalanced -= Balanced[n]; // Update total current to new (lower) value
IsetBalanced = TotalCurrent;
}
}
}
}

// Calculate average current per EVSE
n = 0;
do {
Expand Down

0 comments on commit 901012e

Please sign in to comment.