Skip to content
This repository has been archived by the owner on Jun 22, 2018. It is now read-only.

Commit

Permalink
Cleaned up the "begin()" call
Browse files Browse the repository at this point in the history
Removed unnecessary parameters, reduced call to bare minimum
  • Loading branch information
Arnd authored and Arnd committed Jan 10, 2017
1 parent f29d5eb commit e92c042
Show file tree
Hide file tree
Showing 9 changed files with 401 additions and 408 deletions.
Binary file modified Examples/DisplayReadings/.vs/DisplayReadings/v14/.atsuo
Binary file not shown.
Binary file modified Examples/DisplayReadings/Debug/DisplayReadings.elf
Binary file not shown.
370 changes: 183 additions & 187 deletions Examples/DisplayReadings/Debug/DisplayReadings.hex

Large diffs are not rendered by default.

Binary file modified Examples/DisplayReadings/Debug/DisplayReadings.ino.elf
Binary file not shown.
370 changes: 183 additions & 187 deletions Examples/DisplayReadings/Debug/DisplayReadings.ino.hex

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Examples/DisplayReadings/Debug/board.buildinfo
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ PreProcessor.HeaderCount=1
PreProcessor.PrototypeCount=4
vm.last.preproc.file.0.file=DisplayReadings.ino
vm.last.preproc.file.0.offset=1
vm.last.preproc.file.0.length=8826
vm.last.preproc.file.0.linecount=86
vm.last.preproc.file.0.length=8589
vm.last.preproc.file.0.linecount=84
vm.last.preproc.file.0.linestart=0
vm.last.preproc.file.0.lineend=86
vm.last.preproc.file.0.lineend=84
vm.last.preproc.file.0.prefix_lines=0
sketch_path=C:\Users\Arnd\Documents\Arduino\libraries\INA226\Examples\DisplayReadings
vm.sketch_source_path=C:\Users\Arnd\AppData\Local\Temp\VMicroBuilds\DisplayReadings\micro
Expand All @@ -281,7 +281,7 @@ build.project_name=DisplayReadings.ino
runtime.vm.ide.platforms.path=C:\Program Files (x86)\Atmel\Studio\7.0\Extensions\yhvelnol.hcr\Micro Platforms
build.variant.path=C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro
archive_file=core.a
extra.time.local=29119246
extra.time.local=72343038
tools.ctags.path={runtime.tools.ctags.path}
tools.ctags.cmd.path={path}/ctags
tools.ctags.pattern="{cmd.path}" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "{source_file}"
Expand All @@ -293,4 +293,4 @@ build.path_core=C:\Users\Arnd\AppData\Local\Temp\VMicroBuilds\DisplayReadings\mi
build.path_libraries=C:\Users\Arnd\AppData\Local\Temp\VMicroBuilds\DisplayReadings\micro
object_file=C:\Users\Arnd\AppData\Local\Temp\VMicroBuilds\DisplayReadings\micro\DisplayReadings.cpp.o
source_file=C:\Users\Arnd\AppData\Local\Temp\VMicroBuilds\DisplayReadings\micro\DisplayReadings.cpp
object_files= "C:\Users\Arnd\AppData\Local\Temp\VMicroBuilds\DisplayReadings\micro\DisplayReadings.cpp.o" "C:\Users\Arnd\AppData\Local\Temp\VMicroBuilds\DisplayReadings\micro\Wire\Wire.cpp.o" "C:\Users\Arnd\AppData\Local\Temp\VMicroBuilds\DisplayReadings\micro\Wire\utility\twi.c.o" "C:\Users\Arnd\AppData\Local\Temp\VMicroBuilds\DisplayReadings\micro\INA226\INA.cpp.o"
object_files= "C:\Users\Arnd\AppData\Local\Temp\VMicroBuilds\DisplayReadings\micro\DisplayReadings.cpp.o" "C:\Users\Arnd\AppData\Local\Temp\VMicroBuilds\DisplayReadings\micro\Wire\Wire.cpp.o" "C:\Users\Arnd\AppData\Local\Temp\VMicroBuilds\DisplayReadings\micro\Wire\utility\twi.c.o" "C:\Users\Arnd\AppData\Local\Temp\VMicroBuilds\DisplayReadings\micro\INA226\INA226.cpp.o"
8 changes: 3 additions & 5 deletions Examples/DisplayReadings/DisplayReadings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
** 1.0.0 2017-01-09 [email protected] Cloned example from test program suite **
** **
*******************************************************************************************************************/
#include <INA.h> // INA Library //
#include <INA226.h> // INA226 Library //
/*******************************************************************************************************************
** Declare program Constants **
*******************************************************************************************************************/
Expand All @@ -53,10 +53,8 @@ void setup() { //
Serial.begin(SERIAL_SPEED); // Start serial communications //
delay(2000); // Wait for comms port to connect //
Serial.print(F("\n\nDisplay INA226 Readings V1.0.0\n")); // Display program information //
INA226.begin( 6, // Volts maximum expected on bus //
1, // ± Amps maximum expected on bus //
100, // ± Shunt millivolts maximum //
100000); // Shunt resistance in microOhm(µ?),//
INA226.begin( 1, // ± Amps maximum expected on bus //
100000); // Shunt resistance in nanoOhm(µ?),//
// "100000" equates to 0.1 Ohm //
INA226.setAveraging(4); // Average each reading n-times //
INA226.setBusConversion(); // Maximum conversion time 8.244ms //
Expand Down
20 changes: 9 additions & 11 deletions INA.cpp → INA226.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*******************************************************************************************************************
** INA class method definitions. **
** **
** Detailed documentation can be found on the GitHub Wiki pages at https://github.com/SV-Zanshin/INA226/wiki **
** **
** This program is free software: you can redistribute it and/or modify it under the terms of the GNU General **
** Public License as published by the Free Software Foundation, either version 3 of the License, or (at your **
** option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY **
Expand All @@ -9,7 +11,7 @@
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
** **
*******************************************************************************************************************/
#include "INA.h" // Include the header definition //
#include "INA226.h" // Include the header definition //
#include <Wire.h> // I2C Library definition //

/*******************************************************************************************************************
Expand All @@ -24,20 +26,16 @@ INA226_Class::~INA226_Class() {} // of unused class destructor //
/*******************************************************************************************************************
** Method begin() does all of the initialization work **
*******************************************************************************************************************/
void INA226_Class::begin(uint8_t maxBusVolts = 30, // Class initializer with optional //
uint8_t maxBusAmps = 200, // register settings for setup and //
uint16_t maxShuntmV = 50, // calibration //
uint32_t microOhmR = UINT32_MAX ) { // //
void INA226_Class::begin(const uint8_t maxBusAmps, const uint32_t nanoOhmR) { // Class initializer //
Wire.begin(); // Start the I2C wire subsystem //
for(_DeviceAddress = 1;_DeviceAddress<127;_DeviceAddress++) { // Loop for each possible address //
Wire.beginTransmission(_DeviceAddress); // See if something is at address //
if (Wire.endTransmission() == 0) { // by checking the return error //
writeWord(INA_CONFIGURATION_REGISTER,INA_RESET_DEVICE); // Force INAs to reset //
delay(10); // Wait for INA to finish resetting //
if (readWord(INA_CONFIGURATION_REGISTER)==INA_DEFAULT_CONFIGURATION) { // Yes, we've found an INA226! //
if (microOhmR==UINT32_MAX) microOhmR = (maxShuntmV*1000)/maxBusAmps; // convert to avoid floating point //
_Current_LSB = (uint32_t)maxBusAmps*1000000000/32767; // Get the best possible LSB //
_Calibration = 51200000/((int64_t)_Current_LSB*microOhmR/100000); // Compute calibration register //
_Calibration = 51200000/((int64_t)_Current_LSB*nanoOhmR/100000); // Compute calibration register //
_Power_LSB = (uint32_t)25*_Current_LSB; // Fixed multiplier for INA219 //
writeWord(INA_CALIBRATION_REGISTER,_Calibration); // Write the calibration value //
break; // Stop searching //
Expand Down Expand Up @@ -107,14 +105,14 @@ uint16_t INA226_Class::getBusMilliVolts() { //
/*******************************************************************************************************************
** Method getShuntMicroVolts retrieves the shunt voltage measurement **
*******************************************************************************************************************/
int32_t INA226_Class::getShuntMicroVolts() { // //
int32_t shuntVoltage = readWord(INA_SHUNT_VOLTAGE_REGISTER); // Get the raw value //
int16_t INA226_Class::getShuntMicroVolts() { // //
int16_t shuntVoltage = readWord(INA_SHUNT_VOLTAGE_REGISTER); // Get the raw value //
shuntVoltage = shuntVoltage*INA_SHUNT_VOLTAGE_LSB/10; // Convert to microvolts //
return(shuntVoltage); // return computed microvolts //
} // of method getShuntMicroVolts() // //

/*******************************************************************************************************************
** Method getBusMicroAmps retrieves the computed current in microamps **
** Method getBusMicroAmps retrieves the computed current in microamps. **
*******************************************************************************************************************/
int32_t INA226_Class::getBusMicroAmps() { // //
int32_t microAmps = readWord(INA_CURRENT_REGISTER); // Get the raw value //
Expand All @@ -129,7 +127,7 @@ int32_t INA226_Class::getBusMicroWatts() { //
int32_t microWatts = readWord(INA_POWER_REGISTER); // Get the raw value //
microWatts = (int64_t)microWatts*_Power_LSB/1000; // Convert to milliwatts //
return(microWatts); // return computed milliwatts //
} // of method getBusMicroWatts() // //
} // of method getBusMicroWatts() // //

/*******************************************************************************************************************
** Method setAveraging sets the hardware averaging for the different devices **
Expand Down
31 changes: 18 additions & 13 deletions INA.h → INA226.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
** **
** Vers. Date Developer Comments **
** ====== ========== =================== ======================================================================== **
** 1.0.0 2017-01-10 [email protected] Fixed library file name, added constants for setMode() call **
** 1.0.0 2017-01-09 [email protected] Added reset() and setMode() calls **
** 1.0.b2 2017-01-08 [email protected] Removed INA219 code, concentrating on only the INA226 **
** 1.0.b1 2017-01-05 [email protected] Created class **
Expand All @@ -44,14 +45,14 @@
/*****************************************************************************************************************
** Declare constants used in the class **
*****************************************************************************************************************/
const uint8_t I2C_DELAY = 10; // Microsecond delay on write //
const uint8_t INA_CONFIGURATION_REGISTER = 0; // Registers common to all INAs //
const uint8_t INA_SHUNT_VOLTAGE_REGISTER = 1; // //
const uint8_t INA_BUS_VOLTAGE_REGISTER = 2; // //
const uint8_t INA_POWER_REGISTER = 3; // //
const uint8_t INA_CURRENT_REGISTER = 4; // //
const uint8_t INA_CALIBRATION_REGISTER = 5; // //
const uint8_t INA_MASK_ENABLE_REGISTER = 6; // //
const uint8_t I2C_DELAY = 10; // Microsecond delay on write //
const uint8_t INA_CONFIGURATION_REGISTER = 0; // Registers common to all INAs //
const uint8_t INA_SHUNT_VOLTAGE_REGISTER = 1; // //
const uint8_t INA_BUS_VOLTAGE_REGISTER = 2; // //
const uint8_t INA_POWER_REGISTER = 3; // //
const uint8_t INA_CURRENT_REGISTER = 4; // //
const uint8_t INA_CALIBRATION_REGISTER = 5; // //
const uint8_t INA_MASK_ENABLE_REGISTER = 6; // //
const uint16_t INA_RESET_DEVICE = 0x8000; // Write to configuration to reset //
const uint16_t INA_DEFAULT_CONFIGURATION = 0x4127; // Default configuration register //
const uint16_t INA_BUS_VOLTAGE_LSB = 125; // LSB in uV *100 1.25mV //
Expand All @@ -61,6 +62,13 @@
const uint16_t INA_CONFIG_SHUNT_TIME_MASK = 0x0038; // Bits 3-5 //
const uint16_t INA_CONVERSION_READY_MASK = 0x0080; // Bit 4 //
const uint16_t INA_CONFIG_MODE_MASK = 0x0007; // Bits 0-3 //
const uint8_t INA_MODE_TRIGGERED_SHUNT = B001; // Triggered shunt, no bus //
const uint8_t INA_MODE_TRIGGERED_BUS = B010; // Triggered bus, no shunt //
const uint8_t INA_MODE_TRIGGERED_BOTH = B011; // Triggered bus and shunt //
const uint8_t INA_MODE_POWER_DOWN = B100; // shutdown or power-down //
const uint8_t INA_MODE_CONTINUOUS_SHUNT = B101; // Continuous shunt, no bus //
const uint8_t INA_MODE_CONTINUOUS_BUS = B110; // Continuous bus, no shunt //
const uint8_t INA_MODE_CONTINUOUS_BOTH = B111; // Both continuous, default value //

/*****************************************************************************************************************
** Declare class header **
Expand All @@ -69,12 +77,9 @@
public: // Publicly visible methods //
INA226_Class(); // Class constructor //
~INA226_Class(); // Class destructor //
void begin(uint8_t maxBusVolts = 30, // Initialize class //
uint8_t maxBusAmps = 200, // register settings for setup and //
uint16_t maxShuntmV = 50, // calibration //
uint32_t microOhmR = UINT32_MAX ); // //
void begin(const uint8_t maxBusAmps, const uint32_t nanoOhmR); // Class initializer //
uint16_t getBusMilliVolts(); // Retrieve Bus voltage in mV //
int32_t getShuntMicroVolts(); // Retrieve Shunt voltage in uV //
int16_t getShuntMicroVolts(); // Retrieve Shunt voltage in uV //
int32_t getBusMicroAmps(); // Retrieve microamps //
int32_t getBusMicroWatts(); // Retrieve microwatts //
void reset(); // Reset the device //
Expand Down

0 comments on commit e92c042

Please sign in to comment.