|
SparkFun Qwiic Current Sensor - ADE7953
v1.0.0-3-g9a02684
Arduino Library for the SparkFun Qwiic Current Sensor (ADE7953)
|
Platform-independent driver for the ADE7953 energy metering IC. More...
#include <sfDevADE7953.h>
Public Member Functions | |
| 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... | |
Protected Member Functions | |
| sfTkError_t | applyDefaultConfig (void) |
| Apply the datasheet unlock + optimize sequence and default configuration. More... | |
Static Protected Member Functions | |
| 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 | |
| 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 | |
| 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... | |
Platform-independent driver for the ADE7953 energy metering IC.
This class implements register-level access to the ADE7953 via the SparkFun Toolkit bus interface. Most methods return a SparkFun Toolkit error code (::ksfTkErrOk on success, a negative value on error); values read from the device are returned through reference (output) parameters. Callers that do not care about error handling can simply ignore the returned code.
|
inline |
|
protected |
| sfTkError_t sfDevADE7953::autoCalibrateA | ( | uint16_t | numSamples = 50 | ) |
Auto-calibrate the Channel A no-load baseline by averaging samples.
Reads numSamples raw IRMS samples (which must be taken with NO current flowing) and stores their average as a software noise floor. getCurrentA() then removes it in the squared domain — corrected = sqrt(reading^2 - baseline^2) — which is the physically correct way to subtract an RMS noise floor and needs no datasheet-specific scaling. This leaves the hardware AIRMSOS register untouched.
| numSamples | Number of samples to average (must be > 0). |
| sfTkError_t sfDevADE7953::autoCalibrateB | ( | uint16_t | numSamples = 50 | ) |
Auto-calibrate the Channel B no-load baseline by averaging samples.
| numSamples | Number of samples to average (must be > 0). |
| sfTkError_t sfDevADE7953::begin | ( | sfTkIBus * | theBus = nullptr | ) |
Initialize the device driver with the given bus.
Verifies the device is responding, configures big-endian byte order, applies the optimized performance register sequence required by the datasheet, and sets sensible default gain / HPF configuration so a basic sketch works without any further setup.
| theBus | Pointer to the initialized bus object. If null, a bus set by a prior call is used. |
|
staticprotected |
Look up the turns ratio and PGA gain for a known current clamp preset.
| clamp | One of the supported clamps (see sfe_ade7953_clamp_t). |
| ratio | Output reference that receives the clamp's turns ratio. |
| gain | Output reference that receives the clamp's recommended PGA gain. |
| void sfDevADE7953::clearCalibration | ( | void | ) |
Clear the software no-load baseline for both channels (set by autoCalibrate).
| sfTkError_t sfDevADE7953::enableHPF | ( | bool | enable | ) |
Enable or disable the high-pass filter on all channels.
The HPF removes DC offset before RMS computation. It should be enabled for accurate IRMS readings, and is enabled by default after power-on reset and by begin().
| enable | True to enable the HPF, false to disable. |
| sfTkError_t sfDevADE7953::enableZXLPF | ( | bool | enable | ) |
Enable or disable the zero-crossing low-pass filter.
| enable | True to enable the LPF, false to disable. |
| float sfDevADE7953::getBurdenResistor | ( | void | ) |
Get the configured burden resistor value.
| sfTkError_t sfDevADE7953::getCurrentA | ( | float & | amps | ) |
Read the RMS current on Channel A converted to amps.
Combines the raw IRMS reading with the configured PGA gain, CT ratio, burden resistor, and full-scale constants. The PGA gain is read from the device on each call, so the conversion always matches the active gain.
| amps | Output reference that receives the current in amps. |
| sfTkError_t sfDevADE7953::getCurrentB | ( | float & | amps | ) |
Read the RMS current on Channel B converted to amps.
| amps | Output reference that receives the current in amps. |
| float sfDevADE7953::getCurrentTransformerRatio | ( | void | ) |
Get the configured CT turns ratio for Channel A.
| float sfDevADE7953::getCurrentTransformerRatioA | ( | void | ) |
Get the configured CT turns ratio for Channel A.
| float sfDevADE7953::getCurrentTransformerRatioB | ( | void | ) |
Get the configured CT turns ratio for Channel B.
| sfTkError_t sfDevADE7953::getDigitalGainIA | ( | float & | multiplier | ) |
Get the digital gain for Current Channel A as a floating-point multiplier.
| multiplier | Output reference that receives the gain multiplier (1.0 = unity). |
| sfTkError_t sfDevADE7953::getDigitalGainIA | ( | uint32_t & | gain | ) |
Get the digital gain for Current Channel A as a raw register value.
| gain | Output reference that receives the digital gain register value. |
| sfTkError_t sfDevADE7953::getDigitalGainIB | ( | float & | multiplier | ) |
Get the digital gain for Current Channel B as a floating-point multiplier.
| multiplier | Output reference that receives the gain multiplier (1.0 = unity). |
| sfTkError_t sfDevADE7953::getDigitalGainIB | ( | uint32_t & | gain | ) |
Get the digital gain for Current Channel B as a raw register value.
| gain | Output reference that receives the digital gain register value. |
| sfTkError_t sfDevADE7953::getGainIA | ( | sfe_ade7953_pga_gain_t & | gain | ) |
Get the PGA gain for Current Channel A.
| gain | Output reference that receives the PGA gain setting. |
| sfTkError_t sfDevADE7953::getGainIB | ( | sfe_ade7953_pga_gain_t & | gain | ) |
Get the PGA gain for Current Channel B.
| gain | Output reference that receives the PGA gain setting. |
| sfTkError_t sfDevADE7953::getGainV | ( | sfe_ade7953_pga_gain_t & | gain | ) |
Get the PGA gain for the voltage channel.
| gain | Output reference that receives the PGA gain setting. |
| sfTkError_t sfDevADE7953::getInstantaneousIA | ( | int32_t & | value | ) |
Read the instantaneous current sample for Channel A.
| value | Output reference that receives the signed instantaneous current value. |
| sfTkError_t sfDevADE7953::getInstantaneousIB | ( | int32_t & | value | ) |
Read the instantaneous current sample for Channel B.
| value | Output reference that receives the signed instantaneous current value. |
| sfTkError_t sfDevADE7953::getInterruptEnableA | ( | sfe_ade7953_irq_reg_t & | mask | ) |
Get the interrupt enable mask for Channel A.
| mask | Output reference that receives the interrupt enable bitfield. |
| sfTkError_t sfDevADE7953::getInterruptEnableB | ( | sfe_ade7953_irq_reg_t & | mask | ) |
Get the interrupt enable mask for Channel B.
| mask | Output reference that receives the interrupt enable bitfield. |
| sfTkError_t sfDevADE7953::getInterruptStatusA | ( | sfe_ade7953_irq_reg_t & | status | ) |
Read the interrupt status for Channel A (non-destructive).
| status | Output reference that receives the interrupt status bitfield. |
| sfTkError_t sfDevADE7953::getInterruptStatusB | ( | sfe_ade7953_irq_reg_t & | status | ) |
Read the interrupt status for Channel B (non-destructive).
| status | Output reference that receives the interrupt status bitfield. |
| sfTkError_t sfDevADE7953::getIRMSA | ( | uint32_t & | value | ) |
Read the raw IRMS value for Current Channel A.
| value | Output reference that receives the raw unsigned IRMS value. |
| sfTkError_t sfDevADE7953::getIRMSB | ( | uint32_t & | value | ) |
Read the raw IRMS value for Current Channel B.
| value | Output reference that receives the raw unsigned IRMS value. |
| sfTkError_t sfDevADE7953::getIRMSOffsetA | ( | int32_t & | offset | ) |
Get the IRMS offset for Current Channel A.
| offset | Output reference that receives the signed offset value. |
| sfTkError_t sfDevADE7953::getIRMSOffsetB | ( | int32_t & | offset | ) |
Get the IRMS offset for Current Channel B.
| offset | Output reference that receives the signed offset value. |
| sfTkError_t sfDevADE7953::getLastAddress | ( | uint16_t & | address | ) |
Get the address of the last successful communication.
| address | Output reference that receives the register address. |
| sfTkError_t sfDevADE7953::getLastData16 | ( | uint16_t & | data | ) |
Get the data from the last successful 16-bit register communication.
| data | Output reference that receives the data value. |
| sfTkError_t sfDevADE7953::getLastData32 | ( | uint32_t & | data | ) |
Get the data from the last successful 24/32-bit register communication.
| data | Output reference that receives the data value. |
| sfTkError_t sfDevADE7953::getLastData8 | ( | uint8_t & | data | ) |
Get the data from the last successful 8-bit register communication.
| data | Output reference that receives the data value. |
| sfTkError_t sfDevADE7953::getLastOperation | ( | uint8_t & | op | ) |
Get the type of the last successful communication.
| op | Output reference that receives 0x35 for a read or 0xCA for a write. |
| sfTkError_t sfDevADE7953::getLineCycleCount | ( | uint16_t & | halfCycles | ) |
Get the number of half line cycles for line cycle accumulation.
| halfCycles | Output reference that receives the number of half cycles. |
| sfTkError_t sfDevADE7953::getLineCycleMode | ( | sfe_ade7953_lcycmode_reg_t & | mode | ) |
Get the line cycle accumulation mode register.
| mode | Output reference that receives the line cycle mode bitfield. |
| sfTkError_t sfDevADE7953::getNoLoadDisable | ( | sfe_ade7953_disnoload_reg_t & | mask | ) |
Get the no-load detection disable register.
| mask | Output reference that receives the no-load disable bitfield. |
| sfTkError_t sfDevADE7953::getOvercurrentLevel | ( | uint32_t & | level | ) |
Get the overcurrent detection threshold.
| level | Output reference that receives the threshold level. |
| sfTkError_t sfDevADE7953::getPeakIA | ( | uint32_t & | value | ) |
Read the peak current value for Channel A.
| value | Output reference that receives the peak value. |
| sfTkError_t sfDevADE7953::getPeakIB | ( | uint32_t & | value | ) |
Read the peak current value for Channel B.
| value | Output reference that receives the peak value. |
| sfTkError_t sfDevADE7953::getPeriod | ( | uint16_t & | period | ) |
Read the line period derived from zero-crossing detection.
| period | Output reference that receives the period register value. |
| sfTkError_t sfDevADE7953::getSagCycles | ( | uint8_t & | cycles | ) |
Get the number of sag line cycles.
| cycles | Output reference that receives the number of half line cycles. |
| sfTkError_t sfDevADE7953::getSagLevel | ( | uint32_t & | level | ) |
Get the sag voltage level threshold.
| level | Output reference that receives the sag level. |
| sfTkError_t sfDevADE7953::getVersion | ( | uint8_t & | version | ) |
Read the silicon version number from the Version register (0x702).
| version | Output reference that receives the silicon version. |
| sfTkError_t sfDevADE7953::getWriteProtect | ( | uint8_t & | protect | ) |
Get the current write protection setting.
| protect | Output reference that receives the write protection value (Bits[2:0]). |
| sfTkError_t sfDevADE7953::getZXEdge | ( | sfe_ade7953_zx_edge_t & | edge | ) |
Get the current zero-crossing edge selection.
| edge | Output reference that receives the edge selection value. |
| sfTkError_t sfDevADE7953::getZXISourceChannel | ( | bool & | useChannelB | ) |
Get which current channel drives the ZX_I output.
| useChannelB | Output reference set true if Channel B drives ZX_I, false for Channel A. |
| bool sfDevADE7953::isConnected | ( | void | ) |
Check whether the ADE7953 is connected and responding.
| sfTkError_t sfDevADE7953::isHPFEnabled | ( | bool & | enabled | ) |
Check whether the high-pass filter is currently enabled.
| enabled | Output reference set true if the HPF is enabled. |
|
staticprotected |
Convert a PGA gain enum value to its numeric multiplier (1, 2, 4, 8, 16, 22).
| sfTkError_t sfDevADE7953::readAndResetInterruptStatusA | ( | sfe_ade7953_irq_reg_t & | status | ) |
Read the interrupt status for Channel A and clear it.
Reads the read-with-reset register, returning the status and clearing the flags in a single operation.
| status | Output reference that receives the interrupt status bitfield before reset. |
| sfTkError_t sfDevADE7953::readAndResetInterruptStatusB | ( | sfe_ade7953_irq_reg_t & | status | ) |
Read the interrupt status for Channel B and clear it.
| status | Output reference that receives the interrupt status bitfield before reset. |
| sfTkError_t sfDevADE7953::readAndResetPeakIA | ( | uint32_t & | value | ) |
Read the peak current value for Channel A and clear it.
Reads the read-with-reset register, which returns the peak value and clears it in a single operation.
| value | Output reference that receives the peak value before reset. |
| sfTkError_t sfDevADE7953::readAndResetPeakIB | ( | uint32_t & | value | ) |
Read the peak current value for Channel B and clear it.
| value | Output reference that receives the peak value before reset. |
|
staticprotected |
Remove a no-load baseline from a raw RMS reading in the squared domain.
| sfTkError_t sfDevADE7953::reset | ( | void | ) |
Perform a software reset and re-apply the datasheet performance configuration.
Asserts the CONFIG SWRST bit. Because a reset returns all registers to their power-on defaults, this method re-runs the unlock + optimize sequence (and default gain / HPF configuration) afterward so the device is left in the same state as a fresh begin().
| void sfDevADE7953::setBurdenResistor | ( | float | ohms | ) |
Set the burden resistor value (in ohms) used by getCurrentA() / getCurrentB().
| ohms | Burden resistor value in ohms. |
| void sfDevADE7953::setCurrentClamp | ( | float | turnsRatio | ) |
Configure a custom current clamp on both channels by its turns ratio.
Use this for a clamp that is not one of the presets. Only the CT ratio is changed; the PGA gain is left as-is (set it with setGainIA()/setGainIB() if needed).
| turnsRatio | Turns ratio of the current transformer (e.g. 2000.0 for 30A:15mA). |
| sfTkError_t sfDevADE7953::setCurrentClamp | ( | sfe_ade7953_clamp_t | clamp | ) |
Select a known current clamp and apply its turns ratio and PGA gain to both channels.
Sets the CT ratio used by getCurrentA()/getCurrentB() and writes a suitable PGA gain to both current channels for the board's 5.6 ohm burden resistor. To use a different clamp on each channel, call setCurrentClampA()/setCurrentClampB() instead.
| clamp | One of the supported clamps (see sfe_ade7953_clamp_t). |
| void sfDevADE7953::setCurrentClampA | ( | float | turnsRatio | ) |
Configure a custom current clamp on Channel A by its turns ratio.
Only the Channel A CT ratio is changed; the PGA gain is left as-is. Pass 1.0 to measure Channel A directly (no current transformer).
| turnsRatio | Turns ratio of the current transformer (e.g. 2000.0 for 30A:15mA). |
| sfTkError_t sfDevADE7953::setCurrentClampA | ( | sfe_ade7953_clamp_t | clamp | ) |
Select a known current clamp for Channel A and apply its turns ratio and PGA gain.
Sets the Channel A CT ratio used by getCurrentA() and writes a suitable PGA gain to Channel A only. Channel B is left unchanged.
| clamp | One of the supported clamps (see sfe_ade7953_clamp_t). |
| void sfDevADE7953::setCurrentClampB | ( | float | turnsRatio | ) |
Configure a custom current clamp on Channel B by its turns ratio.
Only the Channel B CT ratio is changed; the PGA gain is left as-is. Pass 1.0 to measure Channel B directly (no current transformer).
| turnsRatio | Turns ratio of the current transformer (e.g. 2000.0 for 30A:15mA). |
| sfTkError_t sfDevADE7953::setCurrentClampB | ( | sfe_ade7953_clamp_t | clamp | ) |
Select a known current clamp for Channel B and apply its turns ratio and PGA gain.
Sets the Channel B CT ratio used by getCurrentB() and writes a suitable PGA gain to Channel B only. Channel A is left unchanged.
| clamp | One of the supported clamps (see sfe_ade7953_clamp_t). |
| void sfDevADE7953::setCurrentTransformerRatio | ( | float | ratio | ) |
Set the CT (current transformer) turns ratio used by getCurrentA() and getCurrentB().
Sets both channels to the same ratio. Use setCurrentTransformerRatioA() / setCurrentTransformerRatioB() to give each channel its own ratio.
| ratio | Turns ratio of the current transformer (e.g. 2000.0 for a 30A:15mA clamp). |
| void sfDevADE7953::setCurrentTransformerRatioA | ( | float | ratio | ) |
Set the CT turns ratio used by getCurrentA() for Channel A.
| ratio | Turns ratio of the current transformer (e.g. 2000.0 for a 30A:15mA clamp). |
| void sfDevADE7953::setCurrentTransformerRatioB | ( | float | ratio | ) |
Set the CT turns ratio used by getCurrentB() for Channel B.
| ratio | Turns ratio of the current transformer (e.g. 2000.0 for a 30A:15mA clamp). |
| sfTkError_t sfDevADE7953::setDigitalGainIA | ( | float | multiplier | ) |
Set the digital (fine) gain for Current Channel A using a floating-point multiplier.
Converts the multiplier to the nearest valid register value (0x400000 = 1.0x).
| multiplier | Desired gain multiplier (must be > 0 and within the representable range). |
| sfTkError_t sfDevADE7953::setDigitalGainIA | ( | uint32_t | gain | ) |
Set the digital (fine) gain for Current Channel A using a raw register value.
| gain | Digital gain register value (0x400000 = unity). |
| sfTkError_t sfDevADE7953::setDigitalGainIB | ( | float | multiplier | ) |
Set the digital (fine) gain for Current Channel B using a floating-point multiplier.
| multiplier | Desired gain multiplier (must be > 0 and within the representable range). |
| sfTkError_t sfDevADE7953::setDigitalGainIB | ( | uint32_t | gain | ) |
Set the digital (fine) gain for Current Channel B using a raw register value.
| gain | Digital gain register value (0x400000 = unity). |
| sfTkError_t sfDevADE7953::setGainIA | ( | sfe_ade7953_pga_gain_t | gain | ) |
Set the PGA gain for Current Channel A.
| gain | PGA gain setting (see sfe_ade7953_pga_gain_t). |
| sfTkError_t sfDevADE7953::setGainIB | ( | sfe_ade7953_pga_gain_t | gain | ) |
Set the PGA gain for Current Channel B.
| gain | PGA gain setting. |
| sfTkError_t sfDevADE7953::setGainV | ( | sfe_ade7953_pga_gain_t | gain | ) |
Set the PGA gain for the voltage channel.
| gain | PGA gain setting. |
| sfTkError_t sfDevADE7953::setInterruptEnableA | ( | sfe_ade7953_irq_reg_t | mask | ) |
Set the interrupt enable mask for Channel A (and voltage).
| mask | Interrupt enable bitfield struct. |
| sfTkError_t sfDevADE7953::setInterruptEnableB | ( | sfe_ade7953_irq_reg_t | mask | ) |
Set the interrupt enable mask for Channel B.
Only bits [13:0] are valid for Channel B.
| mask | Interrupt enable bitfield struct. |
| sfTkError_t sfDevADE7953::setIRMSOffsetA | ( | int32_t | offset | ) |
Set the IRMS offset for Current Channel A.
N raw counts the offset is approximately -(N*N) scaled per the datasheet, not -N. | offset | Signed offset value for IRMS correction. |
| sfTkError_t sfDevADE7953::setIRMSOffsetB | ( | int32_t | offset | ) |
Set the IRMS offset for Current Channel B.
See setIRMSOffsetA() for the squared-domain note.
| offset | Signed offset value for IRMS correction. |
| sfTkError_t sfDevADE7953::setLineCycleCount | ( | uint16_t | halfCycles | ) |
Set the number of half line cycles for line cycle accumulation.
| halfCycles | Number of half cycles. |
| sfTkError_t sfDevADE7953::setLineCycleMode | ( | sfe_ade7953_lcycmode_reg_t | mode | ) |
Set the line cycle accumulation mode register.
| mode | Line cycle mode bitfield struct. |
| sfTkError_t sfDevADE7953::setNoLoadDisable | ( | sfe_ade7953_disnoload_reg_t | mask | ) |
Set the no-load detection disable register.
| mask | No-load disable bitfield struct. |
| sfTkError_t sfDevADE7953::setOvercurrentLevel | ( | uint32_t | level | ) |
Set the overcurrent detection threshold.
| level | Threshold level (24-bit value). |
| sfTkError_t sfDevADE7953::setSagCycles | ( | uint8_t | cycles | ) |
Set the number of sag line cycles.
| cycles | Number of half line cycles for sag detection. |
| sfTkError_t sfDevADE7953::setSagLevel | ( | uint32_t | level | ) |
Set the sag voltage level threshold.
| level | Sag level threshold (24-bit value). |
| sfTkError_t sfDevADE7953::setWriteProtect | ( | uint8_t | protect | ) |
Set write protection bits.
| protect | Write protection value (Bits[2:0]). |
| sfTkError_t sfDevADE7953::setZXEdge | ( | sfe_ade7953_zx_edge_t | edge | ) |
Set the zero-crossing edge selection for interrupt generation.
| edge | Edge selection (see sfe_ade7953_zx_edge_t). |
| sfTkError_t sfDevADE7953::setZXISourceChannel | ( | bool | useChannelB | ) |
Select which current channel drives the ZX_I output.
| useChannelB | If true, ZX_I is based on Channel B; if false, Channel A. |
|
protected |
Channel A no-load IRMS baseline (raw counts).
|
protected |
Channel B no-load IRMS baseline (raw counts).
|
protected |
Burden resistor in ohms.
|
protected |
Channel A CT turns ratio (30A:15mA = 2000:1).
|
protected |
Channel B CT turns ratio (30A:15mA = 2000:1).
|
protected |
ADE7953 full-scale IRMS code.
|
protected |
Full-scale input RMS voltage (0.5 V peak / sqrt(2)).
|
protected |
Pointer to the communication bus device.
|
staticprotected |
Maximum valid digital gain register value.
|
staticprotected |
Digital gain register value for 1.0x.
|
staticprotected |
7-bit I2C address for the ADE7953 (only address).
|
staticprotected |
Last operation was a read.
|
staticprotected |
Last operation was a write.
|
staticprotected |
Value written to 0x120 for rated performance.
|
staticprotected |
Accumulation mode.
|
staticprotected |
Active energy (Channel A)
|
staticprotected |
Active energy (Channel B)
|
staticprotected |
Current channel gain (Channel A)
|
staticprotected |
IRMS offset (Channel A)
|
staticprotected |
Alternative output functions.
|
staticprotected |
Angle between voltage and Current Channel A.
|
staticprotected |
Angle between voltage and Current Channel B.
|
staticprotected |
Apparent energy (Channel A)
|
staticprotected |
Apparent energy (Channel B)
|
staticprotected |
Active power no-load level.
|
staticprotected |
Instantaneous apparent power (Channel A)
|
staticprotected |
Apparent power gain (Channel A)
|
staticprotected |
Apparent power offset (Channel A)
|
staticprotected |
Instantaneous reactive power (Channel A)
|
staticprotected |
Reactive power gain (Channel A)
|
staticprotected |
Reactive power offset (Channel A)
|
staticprotected |
Voltage channel gain.
|
staticprotected |
Instantaneous active power (Channel A)
|
staticprotected |
Active power offset (Channel A)
|
staticprotected |
Active power gain (Channel A)
|
staticprotected |
Current channel gain (Channel B)
|
staticprotected |
IRMS offset (Channel B)
|
staticprotected |
Instantaneous apparent power (Channel B)
|
staticprotected |
Apparent power gain (Channel B)
|
staticprotected |
Apparent power offset (Channel B)
|
staticprotected |
Instantaneous reactive power (Channel B)
|
staticprotected |
Reactive power gain (Channel B)
|
staticprotected |
Reactive power offset (Channel B)
|
staticprotected |
Instantaneous active power (Channel B)
|
staticprotected |
Active power offset (Channel B)
|
staticprotected |
Active power gain (Channel B)
|
staticprotected |
CF1 frequency divider denominator.
|
staticprotected |
CF2 frequency divider denominator.
|
staticprotected |
CF output selection.
|
staticprotected |
Configuration register.
|
staticprotected |
Checksum (32-bit only)
|
staticprotected |
No-load detection disable.
|
staticprotected |
Reference input config (0=internal, 1=external)
|
staticprotected |
Instantaneous current (Channel A)
|
staticprotected |
Current Channel A peak.
|
staticprotected |
Instantaneous current (Channel B)
|
staticprotected |
Current Channel B peak.
|
staticprotected |
IRMS (Channel A)
|
staticprotected |
IRMS (Channel B)
|
staticprotected |
Interrupt enable (Channel A + voltage)
|
staticprotected |
Interrupt enable (Channel B)
|
staticprotected |
Interrupt status (Channel A + voltage)
|
staticprotected |
Interrupt status (Channel B)
|
staticprotected |
Last successful communication address.
|
staticprotected |
Last operation type (0x35=read, 0xCA=write)
|
staticprotected |
Last successful 16-bit register data.
|
staticprotected |
Last successful 24/32-bit register data.
|
staticprotected |
Last successful 8-bit register data.
|
staticprotected |
Line cycle accumulation mode config.
|
staticprotected |
Half line cycles for line cycle accumulation.
|
staticprotected |
Overcurrent level.
|
staticprotected |
Performance optimization (set to 0x0030)
|
staticprotected |
Overvoltage level.
|
staticprotected |
Period register (line period from ZX)
|
staticprotected |
Power factor (Channel A)
|
staticprotected |
Power factor (Channel B)
|
staticprotected |
Current Channel A PGA gain (Bits[2:0])
|
staticprotected |
Current Channel B PGA gain (Bits[2:0])
|
staticprotected |
Voltage channel PGA gain (Bits[2:0])
|
staticprotected |
Phase calibration (Channel A)
|
staticprotected |
Phase calibration (Channel B)
|
staticprotected |
Reactive energy (Channel A)
|
staticprotected |
Reactive energy (Channel B)
|
staticprotected |
Current Channel A peak read with reset.
|
staticprotected |
Current Channel B peak read with reset.
|
staticprotected |
Reset interrupt status (Channel A + voltage)
|
staticprotected |
Reset interrupt status (Channel B)
|
staticprotected |
Voltage peak read with reset.
|
staticprotected |
Sag line cycles.
|
staticprotected |
Sag voltage level.
|
staticprotected |
Register unlock (write key to unlock 0x120)
|
staticprotected |
Instantaneous voltage.
|
staticprotected |
Apparent power no-load level.
|
staticprotected |
Reactive power no-load level.
|
staticprotected |
Silicon version number.
|
staticprotected |
Voltage channel peak.
|
staticprotected |
VRMS.
|
staticprotected |
VRMS offset.
|
staticprotected |
Write protection bits (Bits[2:0])
|
staticprotected |
Zero-crossing timeout.
|
staticprotected |
Key written to kRegUnlock to unlock 0x120.