diff --git a/envSetup.py b/envSetup.py index 5f037cc..ea09966 100644 --- a/envSetup.py +++ b/envSetup.py @@ -79,7 +79,7 @@ if sslEnabled: cn = (cert_components.get(b'CN')).decode('utf-8') else: cn = cert_components.get('CN') - print('Centificate {0} - CN: {1}'.format(index, cn)) + print('Certificate {0} - CN: {1}'.format(index, cn)) try: temp_certname = '{0}_{1}.crt'.format("transformerMonitorServerCert", index) diff --git a/lib/ATM90E36/ATM90E36.cpp b/lib/ATM90E36/ATM90E36.cpp index ed0e613..908714a 100644 --- a/lib/ATM90E36/ATM90E36.cpp +++ b/lib/ATM90E36/ATM90E36.cpp @@ -462,12 +462,34 @@ void ATM90E36::begin(int pin, unsigned short lineFreq, unsigned short pgagain, u _pgagain = pgagain; //PGA Gain for current channels _ugain = ugain; //voltage rms gain _igainA = igainA; //CT1 - _igainB = igainB; //CT2 - _igainC = igainC; //CT3 - _igainN = igainN; //N + _igainB = igainA; //CT2 + _igainC = igainA; //CT3 + _igainN = igainA; //N //pinMode(_energy_CS, OUTPUT); + // calculation for voltage sag threshold - assumes we do not want to go under 90v for split phase and 190v otherwise + // determine proper low and high frequency threshold + unsigned short vSagTh; + unsigned short sagV; + unsigned short FreqHiThresh; + unsigned short FreqLoThresh; + if (_lineFreq == 4485 || _lineFreq == 5231) + { + sagV = 90; + FreqHiThresh = 61 * 100; + FreqLoThresh = 59 * 100; + } + else + { + sagV = 190; + FreqHiThresh = 51 * 100; + FreqLoThresh = 49 * 100; + } + + vSagTh = (sagV * 100 * sqrt(2)) / (2 * _ugain / 32768); + + /* Enable SPI */ //SPI.begin(); //moved to main program to assign different SPI pins @@ -533,12 +555,12 @@ void ATM90E36::begin(int pin, unsigned short lineFreq, unsigned short pgagain, u CommEnergyIC(WRITE, IgainA, _igainA); // A line current gain CommEnergyIC(WRITE, UoffsetA, 0x0000); // A Voltage offset CommEnergyIC(WRITE, IoffsetA, 0x0000); // A line current offset - CommEnergyIC(WRITE, UgainB, _ugain); // B Voltage rms gain - CommEnergyIC(WRITE, IgainB, _igainB); // B line current gain + CommEnergyIC(WRITE, UgainB, 0); // B Voltage rms gain + CommEnergyIC(WRITE, IgainB, 0); // B line current gain CommEnergyIC(WRITE, UoffsetB, 0x0000); // B Voltage offset CommEnergyIC(WRITE, IoffsetB, 0x0000); // B line current offset - CommEnergyIC(WRITE, UgainC, _ugain); // C Voltage rms gain - CommEnergyIC(WRITE, IgainC, _igainC); // C line current gain + CommEnergyIC(WRITE, UgainC, 0); // C Voltage rms gain + CommEnergyIC(WRITE, IgainC, 0); // C line current gain CommEnergyIC(WRITE, UoffsetC, 0x0000); // C Voltage offset CommEnergyIC(WRITE, IoffsetC, 0x0000); // C line current offset CommEnergyIC(WRITE, IgainN, _igainN); // C line current gain diff --git a/platformio.ini b/platformio.ini index e526e27..e3378a6 100644 --- a/platformio.ini +++ b/platformio.ini @@ -22,12 +22,11 @@ upload_port = COM6 [env:dev] build_flags = -D DEV ${env.build_flags} lib_deps = - ; knolleary/pubsubclient - ; https://github.com/CircuitSetup/ATM90E36 - ; https://github.com/whatnick/ATM90E26_Arduino - ; bblanchon/ArduinoJson @ ^6.21.3 - ; paulstoffregen/OneWire@^2.3.8 - ; milesburton/DallasTemperature@^3.11.0 + knolleary/pubsubclient + https://github.com/whatnick/ATM90E26_Arduino + bblanchon/ArduinoJson @ ^6.21.3 + paulstoffregen/OneWire@^2.3.8 + milesburton/DallasTemperature@^3.11.0SP build_src_filter = + -<.git/> -<.svn/> - [env:store-creds] diff --git a/src/tests/AT90E36.cpp b/src/tests/AT90E36.cpp index 0e5a85d..d29325e 100644 --- a/src/tests/AT90E36.cpp +++ b/src/tests/AT90E36.cpp @@ -26,6 +26,14 @@ void setup() { - MOSI: 23 - CS: 5 */ + // PM0 - 17 + // PM1 - 21 + // set normal detection mode for ATM90E36 + pinMode(21, OUTPUT); + pinMode(34, INPUT); + pinMode(17, OUTPUT); + digitalWrite(17, HIGH); + digitalWrite(21, HIGH); delay(2000); Serial.begin(9600); while (!Serial) { @@ -37,17 +45,18 @@ void setup() { // ss pin is the first parameter SPI.begin(SCK, MISO, MOSI, SS); delay(1000); + /* CS pin - 33 for ESP32 Line Frequency - 60 Hz for NA - 5509 - see MMode0 section (4.2.3) in data sheet for ATM90E36 - PGA Gain - + PGA Gain - adjusts ADC gain for current and voltage Current gain - Note: values are adjusted from https://github.com/DitroniX/IPEM-IoT-Power-Energy-Monitor/blob/main/Code/IPEM_1_Test_Code_ATM90E32_ATM90E36/include/IPEM_Hardware.h */ - unsigned short PgaGain = 0x5555; + unsigned short PgaGain = 0b1101010101010101; unsigned short frequency = 0b0001010110000101; - unsigned short VoltageGain = 19800; - eic.begin(SS, frequency, PgaGain, VoltageGain, 0x1000,0x1000, 0x1000, 0x1000); + unsigned short VoltageGain = 19900; + eic.begin(SS, frequency, PgaGain, VoltageGain, 0x100,0x100, 0x100, 0x100); delay(1000); } @@ -83,6 +92,7 @@ void loop() { freq=eic.GetFrequency(); delay(10); Serial.println("f"+String(freq)+"Hz"); - Serial.println("Waiting 1s"); - delay(1000); + // Serial.println("Warn: "+String(digitalRead(34))); + Serial.println("Waiting 6s"); + delay(6000); } \ No newline at end of file