Skip to content

ESP32 ATM90E32 ATM90E36 Test Code

Dave Williams | DitroniX | G8PUO edited this page Mar 24, 2023 · 3 revisions

IPEM ‘IPEM_1_Test_Code_ATM90E32_ATM90E36’ Options

This development code is primarily used to provide bring up and bench test the boards, prior to shipping. However, the application has quickly grown to be a flexible piece of firmware.

Both variables and 'compiler options' are used. These are sometimes referred as compiler preprocessors, or preprocessor macros.

In order to facilitate chunks of duplicated code with different values, pending which ATM90 device is used, the compiler switches automatically select, and deselect, code as needed. It is thus important you only change the configuration switches were highlighted.

This version of firmware code is configured for:

  • ATM90E32 (ATM90DEVICE ATM90E32_DEVICE)
  • CT4 Configured to ESP32 ADC (CT4_CONFIG CT4_ESP)
  • CT4 Input Enabled (CT4_ENABLED true)
  • Multi-Voltage Input (ATM_SINGLEVOLTAGE false)
  • Split-Phase USA Disabled (ATM_SPLITPHASE false)
  • Hardware Test Enabled (DisableHardwareTest false)
  • Display of Board Configuration (EnableDisplayBoardConfiguration true)
  • Domoticz Publishing Disabled (EnableDomoticz false)
  • Loop Refreshing Terminal Output (EnableBasicLoop false) - Display Info ONCE uppon Reset
  • Value Outputs are filtered through a Sofware Noise Filter / Comparator / Squelch (EnableNoiseFilterSquelch true)
  • When Publishing to Domoticz - Mute Detailed Output to Serial (Loop)

CALIBRATION (This should be minimal - based on the below)

  • This version of firmware has been setup for ATM90E32 and CT4 to ESP32 ADC. Current Clamp default example settings are based on SCT-013-000 100A/50mA
  • Voltages default example settings are based on Single/Three Phase
  • Voltage Inputs from a Greenbrook DAT01A (TC TR7) Transformer, set to 12V AC.
  • You can update calibration in IPEM_Hardware.h
  • You can update board ATM Configurations in ATM90E3x.h

Code Switches and Options

file : \src\main.cpp

  • Variable - LoopDelay
    • Default 1
    • Used in the 'Loop' 1 = 1 second.
  • Variable - EnableBasicLoop
    • Default false
    • Default is to only display registers once upon boot or pressing of the user button.
    • Set to true to display loop readings.
  • Variable - EnableDisplayBoardConfiguration
    • Default false
    • Set to true to display board software configuration Information

file : \include\IPEM_Hardware.h

Basic Settings

  • Variable - EnableAveraging
    • Default true
    • Set to true to enable averaging (ESP32 DCV).
  • Variable - DisableHardwareTest
    • Default false
    • Set to true to speed up booting.
  • Variable - EnableNoiseFilterSquelch
    • Default true
    • This realtes to NoiseFilterSquelch Threshold. false returns raw values.

ATMDEVICE Calibration Defaults

  • Variable - LineFreq
    • Default 389
    • Typical Values: 389 for 50 Hz (World) 4485 for 60Hz (North America)
  • Variable - PGAGain
    • Default for ATM90E32 0x557F or 0b0101010101111111 (DDV3V2V1I4I3I2I1)
    • Default for ATM90E36 0x5555 or 0b0101010101010101 (DDV3V2V1I4I3I2I1)
    • Further details can be found on the binary settings, in the application notes.
  • Variables - VoltageGain1, VoltageGain2 and VoltageGain3
    • These relate to the three AC voltage inputs. V1 also applied AC Power In via Solder Jumper
    • The calculation is based on the DAT01 on 12V setting @ ~19V RMS. Need to allow for +/- ~ 1% Tolerance.
    • Default for ATM90E32 0x9790 or 38800
      • Calculations: Base value for 240V is 38800. To increase/decrease change by Approx. ~100 per 1.0 V RMS.
      • Calculations: Base value for 120V is 20200. To increase/decrease change by Approx. ~100 per 1.0 V RMS
    • Default for ATM90E36 0x4EE8 or 20200
      • Calculations: Base value for 240V is 20200. To increase/decrease change by Approx. ~100 per 1.0 V RMS
      • Calculations: Base value for 120V is 9700. To increase/decrease change by Approx. ~100 per 1.0 V RMS.
  • Variables - CurrentGainCT1, CurrentGainCT2 and CurrentGainCT3
    • These relate to the three main Current Clamp Inputs CT1, CT2 and CT3
    • The calculation is based on the YDH? 100A/50mA Need to allow for +/- ~ 1% Tolerance.
    • Default for ATM90E32 0x9664 or 38500
      • Calculations: Base value for CT100/50 Mid Range 38500. To increase/decrease change by Approx. ~500 per 0.01A RMS
    • Default for ATM90E36 0x82DC or 33500
      • Calculations: Base value for CT100/50 Mid Range 33500. To increase/decrease change by Approx. ~500 per 0.01A RMS

file : \include\ATM90E3x.h

  • Define - ATM90DEVICE
    • Default ATM90E32_DEVICE
    • Options:
      • Set to ATM90E32_DEVICE to configure appropriate registers and code functions for ATM90E32
      • Set to ATM90E36_DEVICE to configure appropriate registers and code functions for ATM90E36
  • Define - CT4_CONFIG
    • Default CT4_ESP
    • Options:
      • Set to CT4_ESP for CT4 configured to EP32 ADC
        • See Solder Jumpers on the PCB bottom for Hardware Configuration
          • Relates to CT4A, CT4B, CT4C, CT4D, CT4E
        • Depending on board, R/C values may require changing
          • R19, R20 = 0R (Default for ATM90E32)
          • R27, R28 = 10K (Default for ATM90E32)
          • C9 = 10u 6V3 (Default for ATM90E32)
      • Set to CT4_ATM for CT4 configured to ATM90E36
        • See Solder Jumpers on the PCB bottom for Hardware Configuration
          • Relates to CT4A, CT4B, CT4C, CT4D, CT4E -
        • Depending on board, R/C values may require changing
          • R19, R20 = 2R4 (Default for ATM90E36)
          • R27, R28 = 1K (Default for ATM90E36)
          • C9 = 18n 50V (Default for ATM90E36)
  • Define - CT4_ENABLED
    • Default true
    • CT4 ESP32 Clamp (Default true)
    • This setting work in tandem with CT4_CONFIG
  • Define - ATM_SINGLEVOLTAGE
    • Default false
    • This enables a single AC voltage input to be used across all CT clamps and calculations.
    • Set to true to use V1 for CT1, CT2, CT3, CT4, CTN.
    • Single Voltage setting uses either V1 input or AC Power Input (depending on SJ1 Link Setting)
  • Define - ATM_SPLITPHASE
    • Default false
    • NB. This part of the code has not been fully tested (yet).
    • If Split Phase (i.e. USA 120+120), set to true
      • AC Voltage is monitored via LineVoltage1 and LineVoltage3
        • LineVoltage2 is ignored
        • Average Voltage is (LineVoltage1 + LineVoltage3) / 2
      • AC Current is monitored via LineCurrentCT1 and LineCurrentCT3
        • Calculated Total Power is (LineVoltage1 * LineCurrentCT1) + (LineVoltage3 * LineCurrentCT3)

file : \include\Domoticz.h

  • Const ssid
    • network SSID - Case Sensitive
  • Const password
    • WiFi Network password - Case Sensitive
  • Const domoticz_server
    • Domoticz Server IP Address (Typically a Fixed Local Address)
  • Variable port
    • Domoticz Network Port (Default)
  • Variable EnableDomoticz
    • Default false
    • Change to true to enable read Loop and sending data to Domoticz.
    • Important - You WILL need to setup hardware index in Domoticz
  • Domoticz Hardware Device Indexes
    • A number of variables, prefixed with 'idx', are used to enable, or disable, publishing of the related data.
      • Default of these index variables is 0.
      • Device needs to be created in Domoticz.

Further information on Domoticz setup can be found in Wiki