Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Hybrid_Supercapacitor_Car_Battery_Monitoring
Fork of INA219 by
Revision 1:8ccc8e47e3d5, committed 2017-12-26
- Comitter:
- madelectroneng
- Date:
- Tue Dec 26 21:28:13 2017 +0000
- Parent:
- 0:eee9c8ba72ff
- Commit message:
- updated for 0.01Ohm resistor so it can read up to 32A instead of 3.2A
Changed in this revision
| INA219.cpp | Show annotated file Show diff for this revision Revisions of this file |
| INA219.hpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r eee9c8ba72ff -r 8ccc8e47e3d5 INA219.cpp
--- a/INA219.cpp Thu Aug 28 10:32:20 2014 +0000
+++ b/INA219.cpp Tue Dec 26 21:28:13 2017 +0000
@@ -51,7 +51,7 @@
void INA219::calibrate_16v_400mA()
{
// ASSUMING A 0.1 OHM RESISTOR!
- write_register_u16(INA219_REG_CALIBRATION, 8192);
+ write_register_u16(INA219_REG_CALIBRATION, 7600);
// Write to config register
@@ -67,13 +67,13 @@
resolution_mask = INA219_CONFIG_BADCRES_9BIT | INA219_CONFIG_SADCRES_9BIT_1S_84US;
write_register_u16(INA219_REG_CONFIG, INA219_CONFIG_BVOLTAGERANGE_16V |
- INA219_CONFIG_GAIN_1_40MV |
+ INA219_CONFIG_GAIN_8_320MV |
resolution_mask |
INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS);
// Set current divider
- current_divider = 20;
- power_divider = 1;
+ current_divider = 2;
+ power_divider = 10;
}
int16_t INA219::read_current_raw()
@@ -85,4 +85,24 @@
{
float raw_current = read_current_raw();
return raw_current / current_divider;
+}
+int16_t INA219::read_bus_voltage_raw()
+{
+ return ((int16_t)read_register_u16(INA219_REG_BUSVOLTAGE)>>3)*4;
+}
+
+float INA219::read_bus_voltage()
+{
+ float raw_voltage = read_bus_voltage_raw();
+ return raw_voltage*0.001;
+}
+int16_t INA219::read_power_raw()
+{
+ return ((int16_t)read_register_u16(INA219_REG_POWER)>>3)*4;
+}
+
+float INA219::read_power_mW()
+{
+ float raw_mW = read_power_raw();
+ return raw_mW*2.000;
}
\ No newline at end of file
diff -r eee9c8ba72ff -r 8ccc8e47e3d5 INA219.hpp
--- a/INA219.hpp Thu Aug 28 10:32:20 2014 +0000
+++ b/INA219.hpp Tue Dec 26 21:28:13 2017 +0000
@@ -59,7 +59,7 @@
* @returns
* A value between -32768 and +32768. Depending on the calibration and configuration register values, the actual power can be calculated.
*/
- //int16_t read_power_raw();
+ int16_t read_power_raw();
/** Reads the power from the INA219 and calculates the actual value in mW.
*
* @see read_power_raw
@@ -67,7 +67,7 @@
* @returns
* A floating point value corresponding to the power being used in the circuit, in mW.
*/
- //float read_power_mW();
+ float read_power_mW();
/** Reads the raw shunt voltage value from the INA219.
*
@@ -76,7 +76,7 @@
* @returns
* A value between -32768 and +32768. Depending on the calibration and configuration register values, the actual shunt voltage can be calculated.
*/
- //int16_t read_shunt_voltage_raw();
+ int16_t read_shunt_voltage_raw();
/** Reads the shunt voltage from the INA219 and calculates the actual value in mV.
*
* @see read_shunt_voltage_raw
@@ -84,7 +84,7 @@
* @returns
* A floating point value corresponding to the potential difference across the current shunt, in mV.
*/
- //float read_shunt_voltage_mV();
+ float read_shunt_voltage_mV();
/** Reads the raw bus voltage.
*
@@ -93,7 +93,7 @@
* @returns
* A value between -32768 and +32768 corresponding to the bus voltage.
*/
- //int16_t read_bus_voltage_raw();
+ int16_t read_bus_voltage_raw();
/** Reads the bus voltage and uses it to calculate the actual bus voltage.
*
* @see read_bus_voltage_raw
@@ -101,7 +101,7 @@
* @returns
* A floating point value corresponding to the voltage of V+ (in V).
*/
- //float read_bus_voltage();
+ float read_bus_voltage();
/** Sets the calibration register.
*
