|
SparkFun Qwiic Current Sensor - ADE7953
v1.0.0-3-g9a02684
Arduino Library for the SparkFun Qwiic Current Sensor (ADE7953)
|
Arduino I2C implementation for the ADE7953 energy meter. More...
#include <SparkFun_ADE7953.h>
Public Member Functions | |
| SfeADE7953ArdI2C () | |
| bool | begin (uint8_t address=kI2CAddress, TwoWire &wirePort=Wire) |
| Initializes the ADE7953 with I2C communication. More... | |
Public Member Functions inherited from sfDevADE7953 | |
| sfDevADE7953 () | |
| sfTkError_t | begin (sfTkIBus *theBus=nullptr) |
| Initialize the device driver with the given bus. More... | |
| bool | isConnected (void) |
| Check whether the ADE7953 is connected and responding. More... | |
| sfTkError_t | getVersion (uint8_t &version) |
| Read the silicon version number from the Version register (0x702). More... | |
| sfTkError_t | reset (void) |
| Perform a software reset and re-apply the datasheet performance configuration. More... | |
| sfTkError_t | setWriteProtect (uint8_t protect) |
| Set write protection bits. More... | |
| sfTkError_t | getWriteProtect (uint8_t &protect) |
| Get the current write protection setting. More... | |
| sfTkError_t | setGainIA (sfe_ade7953_pga_gain_t gain) |
| Set the PGA gain for Current Channel A. More... | |
| sfTkError_t | getGainIA (sfe_ade7953_pga_gain_t &gain) |
| Get the PGA gain for Current Channel A. More... | |
| sfTkError_t | setGainIB (sfe_ade7953_pga_gain_t gain) |
| Set the PGA gain for Current Channel B. More... | |
| sfTkError_t | getGainIB (sfe_ade7953_pga_gain_t &gain) |
| Get the PGA gain for Current Channel B. More... | |
| sfTkError_t | setGainV (sfe_ade7953_pga_gain_t gain) |
| Set the PGA gain for the voltage channel. More... | |
| sfTkError_t | getGainV (sfe_ade7953_pga_gain_t &gain) |
| Get the PGA gain for the voltage channel. More... | |
| sfTkError_t | setDigitalGainIA (uint32_t gain) |
| Set the digital (fine) gain for Current Channel A using a raw register value. More... | |
| sfTkError_t | setDigitalGainIA (float multiplier) |
| Set the digital (fine) gain for Current Channel A using a floating-point multiplier. More... | |
| sfTkError_t | getDigitalGainIA (uint32_t &gain) |
| Get the digital gain for Current Channel A as a raw register value. More... | |
| sfTkError_t | getDigitalGainIA (float &multiplier) |
| Get the digital gain for Current Channel A as a floating-point multiplier. More... | |
| sfTkError_t | setDigitalGainIB (uint32_t gain) |
| Set the digital (fine) gain for Current Channel B using a raw register value. More... | |
| sfTkError_t | setDigitalGainIB (float multiplier) |
| Set the digital (fine) gain for Current Channel B using a floating-point multiplier. More... | |
| sfTkError_t | getDigitalGainIB (uint32_t &gain) |
| Get the digital gain for Current Channel B as a raw register value. More... | |
| sfTkError_t | getDigitalGainIB (float &multiplier) |
| Get the digital gain for Current Channel B as a floating-point multiplier. More... | |
| sfTkError_t | getIRMSA (uint32_t &value) |
| Read the raw IRMS value for Current Channel A. More... | |
| sfTkError_t | getIRMSB (uint32_t &value) |
| Read the raw IRMS value for Current Channel B. More... | |
| sfTkError_t | getCurrentA (float &s) |
| Read the RMS current on Channel A converted to amps. More... | |
| sfTkError_t | getCurrentB (float &s) |
| Read the RMS current on Channel B converted to amps. More... | |
| sfTkError_t | getInstantaneousIA (int32_t &value) |
| Read the instantaneous current sample for Channel A. More... | |
| sfTkError_t | getInstantaneousIB (int32_t &value) |
| Read the instantaneous current sample for Channel B. More... | |
| sfTkError_t | setCurrentClamp (sfe_ade7953_clamp_t clamp) |
| Select a known current clamp and apply its turns ratio and PGA gain to both channels. More... | |
| sfTkError_t | setCurrentClampA (sfe_ade7953_clamp_t clamp) |
| Select a known current clamp for Channel A and apply its turns ratio and PGA gain. More... | |
| sfTkError_t | setCurrentClampB (sfe_ade7953_clamp_t clamp) |
| Select a known current clamp for Channel B and apply its turns ratio and PGA gain. More... | |
| void | setCurrentClamp (float turnsRatio) |
| Configure a custom current clamp on both channels by its turns ratio. More... | |
| void | setCurrentClampA (float turnsRatio) |
| Configure a custom current clamp on Channel A by its turns ratio. More... | |
| void | setCurrentClampB (float turnsRatio) |
| Configure a custom current clamp on Channel B by its turns ratio. More... | |
| void | setCurrentTransformerRatio (float ratio) |
| Set the CT (current transformer) turns ratio used by getCurrentA() and getCurrentB(). More... | |
| void | setCurrentTransformerRatioA (float ratio) |
| Set the CT turns ratio used by getCurrentA() for Channel A. More... | |
| void | setCurrentTransformerRatioB (float ratio) |
| Set the CT turns ratio used by getCurrentB() for Channel B. More... | |
| float | getCurrentTransformerRatio (void) |
| Get the configured CT turns ratio for Channel A. More... | |
| float | getCurrentTransformerRatioA (void) |
| Get the configured CT turns ratio for Channel A. More... | |
| float | getCurrentTransformerRatioB (void) |
| Get the configured CT turns ratio for Channel B. More... | |
| void | setBurdenResistor (float ohms) |
| Set the burden resistor value (in ohms) used by getCurrentA() / getCurrentB(). More... | |
| float | getBurdenResistor (void) |
| Get the configured burden resistor value. More... | |
| sfTkError_t | autoCalibrateA (uint16_t numSamples=50) |
| Auto-calibrate the Channel A no-load baseline by averaging samples. More... | |
| sfTkError_t | autoCalibrateB (uint16_t numSamples=50) |
| Auto-calibrate the Channel B no-load baseline by averaging samples. More... | |
| void | clearCalibration (void) |
| Clear the software no-load baseline for both channels (set by autoCalibrate). More... | |
| sfTkError_t | getPeakIA (uint32_t &value) |
| Read the peak current value for Channel A. More... | |
| sfTkError_t | getPeakIB (uint32_t &value) |
| Read the peak current value for Channel B. More... | |
| sfTkError_t | readAndResetPeakIA (uint32_t &value) |
| Read the peak current value for Channel A and clear it. More... | |
| sfTkError_t | readAndResetPeakIB (uint32_t &value) |
| Read the peak current value for Channel B and clear it. More... | |
| sfTkError_t | setOvercurrentLevel (uint32_t level) |
| Set the overcurrent detection threshold. More... | |
| sfTkError_t | getOvercurrentLevel (uint32_t &level) |
| Get the overcurrent detection threshold. More... | |
| sfTkError_t | setIRMSOffsetA (int32_t offset) |
| Set the IRMS offset for Current Channel A. More... | |
| sfTkError_t | getIRMSOffsetA (int32_t &offset) |
| Get the IRMS offset for Current Channel A. More... | |
| sfTkError_t | setIRMSOffsetB (int32_t offset) |
| Set the IRMS offset for Current Channel B. More... | |
| sfTkError_t | getIRMSOffsetB (int32_t &offset) |
| Get the IRMS offset for Current Channel B. More... | |
| sfTkError_t | setZXISourceChannel (bool useChannelB) |
| Select which current channel drives the ZX_I output. More... | |
| sfTkError_t | getZXISourceChannel (bool &useChannelB) |
| Get which current channel drives the ZX_I output. More... | |
| sfTkError_t | setZXEdge (sfe_ade7953_zx_edge_t edge) |
| Set the zero-crossing edge selection for interrupt generation. More... | |
| sfTkError_t | getZXEdge (sfe_ade7953_zx_edge_t &edge) |
| Get the current zero-crossing edge selection. More... | |
| sfTkError_t | enableZXLPF (bool enable) |
| Enable or disable the zero-crossing low-pass filter. More... | |
| sfTkError_t | enableHPF (bool enable) |
| Enable or disable the high-pass filter on all channels. More... | |
| sfTkError_t | isHPFEnabled (bool &enabled) |
| Check whether the high-pass filter is currently enabled. More... | |
| sfTkError_t | getPeriod (uint16_t &period) |
| Read the line period derived from zero-crossing detection. More... | |
| sfTkError_t | setInterruptEnableA (sfe_ade7953_irq_reg_t mask) |
| Set the interrupt enable mask for Channel A (and voltage). More... | |
| sfTkError_t | getInterruptEnableA (sfe_ade7953_irq_reg_t &mask) |
| Get the interrupt enable mask for Channel A. More... | |
| sfTkError_t | getInterruptStatusA (sfe_ade7953_irq_reg_t &status) |
| Read the interrupt status for Channel A (non-destructive). More... | |
| sfTkError_t | readAndResetInterruptStatusA (sfe_ade7953_irq_reg_t &status) |
| Read the interrupt status for Channel A and clear it. More... | |
| sfTkError_t | setInterruptEnableB (sfe_ade7953_irq_reg_t mask) |
| Set the interrupt enable mask for Channel B. More... | |
| sfTkError_t | getInterruptEnableB (sfe_ade7953_irq_reg_t &mask) |
| Get the interrupt enable mask for Channel B. More... | |
| sfTkError_t | getInterruptStatusB (sfe_ade7953_irq_reg_t &status) |
| Read the interrupt status for Channel B (non-destructive). More... | |
| sfTkError_t | readAndResetInterruptStatusB (sfe_ade7953_irq_reg_t &status) |
| Read the interrupt status for Channel B and clear it. More... | |
| sfTkError_t | setNoLoadDisable (sfe_ade7953_disnoload_reg_t mask) |
| Set the no-load detection disable register. More... | |
| sfTkError_t | getNoLoadDisable (sfe_ade7953_disnoload_reg_t &mask) |
| Get the no-load detection disable register. More... | |
| sfTkError_t | setLineCycleMode (sfe_ade7953_lcycmode_reg_t mode) |
| Set the line cycle accumulation mode register. More... | |
| sfTkError_t | getLineCycleMode (sfe_ade7953_lcycmode_reg_t &mode) |
| Get the line cycle accumulation mode register. More... | |
| sfTkError_t | setLineCycleCount (uint16_t halfCycles) |
| Set the number of half line cycles for line cycle accumulation. More... | |
| sfTkError_t | getLineCycleCount (uint16_t &halfCycles) |
| Get the number of half line cycles for line cycle accumulation. More... | |
| sfTkError_t | setSagCycles (uint8_t cycles) |
| Set the number of sag line cycles. More... | |
| sfTkError_t | getSagCycles (uint8_t &cycles) |
| Get the number of sag line cycles. More... | |
| sfTkError_t | setSagLevel (uint32_t level) |
| Set the sag voltage level threshold. More... | |
| sfTkError_t | getSagLevel (uint32_t &level) |
| Get the sag voltage level threshold. More... | |
| sfTkError_t | getLastOperation (uint8_t &op) |
| Get the type of the last successful communication. More... | |
| sfTkError_t | getLastAddress (uint16_t &address) |
| Get the address of the last successful communication. More... | |
| sfTkError_t | getLastData8 (uint8_t &data) |
| Get the data from the last successful 8-bit register communication. More... | |
| sfTkError_t | getLastData16 (uint16_t &data) |
| Get the data from the last successful 16-bit register communication. More... | |
| sfTkError_t | getLastData32 (uint32_t &data) |
| Get the data from the last successful 24/32-bit register communication. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from sfDevADE7953 | |
| sfTkError_t | applyDefaultConfig (void) |
| Apply the datasheet unlock + optimize sequence and default configuration. More... | |
Static Protected Member Functions inherited from sfDevADE7953 | |
| static float | pgaGainToMultiplier (sfe_ade7953_pga_gain_t gain) |
| Convert a PGA gain enum value to its numeric multiplier (1, 2, 4, 8, 16, 22). More... | |
| static void | clampPreset (sfe_ade7953_clamp_t clamp, float &ratio, sfe_ade7953_pga_gain_t &gain) |
| Look up the turns ratio and PGA gain for a known current clamp preset. More... | |
| static float | removeBaseline (uint32_t reading, uint32_t baseline) |
| Remove a no-load baseline from a raw RMS reading in the squared domain. More... | |
Protected Attributes inherited from sfDevADE7953 | |
| sfTkIBus * | _theBus |
| Pointer to the communication bus device. More... | |
| float | _ctRatioA = 2000.0f |
| Channel A CT turns ratio (30A:15mA = 2000:1). More... | |
| float | _ctRatioB = 2000.0f |
| Channel B CT turns ratio (30A:15mA = 2000:1). More... | |
| float | _burdenResistor = 5.6f |
| Burden resistor in ohms. More... | |
| float | _fullScaleCode = 5928256.0f |
| ADE7953 full-scale IRMS code. More... | |
| float | _fullScaleVRMS = 0.35355f |
| Full-scale input RMS voltage (0.5 V peak / sqrt(2)). More... | |
| uint32_t | _baselineA = 0 |
| Channel A no-load IRMS baseline (raw counts). More... | |
| uint32_t | _baselineB = 0 |
| Channel B no-load IRMS baseline (raw counts). More... | |
Static Protected Attributes inherited from sfDevADE7953 | |
| static const uint8_t | kI2CAddress = 0x38 |
| 7-bit I2C address for the ADE7953 (only address). More... | |
| static const uint16_t | kRegSagCyc = 0x000 |
| Sag line cycles. More... | |
| static const uint16_t | kRegDisNoLoad = 0x001 |
| No-load detection disable. More... | |
| static const uint16_t | kRegLCycMode = 0x004 |
| Line cycle accumulation mode config. More... | |
| static const uint16_t | kRegPgaV = 0x007 |
| Voltage channel PGA gain (Bits[2:0]) More... | |
| static const uint16_t | kRegPgaIA = 0x008 |
| Current Channel A PGA gain (Bits[2:0]) More... | |
| static const uint16_t | kRegPgaIB = 0x009 |
| Current Channel B PGA gain (Bits[2:0]) More... | |
| static const uint16_t | kRegWriteProtect = 0x040 |
| Write protection bits (Bits[2:0]) More... | |
| static const uint16_t | kRegLastOp = 0x0FD |
| Last operation type (0x35=read, 0xCA=write) More... | |
| static const uint16_t | kRegLastRwData8 = 0x0FF |
| Last successful 8-bit register data. More... | |
| static const uint16_t | kRegVersion = 0x702 |
| Silicon version number. More... | |
| static const uint16_t | kRegExRef = 0x800 |
| Reference input config (0=internal, 1=external) More... | |
| static const uint16_t | kRegUnlock = 0x0FE |
| Register unlock (write key to unlock 0x120) More... | |
| static const uint16_t | kRegZXTout = 0x100 |
| Zero-crossing timeout. More... | |
| static const uint16_t | kRegLineCyc = 0x101 |
| Half line cycles for line cycle accumulation. More... | |
| static const uint16_t | kRegConfig = 0x102 |
| Configuration register. More... | |
| static const uint16_t | kRegCF1Den = 0x103 |
| CF1 frequency divider denominator. More... | |
| static const uint16_t | kRegCF2Den = 0x104 |
| CF2 frequency divider denominator. More... | |
| static const uint16_t | kRegCFMode = 0x107 |
| CF output selection. More... | |
| static const uint16_t | kRegPhCalA = 0x108 |
| Phase calibration (Channel A) More... | |
| static const uint16_t | kRegPhCalB = 0x109 |
| Phase calibration (Channel B) More... | |
| static const uint16_t | kRegPFA = 0x10A |
| Power factor (Channel A) More... | |
| static const uint16_t | kRegPFB = 0x10B |
| Power factor (Channel B) More... | |
| static const uint16_t | kRegAngleA = 0x10C |
| Angle between voltage and Current Channel A. More... | |
| static const uint16_t | kRegAngleB = 0x10D |
| Angle between voltage and Current Channel B. More... | |
| static const uint16_t | kRegPeriod = 0x10E |
| Period register (line period from ZX) More... | |
| static const uint16_t | kRegAltOutput = 0x110 |
| Alternative output functions. More... | |
| static const uint16_t | kRegOptimize = 0x120 |
| Performance optimization (set to 0x0030) More... | |
| static const uint16_t | kRegLastAdd = 0x1FE |
| Last successful communication address. More... | |
| static const uint16_t | kRegLastRwData16 = 0x1FF |
| Last successful 16-bit register data. More... | |
| static const uint16_t | kRegSagLvl = 0x300 |
| Sag voltage level. More... | |
| static const uint16_t | kRegAccMode = 0x301 |
| Accumulation mode. More... | |
| static const uint16_t | kRegApNoLoad = 0x303 |
| Active power no-load level. More... | |
| static const uint16_t | kRegVarNoLoad = 0x304 |
| Reactive power no-load level. More... | |
| static const uint16_t | kRegVaNoLoad = 0x305 |
| Apparent power no-load level. More... | |
| static const uint16_t | kRegAVA = 0x310 |
| Instantaneous apparent power (Channel A) More... | |
| static const uint16_t | kRegBVA = 0x311 |
| Instantaneous apparent power (Channel B) More... | |
| static const uint16_t | kRegAWatt = 0x312 |
| Instantaneous active power (Channel A) More... | |
| static const uint16_t | kRegBWatt = 0x313 |
| Instantaneous active power (Channel B) More... | |
| static const uint16_t | kRegAVar = 0x314 |
| Instantaneous reactive power (Channel A) More... | |
| static const uint16_t | kRegBVar = 0x315 |
| Instantaneous reactive power (Channel B) More... | |
| static const uint16_t | kRegIA = 0x316 |
| Instantaneous current (Channel A) More... | |
| static const uint16_t | kRegIB = 0x317 |
| Instantaneous current (Channel B) More... | |
| static const uint16_t | kRegV = 0x318 |
| Instantaneous voltage. More... | |
| static const uint16_t | kRegIRMSA = 0x31A |
| IRMS (Channel A) More... | |
| static const uint16_t | kRegIRMSB = 0x31B |
| IRMS (Channel B) More... | |
| static const uint16_t | kRegVRMS = 0x31C |
| VRMS. More... | |
| static const uint16_t | kRegAEnergyA = 0x31E |
| Active energy (Channel A) More... | |
| static const uint16_t | kRegAEnergyB = 0x31F |
| Active energy (Channel B) More... | |
| static const uint16_t | kRegREnergyA = 0x320 |
| Reactive energy (Channel A) More... | |
| static const uint16_t | kRegREnergyB = 0x321 |
| Reactive energy (Channel B) More... | |
| static const uint16_t | kRegApEnergyA = 0x322 |
| Apparent energy (Channel A) More... | |
| static const uint16_t | kRegApEnergyB = 0x323 |
| Apparent energy (Channel B) More... | |
| static const uint16_t | kRegOvLvl = 0x324 |
| Overvoltage level. More... | |
| static const uint16_t | kRegOiLvl = 0x325 |
| Overcurrent level. More... | |
| static const uint16_t | kRegVPeak = 0x326 |
| Voltage channel peak. More... | |
| static const uint16_t | kRegRstVPeak = 0x327 |
| Voltage peak read with reset. More... | |
| static const uint16_t | kRegIAPeak = 0x328 |
| Current Channel A peak. More... | |
| static const uint16_t | kRegRstIAPeak = 0x329 |
| Current Channel A peak read with reset. More... | |
| static const uint16_t | kRegIBPeak = 0x32A |
| Current Channel B peak. More... | |
| static const uint16_t | kRegRstIBPeak = 0x32B |
| Current Channel B peak read with reset. More... | |
| static const uint16_t | kRegIrqEnA = 0x32C |
| Interrupt enable (Channel A + voltage) More... | |
| static const uint16_t | kRegIrqStatA = 0x32D |
| Interrupt status (Channel A + voltage) More... | |
| static const uint16_t | kRegRstIrqStatA = 0x32E |
| Reset interrupt status (Channel A + voltage) More... | |
| static const uint16_t | kRegIrqEnB = 0x32F |
| Interrupt enable (Channel B) More... | |
| static const uint16_t | kRegIrqStatB = 0x330 |
| Interrupt status (Channel B) More... | |
| static const uint16_t | kRegRstIrqStatB = 0x331 |
| Reset interrupt status (Channel B) More... | |
| static const uint16_t | kRegCRC = 0x37F |
| Checksum (32-bit only) More... | |
| static const uint16_t | kRegAIGain = 0x380 |
| Current channel gain (Channel A) More... | |
| static const uint16_t | kRegAVGain = 0x381 |
| Voltage channel gain. More... | |
| static const uint16_t | kRegAWGain = 0x382 |
| Active power gain (Channel A) More... | |
| static const uint16_t | kRegAVarGain = 0x383 |
| Reactive power gain (Channel A) More... | |
| static const uint16_t | kRegAVaGain = 0x384 |
| Apparent power gain (Channel A) More... | |
| static const uint16_t | kRegAIRMSOS = 0x386 |
| IRMS offset (Channel A) More... | |
| static const uint16_t | kRegVRMSOS = 0x388 |
| VRMS offset. More... | |
| static const uint16_t | kRegAWattOS = 0x389 |
| Active power offset (Channel A) More... | |
| static const uint16_t | kRegAVarOS = 0x38A |
| Reactive power offset (Channel A) More... | |
| static const uint16_t | kRegAVaOS = 0x38B |
| Apparent power offset (Channel A) More... | |
| static const uint16_t | kRegBIGain = 0x38C |
| Current channel gain (Channel B) More... | |
| static const uint16_t | kRegBWGain = 0x38E |
| Active power gain (Channel B) More... | |
| static const uint16_t | kRegBVarGain = 0x38F |
| Reactive power gain (Channel B) More... | |
| static const uint16_t | kRegBVaGain = 0x390 |
| Apparent power gain (Channel B) More... | |
| static const uint16_t | kRegBIRMSOS = 0x392 |
| IRMS offset (Channel B) More... | |
| static const uint16_t | kRegBWattOS = 0x395 |
| Active power offset (Channel B) More... | |
| static const uint16_t | kRegBVarOS = 0x396 |
| Reactive power offset (Channel B) More... | |
| static const uint16_t | kRegBVaOS = 0x397 |
| Apparent power offset (Channel B) More... | |
| static const uint16_t | kRegLastRwData32 = 0x3FF |
| Last successful 24/32-bit register data. More... | |
| static const uint8_t | kUnlockKey = 0xAD |
| Key written to kRegUnlock to unlock 0x120. More... | |
| static const uint16_t | kOptimizeValue = 0x0030 |
| Value written to 0x120 for rated performance. More... | |
| static const uint32_t | kDigitalGainUnity = 0x400000 |
| Digital gain register value for 1.0x. More... | |
| static const uint32_t | kDigitalGainMax = 0x7FFFFF |
| Maximum valid digital gain register value. More... | |
| static const uint8_t | kLastOpRead = 0x35 |
| Last operation was a read. More... | |
| static const uint8_t | kLastOpWrite = 0xCA |
| Last operation was a write. More... | |
Arduino I2C implementation for the ADE7953 energy meter.
This class provides Arduino-specific I2C communication for the ADE7953. It inherits all register access methods from sfDevADE7953 and adds the begin() method required for Arduino initialization. The class owns an sfTkArdI2C bus object which wraps the Arduino Wire library.
|
inline |
|
inline |
Initializes the ADE7953 with I2C communication.
Initializes the Toolkit I2C bus, confirms the device is present on the bus, then calls the base class begin() to verify the device identity, configure byte order, apply the optimized performance register sequence, and set default gain / HPF configuration.
| address | 7-bit I2C address of the device (the ADE7953 uses a single fixed address). |
| wirePort | TwoWire instance to use for I2C communication (default: Wire). |