Start a new topic

Firmware mod to enable Nsayer's voltage monitor on modified v4 hardware

Hi all,


Here is a patch to enable Nsayer's voltage reading code to work on ADC3 of version 4 of the hardware.  The hardware mods can be found in another post in the hardware section.


Date: Thu, 29 Mar 2018 10:02:37 -0700

Subject: [PATCH] add volt meter


firmware/open_evse/src/J1772EvseController.h

firmware/open_evse/src/J1772EvseController.cpp

changed offset to be signed


firmware/open_evse/src/open_evse.h

Nsayer paved the way... just turned on his code and tweaked the

constants


firmware/open_evse/src/rapi_proc.cpp

had to add a int 32 conversion routine

---

 firmware/open_evse/src/J1772EvseController.cpp | 4 ++--

 firmware/open_evse/src/J1772EvseController.h | 4 ++--

 firmware/open_evse/src/open_evse.h | 21 ++++++++++++++++++++-

 firmware/open_evse/src/rapi_proc.cpp | 13 ++++++++++++-

 4 files changed, 36 insertions(+), 6 deletions(-)


diff --git a/firmware/open_evse/src/J1772EvseController.cpp b/firmware/open_evse/src/J1772EvseController.c

pp

index ff96317..dd8a426 100644

--- a/firmware/open_evse/src/J1772EvseController.cpp

+++ b/firmware/open_evse/src/J1772EvseController.cpp

@@ -918,10 +918,10 @@ void J1772EVSEController::Init()

 #endif // AMMETER

 

 #ifdef VOLTMETER

- m_VoltOffset = eeprom_read_dword((uint32_t*)EOFS_VOLT_OFFSET);

+ m_VoltOffset = (int32_t)eeprom_read_dword((uint32_t*)EOFS_VOLT_OFFSET);

   m_VoltScaleFactor = eeprom_read_word((uint16_t*)EOFS_VOLT_SCALE_FACTOR);

 

- if (m_VoltOffset == 0xffffffff) {

+ if ((uint32_t)m_VoltOffset == 0xffffffff) {

     m_VoltOffset = DEFAULT_VOLT_OFFSET;

   }

   if (m_VoltScaleFactor == 0xffff) {

diff --git a/firmware/open_evse/src/J1772EvseController.h b/firmware/open_evse/src/J1772EvseController.h

index cb7ada2..81df1cd 100644

--- a/firmware/open_evse/src/J1772EvseController.h

+++ b/firmware/open_evse/src/J1772EvseController.h

@@ -225,7 +225,7 @@ class J1772EVSEController {

 #endif // AMMETER

 #ifdef VOLTMETER

   uint16_t m_VoltScaleFactor;

- uint32_t m_VoltOffset;

+ int32_t m_VoltOffset;

   uint32_t m_Voltage; // mV

 #endif // VOLTMETER

 

@@ -359,7 +359,7 @@ public:

 

 #ifdef VOLTMETER

   uint16_t GetVoltScaleFactor() { return m_VoltScaleFactor; }

- uint32_t GetVoltOffset() { return m_VoltOffset; }

+ int32_t GetVoltOffset() { return m_VoltOffset; }

   void SetVoltmeter(uint16_t scale,uint32_t offset);

   uint32_t ReadVoltmeter();

   int32_t GetVoltage() { return m_Voltage; }

diff --git a/firmware/open_evse/src/open_evse.h b/firmware/open_evse/src/open_evse.h

index 35f9f9f..f5bc575 100644

--- a/firmware/open_evse/src/open_evse.h

+++ b/firmware/open_evse/src/open_evse.h

@@ -37,7 +37,7 @@

 #else

 #include "WProgram.h" // shouldn't need this but arduino sometimes messes up and puts inside an #ifdef

 #endif // ARDUINO

-#define VERSION "4.8.0"

+#define VERSION "4.8.2"

 

 #include "Language_default.h" //Default language should always be included as bottom layer

 

@@ -126,6 +126,20 @@

 //#define DEFAULT_VOLT_OFFSET (12018) // calibrated for lincomatic's OEII

 #endif // OPENEVSE_2

 

+// Support for Chuck Kamas' modification to the UL OpenEVSE board, which has alternate wiring for a voltmeter for L1/L2.

+#define OPENEVSE_CCK

+#ifdef OPENEVSE_CCK

+// If the AC voltage is > 150,000 mV, then it's L2. Else, L1.

+#define L2_VOLTAGE_THRESHOLD (150000)

+#define VOLTMETER

+// 35 ms is just a bit longer than 1.5 cycles at 50 Hz

+#define VOLTMETER_POLL_INTERVAL (35)

+// This is just a wild guess

+#define DEFAULT_VOLT_SCALE_FACTOR (308) // original guess

+#define DEFAULT_VOLT_OFFSET (-4000) // original guess

+#endif // OPENEVSE_CCK

+

+

 // GFI support

 #define GFI



1 person likes this idea
1 Comment

I am planning on performing this voltage modification again. For HW I will use this $7 board from Amazon:

https://smile.amazon.com/gp/product/B07D1WP884/ref=ppx_yo_dt_b_asin_title_o02_s00?ie=UTF8&psc=1


For FW I will either enable the voltage code that is alreay in the code base or port this to the OpenEVSE:

https://surtrtech.com/2019/01/21/easy-measure-of-ac-voltage-using-arduino-and-zmpt101b/


I will post updates as I go.

Login or Signup to post a comment