Meadow.Foundation.Sensors.Power.Ina260
Ina260 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Ina260 ina260;
public override Task Initialize()
{
Resolver.Log.Debug("Initialize...");
var bus = Device.CreateI2cBus(I2cBusSpeed.Fast);
ina260 = new Ina260(bus);
ina260.Configure(Ina260.ConversionTime.ConversionTime_8244us, Ina260.ConversionTime.ConversionTime_8244us, Ina260.Averaging.Average_4);
//Resolver.SensorService.RegisterSensor(ina260);
Resolver.Log.Info($"--- INA260 Sample App ---");
Resolver.Log.Info($"Manufacturer: {ina260.ManufacturerID}");
Resolver.Log.Info($"DeviceID: 0x{ina260.DeviceID:X3}");
Resolver.Log.Info($"Revision: 0x{ina260.DeviceRevision:X2}");
ina260.Updated += (sender, result) =>
{
Resolver.Log.Info($"{result.New.Voltage:N3} V @ {result.New.Current:N3} A");
};
return Task.CompletedTask;
}
public override Task Run()
{
Resolver.Log.Debug("Run...");
ina260.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
Sample project(s) available on GitHub
Class Ina260
Represents a INA260 Precision Digital Current and Power Monitor
Assembly: Ina2xx.dll
View Source
public class Ina260 : Ina2xx, IObservable<IChangeResult<(Current? Current, Voltage? Voltage, Power? Power)>>, ISamplingSensor<(Current? Current, Voltage? Voltage, Power? Power)>, ISensor<(Current? Current, Voltage? Voltage, Power? Power)>, IDisposable, ICurrentSensor, ISamplingSensor<Current>, ISensor<Current>, IVoltageSensor, ISamplingSensor<Voltage>, ISensor<Voltage>, IPowerSensor, ISamplingSensor<Power>, ISensor<Power>, ISensor, ISamplingSensor, II2cPeripheral
Inheritance: System.Object
-> Meadow.Foundation.ObservableBase<UNIT>
Implements:
Expand
System.IObservable<Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Units.Current>,System.Nullable<Meadow.Units.Voltage>,System.Nullable<Meadow.Units.Power>>>>
, Meadow.Peripherals.Sensors.ISamplingSensor<System.ValueTuple<System.Nullable<Meadow.Units.Current>,System.Nullable<Meadow.Units.Voltage>,System.Nullable<Meadow.Units.Power>>>
, Meadow.Peripherals.Sensors.ISensor<System.ValueTuple<System.Nullable<Meadow.Units.Current>,System.Nullable<Meadow.Units.Voltage>,System.Nullable<Meadow.Units.Power>>>
, System.IDisposable
, Meadow.Peripherals.Sensors.ICurrentSensor
, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Current>
, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Current>
, Meadow.Peripherals.Sensors.IVoltageSensor
, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Voltage>
, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Voltage>
, Meadow.Peripherals.Sensors.IPowerSensor
, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Power>
, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Power>
, Meadow.Peripherals.Sensors.ISensor
, Meadow.Peripherals.Sensors.ISamplingSensor
, Meadow.Hardware.II2cPeripheral
Methods
Configure()
Sets the sensor Configuration to default values. Each implementation should provide overloads for specific available options.
View Source
public override void Configure()
Configure(ConversionTime, ConversionTime, Averaging, Mode)
Sets Configuration of sensor
View Source
public void Configure(Ina260.ConversionTime currentConversionTime = ConversionTime.ConversionTime_1100us, Ina260.ConversionTime voltageConversionTime = ConversionTime.ConversionTime_1100us, Ina260.Averaging averaging = Averaging.Average_1, Ina260.Mode mode = Mode.ContinuousAll)
Parameters
Type | Name | Description |
---|---|---|
Meadow.Foundation.Sensors.Power.Ina260.ConversionTime | currentConversionTime | Conversion time for Current measurements |
Meadow.Foundation.Sensors.Power.Ina260.ConversionTime | voltageConversionTime | Conversion time for Voltage measurements |
Meadow.Foundation.Sensors.Power.Ina260.Averaging | averaging | On-chip value averaging |
Meadow.Foundation.Sensors.Power.Ina260.Mode | mode | selection of values and trigger mode |
ReadCurrent()
Read the Current measurement from the power monitor IC.
View Source
public override Current ReadCurrent()
Returns
Meadow.Units.Current
ReadBusVoltage()
Read the Voltage measurement from the power monitor IC.
View Source
public override Voltage ReadBusVoltage()
Returns
Meadow.Units.Voltage
ReadShuntVoltage()
Read the Voltage across the Shunt (sense) resistor from the power monitor IC.
View Source
public override Voltage ReadShuntVoltage()
Returns
Meadow.Units.Voltage
ReadPower()
Read the Power measurement from the power monitor IC.
View Source
public override Power ReadPower()
Returns
Meadow.Units.Power
AlertOnVoltageLimit(Voltage, bool, bool, bool)
Configures the Voltage Limit Alert function.
View Source
public void AlertOnVoltageLimit(Voltage threshold, bool activeHigh = false, bool latching = false, bool overLimit = false)
Parameters
Type | Name | Description |
---|---|---|
Meadow.Units.Voltage | threshold | Meadow.Units.Voltage threshold for triggering the Alert. |
System.Boolean | activeHigh | State of the alert pin to use for the Alert Signal |
System.Boolean | latching | Whether to latch the Alert until cleared. |
System.Boolean | overLimit | Set true to trigger an alert when the measured voltage is <b>above</b> the <code class="paramref">threshold</code>. |
Exceptions
System.ArgumentOutOfRangeException
Thrown if the <code class="paramref">threshold</code> is outside the limits of the power monitor IC.
AlertOnCurrentLimit(Current, bool, bool, bool)
Configures the Current Limit Alert function.
View Source
public void AlertOnCurrentLimit(Current threshold, bool activeHigh = false, bool latching = false, bool overLimit = false)
Parameters
Type | Name | Description |
---|---|---|
Meadow.Units.Current | threshold | Meadow.Units.Current threshold for triggering the Alert. |
System.Boolean | activeHigh | State of the alert pin to use for the Alert Signal |
System.Boolean | latching | Whether to latch the Alert until cleared. |
System.Boolean | overLimit | Set true to trigger an alert when the measured Current is <b>above</b> the <code class="paramref">threshold</code>. |
Exceptions
System.ArgumentOutOfRangeException
Thrown if the <code class="paramref">threshold</code> is outside the limits of the power monitor IC.
AlertOnPowerLimit(Power, bool, bool)
Configures the Power Limit Alert function.
View Source
public void AlertOnPowerLimit(Power threshold, bool activeHigh = false, bool latching = false)
Parameters
Type | Name | Description |
---|---|---|
Meadow.Units.Power | threshold | Meadow.Units.Power threshold for triggering the Alert. |
System.Boolean | activeHigh | State of the alert pin to use for the Alert Signal |
System.Boolean | latching | Whether to latch the Alert until cleared. |
Exceptions
System.ArgumentOutOfRangeException
Thrown if the <code class="paramref">threshold</code> is outside the limits of the power monitor IC.
AlertOnConversionComplete(bool, bool)
Configures the Alert function to activate when all ADC conversions are complete.
View Source
public void AlertOnConversionComplete(bool activeHigh = false, bool latching = false)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | activeHigh | State of the alert pin to use for the Alert Signal |
System.Boolean | latching | Whether to latch the Alert until cleared. |
GetStatus(out bool, out bool, out bool)
Reads all status bits.
View Source
public void GetStatus(out bool alert, out bool conversionReady, out bool overflow)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | alert | true if the Alert condition was the source of the Alert pin output. |
System.Boolean | conversionReady | true if all conversions and calculations are completed since last time this bit was read. |
System.Boolean | overflow | true indicates the internal arithmetic for Power may have exceeded the maximum of 419.43 W |
Dispose(bool)
Dispose of the object
View Source
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | Is disposing |
Events
AlertChanged
Raised when the Alert signal changes.
View Source
public event EventHandler AlertChanged
Event Type
System.EventHandler
Implements
System.IObservable<Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Units.Current>,System.Nullable<Meadow.Units.Voltage>,System.Nullable<Meadow.Units.Power>>>>
Meadow.Peripherals.Sensors.ISamplingSensor<System.ValueTuple<System.Nullable<Meadow.Units.Current>,System.Nullable<Meadow.Units.Voltage>,System.Nullable<Meadow.Units.Power>>>
Meadow.Peripherals.Sensors.ISensor<System.ValueTuple<System.Nullable<Meadow.Units.Current>,System.Nullable<Meadow.Units.Voltage>,System.Nullable<Meadow.Units.Power>>>
System.IDisposable
Meadow.Peripherals.Sensors.ICurrentSensor
Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Current>
Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Current>
Meadow.Peripherals.Sensors.IVoltageSensor
Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Voltage>
Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Voltage>
Meadow.Peripherals.Sensors.IPowerSensor
Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Power>
Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Power>
Meadow.Peripherals.Sensors.ISensor
Meadow.Peripherals.Sensors.ISamplingSensor
Meadow.Hardware.II2cPeripheral