Skip to content

Commit

Permalink
Irregularly sampled exponentially weighted average for current displays.
Browse files Browse the repository at this point in the history
(merging branch june-2.4.1-amm-ewa)

Squashed commit of the following:

commit af23c49
Author: Dmitriy Lyubimov <dlyubimov@apache.org>
Date:   Mon Jul 3 23:15:46 2017 -0700

    binaries recompiled, unit test flag switched off.

commit a51ee9d
Merge: ebe9994 923284d
Author: Dmitriy Lyubimov <dlyubimov@apache.org>
Date:   Mon Jul 3 23:09:48 2017 -0700

    Merge branch 'june-2.4.1' into june-2.4.1-amm-ewa

commit ebe9994
Author: Dmitriy Lyubimov <dlyubimov@apache.org>
Date:   Sun Jul 2 22:45:39 2017 -0700

    regenerating binaries after merge

commit bcaefd2
Merge: e941499 4f7d133
Author: Dmitriy Lyubimov <dlyubimov@apache.org>
Date:   Sun Jul 2 22:45:16 2017 -0700

    Merge branch 'june-2.4.1' into june-2.4.1-amm-ewa

commit e941499
Merge: 4281b96 7b34d3f
Author: Dmitriy Lyubimov <dlyubimov@apache.org>
Date:   Sun Jul 2 19:23:42 2017 -0700

    Merge branch 'june-2.4.1' into june-2.4.1-amm-ewa

commit 4281b96
Author: Dmitriy Lyubimov <dlyubimov@apache.org>
Date:   Sun Jul 2 09:01:46 2017 -0700

    more comments, binary.

commit cfc1fa2
Author: Dmitriy Lyubimov <dlyubimov@apache.org>
Date:   Sat Jul 1 17:22:20 2017 -0700

    Bug fixes; recompiled binary; probably ok to try with the smoother.
  • Loading branch information
dlyubimov committed Jul 4, 2017
1 parent 923284d commit 816280a
Show file tree
Hide file tree
Showing 5 changed files with 1,638 additions and 1,433 deletions.
15 changes: 12 additions & 3 deletions Hydra_EVSE/Hydra_EVSE.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <Time.h>
#include <DS1307RTC.h>
//#include <Timezone.h>
#include "onlineSum.h"
#include "dst.h"

// SW version
Expand Down Expand Up @@ -253,6 +254,13 @@
// doe RB = 27 - Mega Hydra production
//#define CURRENT_SCALE_FACTOR 184

// Irregular-sampled EWA half-period for ammeter displays (the time after which data points a weighed 1/2
// w.r.t. most recent data point). This is for Ammeter display only, it does not affect current measurements
// for overdraw etc. purposes.
#define AMM_DISPLAY_HALF_PERIOD 1500



#define LOG_NONE 0
#define LOG_INFO 1
#define LOG_DEBUG 2
Expand Down Expand Up @@ -346,7 +354,7 @@ struct car_struct {
unsigned long last_current_log;
boolean seq_done = false;
unsigned int pilot_state;
// unsigned long current_samples[ROLLING_AVERAGE_SIZE];
EWASumD ammSum;

car_struct(unsigned int car, int themOffset, unsigned int relay_pin,
unsigned int pilot_out_pin, unsigned int pilot_sense_pin, unsigned int current_pin) :
Expand All @@ -362,9 +370,9 @@ struct car_struct {
request_time(0),
error_time(0),
last_current_log(0),
pilot_state(LOW)
pilot_state(LOW),
ammSum(AMM_DISPLAY_HALF_PERIOD)
{
// memset(current_samples, 0, sizeof(current_samples));
};

void setRelay(unsigned int state);
Expand Down Expand Up @@ -494,6 +502,7 @@ extern persisted_struct persisted;
extern void Delay(unsigned int);
extern void displayStatus(unsigned int status);
extern char errLetter(unsigned int status);
extern char *formatMilliamps(unsigned long milliamps);

extern boolean &enable_dst;
extern car_struct cars[];
Expand Down
23 changes: 14 additions & 9 deletions Hydra_EVSE/Hydra_EVSE.ino
Original file line number Diff line number Diff line change
Expand Up @@ -617,13 +617,13 @@ int car_struct::checkState()

static inline unsigned long ulong_sqrt(unsigned long in)
{
unsigned long out;
// find the last int whose square is not too big
// Yes, it's wasteful, but we only theoretically ever have to go to 512.
// Removing floating point saves us almost 1K of flash.
for (out = 1; out * out <= in; out++) ;
return out - 1;
// return (unsigned long)sqrt((float)in);
// unsigned long out;
// // find the last int whose square is not too big
// // Yes, it's wasteful, but we only theoretically ever have to go to 512.
// // Removing floating point saves us almost 1K of flash.
// for (out = 1; out * out <= in; out++) ;
// return out - 1;
return sqrt((double)in);
}

unsigned long car_struct::readCurrent()
Expand Down Expand Up @@ -1953,16 +1953,21 @@ void car_struct::loopCurrentMonitor() {
// car A is under its limit. Cancel any overdraw in progress
overdraw_begin = 0;
}

// update the ammeter display.
ammSum.update(car_draw, millis());

display.setCursor(dispCol(), 1);
display.print(carLetter());
display.print(':');
display.print(formatMilliamps(car_draw));
display.print(formatMilliamps(ammSum.ewa()));
}
else
{
// Car A is not charging
overdraw_begin = 0;
// memset(current_samples, 0, sizeof(current_samples));
ammSum.reset();
// memset(current_samples, 0, sizeof(current_samples));
}

}
Expand Down
Loading

0 comments on commit 816280a

Please sign in to comment.