M5Unit-METER 0.2.1 git rev:6a6ea23
Loading...
Searching...
No Matches
m5::unit::UnitINA226 Class Reference

Base class for INA226 unit. More...

#include <unit_INA226.hpp>

Inheritance diagram for m5::unit::UnitINA226:
m5::unit::UnitINA226_10A m5::unit::UnitINA226_1A

Classes

struct  config_t
 Settings for begin. More...
 

Public Member Functions

virtual bool begin () override
 
virtual void update (const bool force=false) override
 
bool readAlertOccurred (bool &alert)
 Read the alert occurred?
 
bool powerDown ()
 Power down.
 
bool softReset (const bool all=false)
 Software reset.
 
Settings for begin
config_t config ()
 Gets the configration.
 
void config (const config_t &cfg)
 Set the configration.
 
Properties
float shuntResistor () const
 Gets the maximum current (A)
 
float maximumCurrent () const
 Gets the maximum current (A)
 
float currentLSB () const
 Gets the current LSB.
 
Measurement data by periodic
float shuntVoltage () const
 Oldest shunt voltage (mV)
 
float voltage () const
 Oldest Bus voltage (mV)
 
float power () const
 Oldest power (mW)
 
float current () const
 Oldest current (mA)
 
Periodic measurement
bool startPeriodicMeasurement (const bool current=true, const bool voltage=true, const bool power=true)
 Start periodic measurement in the current settings.
 
bool startPeriodicMeasurement (const ina226::Sampling rate, const ina226::ConversionTime sct, const ina226::ConversionTime bct, const bool current=true, const bool voltage=true, const bool power=true)
 Start periodic measurement.
 
bool stopPeriodicMeasurement ()
 Stop periodic measurement.
 
Single shot measurement
bool measureSingleshot (ina226::Data &data, const bool current=true, const bool voltage=true, const bool power=true)
 Measurement single shot.
 
bool measureSingleshot (ina226::Data &data, const ina226::Sampling rate, const ina226::ConversionTime sct, const ina226::ConversionTime bct, const bool current=true, const bool voltage=true, const bool power=true)
 Measurement single shot.
 
Settings
bool readMode (ina226::Mode &mode)
 Read the operation mode.
 
bool readSamplingRate (ina226::Sampling &rate)
 Read the sampling rate.
 
bool writeSamplingRate (const ina226::Sampling rate)
 Write the sampling rate.
 
bool readBusVoltageConversionTime (ina226::ConversionTime &ct)
 Read the convsrsion time of Bus voltage.
 
bool writeBusVoltageConversionTime (const ina226::ConversionTime ct)
 Write the convsrsion time of Bus voltage @paramct Conversion time.
 
bool readShuntVoltageConversionTime (ina226::ConversionTime &ct)
 Read the convsrsion time of Shunt voltage.
 
bool writeShuntVoltageConversionTime (const ina226::ConversionTime ct)
 Write the convsrsion time of Shunt voltage @paramct Conversion time.
 
bool readCalibration (uint16_t &cal)
 Read the calibration value.
 
bool writeCalibration (const uint16_t cal)
 Write the calibration value.
 
bool readAlert (ina226::Alert &type)
 Read the alert type.
 
bool writeAlert (const ina226::Alert type, const uint16_t limit, const bool latch=true)
 Write the alert type and limit value.
 
bool readAlertLimit (uint16_t &limit)
 Read the alerm limit value.
 
bool writeAlertLimit (const uint16_t limit)
 Write the alerm limit value.
 

Protected Member Functions

 UnitINA226 (const float shuntRes, const float maxCurA, const float curLSB, const uint8_t addr=DEFAULT_ADDRESS)
 Constructor.
 
bool start_periodic_measurement (const bool current, const bool voltage, const bool power)
 
bool start_periodic_measurement (const ina226::Sampling rate, const ina226::ConversionTime sct, const ina226::ConversionTime bct, const bool current, const bool voltage, const bool power)
 
bool stop_periodic_measurement ()
 
bool write_mode (const ina226::Mode mode)
 
bool read_configuration (uint16_t &v)
 
bool write_configuration (const uint16_t v)
 
bool read_mask (uint16_t &m)
 
bool write_mask (const uint16_t m)
 
bool is_data_ready ()
 
bool read_measurement (ina226::Data &d)
 
 M5_UNIT_COMPONENT_PERIODIC_MEASUREMENT_ADAPTER_HPP_BUILDER (UnitINA226, ina226::Data)
 

Detailed Description

Base class for INA226 unit.

Constructor & Destructor Documentation

◆ UnitINA226()

m5::unit::UnitINA226::UnitINA226 ( const float shuntRes,
const float maxCurA,
const float curLSB,
const uint8_t addr = DEFAULT_ADDRESS )
protected

Constructor.

Parameters
shuntResShunt resistor (O)
maxCurAMaximum measure current (A) @paream curLSB currentLSB

Member Function Documentation

◆ measureSingleshot() [1/2]

bool m5::unit::UnitINA226::measureSingleshot ( ina226::Data & data,
const bool current = true,
const bool voltage = true,
const bool power = true )

Measurement single shot.

Measuring in the current settings

Parameters
[out]dataMeasuerd data
currentMeasure current if true
voltageMeasure bus voltage if true
powerMeasure power if true
Returns
True if successful
Warning
During periodic detection runs, an error is returned
Until it can be measured, it will be blocked until the timeout time

◆ measureSingleshot() [2/2]

bool m5::unit::UnitINA226::measureSingleshot ( ina226::Data & data,
const ina226::Sampling rate,
const ina226::ConversionTime sct,
const ina226::ConversionTime bct,
const bool current = true,
const bool voltage = true,
const bool power = true )

Measurement single shot.

Measuring in the current settings

Parameters
[out]dataMeasuerd data
rateSampling Sampling rate @paran sct Shunt conversion time @paran bct Bus conversion time
currentMeasure current if true
voltageMeasure bus voltage if true
powerMeasure power if true
Returns
True if successful
Warning
During periodic detection runs, an error is returned
Until it can be measured, it will be blocked until the timeout time

◆ powerDown()

bool m5::unit::UnitINA226::powerDown ( )

Power down.

Returns
True if successful

◆ readAlert()

bool m5::unit::UnitINA226::readAlert ( ina226::Alert & type)

Read the alert type.

Parameters
[out]typeAlert type
Returns
True if successful

◆ readAlertLimit()

bool m5::unit::UnitINA226::readAlertLimit ( uint16_t & limit)

Read the alerm limit value.

Parameters
[out]limitLimit value
Returns
True if successful
Note
The unit of value depends on the type of Alert (See also datasheet)

◆ readAlertOccurred()

bool m5::unit::UnitINA226::readAlertOccurred ( bool & alert)

Read the alert occurred?

Parameters
[out]alertAn alert occurred if true
Returns
True if successful

◆ readBusVoltageConversionTime()

bool m5::unit::UnitINA226::readBusVoltageConversionTime ( ina226::ConversionTime & ct)

Read the convsrsion time of Bus voltage.

Parameters
[out]ctConversion time
Returns
True if successful

◆ readCalibration()

bool m5::unit::UnitINA226::readCalibration ( uint16_t & cal)

Read the calibration value.

Parameters
[out]calCalibration value
Returns
True if successful

◆ readMode()

bool m5::unit::UnitINA226::readMode ( ina226::Mode & mode)

Read the operation mode.

Parameters
[out]modeMode
Returns
True if successful

◆ readSamplingRate()

bool m5::unit::UnitINA226::readSamplingRate ( ina226::Sampling & rate)

Read the sampling rate.

Parameters
[out]rateSamling rate
Returns
True if successful

◆ readShuntVoltageConversionTime()

bool m5::unit::UnitINA226::readShuntVoltageConversionTime ( ina226::ConversionTime & ct)

Read the convsrsion time of Shunt voltage.

Parameters
[out]ctConversion time
Returns
True if successful

◆ softReset()

bool m5::unit::UnitINA226::softReset ( const bool all = false)

Software reset.

Parameters
allRewrite calibration value if false
Returns
True if successful
Warning
All register values are changed to their initial values

◆ startPeriodicMeasurement() [1/2]

bool m5::unit::UnitINA226::startPeriodicMeasurement ( const bool current = true,
const bool voltage = true,
const bool power = true )
inline

Start periodic measurement in the current settings.

Parameters
currentMeasure current if true
voltageMeasure bus voltage if true
powerMeasure power if true
Returns
True if successful

◆ startPeriodicMeasurement() [2/2]

bool m5::unit::UnitINA226::startPeriodicMeasurement ( const ina226::Sampling rate,
const ina226::ConversionTime sct,
const ina226::ConversionTime bct,
const bool current = true,
const bool voltage = true,
const bool power = true )
inline

Start periodic measurement.

Parameters
rateSampling Sampling rate @paran sct Shunt conversion time @paran bct Bus conversion time
currentMeasure current if true
voltageMeasure bus voltage if true
powerMeasure power if true
Returns
True if successful

◆ stopPeriodicMeasurement()

bool m5::unit::UnitINA226::stopPeriodicMeasurement ( )
inline

Stop periodic measurement.

Returns
True if successful

◆ writeAlert()

bool m5::unit::UnitINA226::writeAlert ( const ina226::Alert type,
const uint16_t limit,
const bool latch = true )

Write the alert type and limit value.

Parameters
typeAlert type
limitLimit value (Ignore if type is Alert::ConversionReady)
latchAlert latch enabled if true
Returns
True if successful
Note
The unit of value depends on the type of Alert (See also datasheet)
Type Alert Description Unit Value
Type::ShuntOver Type::ShuntUnder SOL/SUL Shunt over/under limit V V / 0.00125
Type::BusOver Type::BusUnder BOL/BUL Bus over/under limit V V / 0..00125
Type::PowerOver POL Power over limit W W / (25 × currentLSB)
Type::ConversionReady CNVR Conversion ready - -
Warning
During periodic detection runs, an error is returned

◆ writeAlertLimit()

bool m5::unit::UnitINA226::writeAlertLimit ( const uint16_t limit)

Write the alerm limit value.

Parameters
limitLimit value
Returns
True if successful
Note
The unit of value depends on the type of Alert (See also datasheet)
Warning
During periodic detection runs, an error is returned

◆ writeBusVoltageConversionTime()

bool m5::unit::UnitINA226::writeBusVoltageConversionTime ( const ina226::ConversionTime ct)

Write the convsrsion time of Bus voltage @paramct Conversion time.

Returns
True if successful
Warning
During periodic detection runs, an error is returned

◆ writeCalibration()

bool m5::unit::UnitINA226::writeCalibration ( const uint16_t cal)

Write the calibration value.

Parameters
calCalibration value
Returns
True if successful

◆ writeSamplingRate()

bool m5::unit::UnitINA226::writeSamplingRate ( const ina226::Sampling rate)

Write the sampling rate.

Parameters
rateSamling rate
Returns
True if successful
Warning
During periodic detection runs, an error is returned

◆ writeShuntVoltageConversionTime()

bool m5::unit::UnitINA226::writeShuntVoltageConversionTime ( const ina226::ConversionTime ct)

Write the convsrsion time of Shunt voltage @paramct Conversion time.

Returns
True if successful
Warning
During periodic detection runs, an error is returned