ACS37800 library for Arduino
Loading...
Searching...
No Matches
ACS37800 Class Reference

Public Member Functions

 ACS37800 (uint8_t address=0x60, TwoWire *bus=&Wire)
 
void setBus (TwoWire *bus)
 
TwoWire * getBus ()
 
void setAddress (uint8_t address)
 
uint8_t getAddress ()
 
uint8_t getLastError ()
 
void setBoardPololu (uint8_t rsense_kohm)
 
void setBoardParameters (uint8_t isense_range, uint32_t riso, uint32_t rsense)
 
void enableWriteAccess ()
 
void setSampleCount (uint16_t count)
 
void readRMSVoltageAndCurrent ()
 
void readActiveAndReactivePower ()
 
int32_t readApparentPowerMilliwatts ()
 
void readInstVoltageAndCurrent ()
 
int32_t readInstPowerMilliwatts ()
 
int32_t readRMSVoltageMillivolts ()
 
int32_t readRMSCurrentMilliamps ()
 
int32_t readActivePowerMilliwatts ()
 
int32_t readReactivePowerMilliwatts ()
 
int32_t readInstVoltageMillivolts ()
 
int32_t readInstCurrentMilliamps ()
 
void writeEepromI2CAddress (uint8_t address)
 
uint32_t readReg (uint8_t reg)
 
void writeReg (uint8_t reg, uint32_t value)
 

Public Attributes

uint16_t vcodesMult = 1
 
uint16_t icodesMult = 1
 
uint16_t pinstantMult = 1
 
uint8_t vcodesShift = 0
 
uint8_t icodesShift = 0
 
uint8_t pinstantShift = 0
 
int32_t instVoltageMillivolts
 
int32_t instCurrentMilliamps
 
int32_t instPowerMilliwatts
 
int32_t rmsVoltageMillivolts
 
int32_t rmsCurrentMilliamps
 
int32_t activePowerMilliwatts
 
int32_t reactivePowerMilliwatts
 
int32_t apparentPowerMilliwatts
 

Detailed Description

Definition at line 16 of file ACS37800.h.

Constructor & Destructor Documentation

◆ ACS37800()

ACS37800::ACS37800 ( uint8_t address = 0x60,
TwoWire * bus = &Wire )
inline

Creates a new ACS37800 object.

The address parameter specifies the 7-bit I2C address to use, and it must match the address that the ACS37800 is configured to use.

Definition at line 23 of file ACS37800.h.

Member Function Documentation

◆ enableWriteAccess()

void ACS37800::enableWriteAccess ( )
inline

This function writes a special code to the ACS37800 to unlock it, which is a prerequisite for most other register writes. Most users should not need to call this function directly, because it is called by the functions that need it.

Definition at line 135 of file ACS37800.h.

◆ getAddress()

uint8_t ACS37800::getAddress ( )
inline

Returns the 7-bit I2C address that this object is configured to use.

Definition at line 55 of file ACS37800.h.

◆ getBus()

TwoWire * ACS37800::getBus ( )
inline

Returns a pointer to the I2C bus that this object is configured to use.

Definition at line 40 of file ACS37800.h.

◆ getLastError()

uint8_t ACS37800::getLastError ( )
inline

Returns 0 if the last communication with the device was successful, or a non-zero error code if there was an error.

Definition at line 62 of file ACS37800.h.

◆ readActiveAndReactivePower()

void ACS37800::readActiveAndReactivePower ( )
inline

Reads the active and reactive power from the sensor, converts both to units of mW, and stores them in the activePowerMilliwatts and reactivePowerMilliwatts members.

Definition at line 180 of file ACS37800.h.

◆ readActivePowerMilliwatts()

int32_t ACS37800::readActivePowerMilliwatts ( )
inline

Reads the active power from the sensor and returns its value converted to milliwatts.

If you need the active and reactive power, it is better to use readActiveAndReactivePower().

Definition at line 248 of file ACS37800.h.

◆ readApparentPowerMilliwatts()

int32_t ACS37800::readApparentPowerMilliwatts ( )
inline

Reads the apparent power from the sensor and returns it in mW.

Definition at line 190 of file ACS37800.h.

◆ readInstCurrentMilliamps()

int32_t ACS37800::readInstCurrentMilliamps ( )
inline

Reads the instantaneous current measurement from the sensor and returns its value converted to milliamps (mA).

If you need the current and the voltage, it is more efficient to use readInstVoltageAndCurrent() instead.

Definition at line 281 of file ACS37800.h.

◆ readInstPowerMilliwatts()

int32_t ACS37800::readInstPowerMilliwatts ( )
inline

Reads the instananeous power measurement (PINSTANT) from the sensor and returns its value converted to milliwatts (mW).

Definition at line 214 of file ACS37800.h.

◆ readInstVoltageAndCurrent()

void ACS37800::readInstVoltageAndCurrent ( )
inline

Reads the instantaneous voltage and current measurements from the sensor (VCODES and ICODES), converts them to mV and mA respectively, and stores them in the instVoltageMillivolts and instCurrentMilliamps members.

Definition at line 203 of file ACS37800.h.

◆ readInstVoltageMillivolts()

int32_t ACS37800::readInstVoltageMillivolts ( )
inline

Reads the instantaneous voltage measurement from the sensor, and returns its value converted to millivolts (mV).

If you need the current and the voltage, it is more efficient to use readInstVoltageAndCurrent() instead.

Definition at line 270 of file ACS37800.h.

◆ readReactivePowerMilliwatts()

int32_t ACS37800::readReactivePowerMilliwatts ( )
inline

Reads the reactive (imaginary) power from the sensor and returns its value converted to milliwatts.

If you need the active and reactive power, it is better to use readActiveAndReactivePower().

Definition at line 259 of file ACS37800.h.

◆ readReg()

uint32_t ACS37800::readReg ( uint8_t reg)
inline

Reads a sensor register and returns its value.

Definition at line 305 of file ACS37800.h.

◆ readRMSCurrentMilliamps()

int32_t ACS37800::readRMSCurrentMilliamps ( )
inline

Reads the root mean square (RMS) current measurement from the sensor and returns its value converted to millivolts (mV).

If you need the current and the voltage, it is more efficient to use readRMSVoltageAndCurrent() instead.

Definition at line 237 of file ACS37800.h.

◆ readRMSVoltageAndCurrent()

void ACS37800::readRMSVoltageAndCurrent ( )
inline

Reads the root mean square (RMS) voltage and current measurements from the sensor, converts them to mV and mA respectively, and stores them in the rmsVoltageMillivolts and rmsCurrentMilliamps members.

Definition at line 168 of file ACS37800.h.

◆ readRMSVoltageMillivolts()

int32_t ACS37800::readRMSVoltageMillivolts ( )
inline

Reads the root mean square (RMS) voltage measurement from the sensor and returns its value converted to millivolts (mV).

If you need the current and the voltage, it is more efficient to use readRMSVoltageAndCurrent() instead.

Definition at line 226 of file ACS37800.h.

◆ setAddress()

void ACS37800::setAddress ( uint8_t address)
inline

Configures this object to use the specified 7-bit I2C address. This must match the address that the ACS37800 is configured to use, which is a function of its EEPROM settings and its DIO_0 and DIO_1 connections.

Definition at line 49 of file ACS37800.h.

◆ setBoardParameters()

void ACS37800::setBoardParameters ( uint8_t isense_range,
uint32_t riso,
uint32_t rsense )
inline

Configures this object to use the right calculation paramters for a generic board.

If you're using a Pololu board, use setBoardPololu() instead of this function to save a significant amount of program space.

The isense_range parameter should be the current sensing range of the ACS37800 IC in units of amps, which depends on the specific part number of the chip and is specified in the datasheet. Typical values are 15, 30, and 90.

The riso parameter is the resistance between the ACS37800's VINN pin and the negative voltage sensing terminal of the board, plus the resistance between the ACS37800's VINP pin and the positive voltage sensing terminal of the board, in ohms.

The rsense parameter is the resistance between the ACS37800's voltage sensing pins, VINN and VINP, in ohms.

Definition at line 120 of file ACS37800.h.

◆ setBoardPololu()

void ACS37800::setBoardPololu ( uint8_t rsense_kohm)
inline

Configures this object to use the right calculation parameters for a Pololu ACS37800 isolated power monitor carrier board.

The rsense_kohm argument should be the Rsense value of your board, in units of kilohms, which depends on the jumper settings of your board. See the "Voltage measurement ranges" section of your board's product page to determine the Rsense value. Valid values are 1, 2, and 4.

Definition at line 74 of file ACS37800.h.

◆ setBus()

void ACS37800::setBus ( TwoWire * bus)
inline

Configures this object to use the specified I2C bus. The default bus is Wire, which is typically the first or only I2C bus on an Arduino. To use Wire1 instead, you can write:

acs.setBus(&Wire1);
Parameters
busA pointer to a TwoWire object representing the I2C bus to use.

Definition at line 33 of file ACS37800.h.

◆ setSampleCount()

void ACS37800::setSampleCount ( uint16_t count)
inline

Configures the sensor to use the specified number of samples for RMS and power calculations. Samples are taken at 32 kHz. The count should be a number between 0 and 1023. 1, 2, and 3 are treated the same as 4 by the ACS37800. 0 means to take samples from one voltage zero crossing to the next, instead of taking a fixed number of samples. This function only reads and writes from the shadow registers, not EEPROM, so the settings it applies will not be stored permanently.

Definition at line 148 of file ACS37800.h.

◆ writeEepromI2CAddress()

void ACS37800::writeEepromI2CAddress ( uint8_t address)
inline

Sets the 7-bit I2C device address of the sensor by writing it to EEPROM.

The new address does not take effect until the sensor is power cycled.

After this function successfully returns, the ACS37800 will take about 25 ms to write to EEPROM, and further communication during that time will not succeed (register reads return 0).

Definition at line 294 of file ACS37800.h.

◆ writeReg()

void ACS37800::writeReg ( uint8_t reg,
uint32_t value )
inline

Writes to a sensor register.

Definition at line 327 of file ACS37800.h.

Member Data Documentation

◆ activePowerMilliwatts

int32_t ACS37800::activePowerMilliwatts

Definition at line 347 of file ACS37800.h.

◆ apparentPowerMilliwatts

int32_t ACS37800::apparentPowerMilliwatts

Definition at line 349 of file ACS37800.h.

◆ icodesMult

uint16_t ACS37800::icodesMult = 1

Definition at line 338 of file ACS37800.h.

◆ icodesShift

uint8_t ACS37800::icodesShift = 0

Definition at line 339 of file ACS37800.h.

◆ instCurrentMilliamps

int32_t ACS37800::instCurrentMilliamps

Definition at line 342 of file ACS37800.h.

◆ instPowerMilliwatts

int32_t ACS37800::instPowerMilliwatts

Definition at line 343 of file ACS37800.h.

◆ instVoltageMillivolts

int32_t ACS37800::instVoltageMillivolts

Definition at line 341 of file ACS37800.h.

◆ pinstantMult

uint16_t ACS37800::pinstantMult = 1

Definition at line 338 of file ACS37800.h.

◆ pinstantShift

uint8_t ACS37800::pinstantShift = 0

Definition at line 339 of file ACS37800.h.

◆ reactivePowerMilliwatts

int32_t ACS37800::reactivePowerMilliwatts

Definition at line 348 of file ACS37800.h.

◆ rmsCurrentMilliamps

int32_t ACS37800::rmsCurrentMilliamps

Definition at line 346 of file ACS37800.h.

◆ rmsVoltageMillivolts

int32_t ACS37800::rmsVoltageMillivolts

Definition at line 345 of file ACS37800.h.

◆ vcodesMult

uint16_t ACS37800::vcodesMult = 1

Definition at line 338 of file ACS37800.h.

◆ vcodesShift

uint8_t ACS37800::vcodesShift = 0

Definition at line 339 of file ACS37800.h.


The documentation for this class was generated from the following file: