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

Commit

Permalink
Added "wait" switch handling on conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnd authored and Arnd committed Jan 10, 2017
1 parent e92c042 commit 9890632
Show file tree
Hide file tree
Showing 10 changed files with 502 additions and 478 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.
469 changes: 237 additions & 232 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.
469 changes: 237 additions & 232 deletions Examples/DisplayReadings/Debug/DisplayReadings.ino.hex

Large diffs are not rendered by default.

8 changes: 4 additions & 4 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=8589
vm.last.preproc.file.0.linecount=84
vm.last.preproc.file.0.length=8644
vm.last.preproc.file.0.linecount=87
vm.last.preproc.file.0.linestart=0
vm.last.preproc.file.0.lineend=84
vm.last.preproc.file.0.lineend=87
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=72343038
extra.time.local=78723014
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 Down
7 changes: 5 additions & 2 deletions Examples/DisplayReadings/DisplayReadings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ void setup() { //
delay(2000); // Wait for comms port to connect //
Serial.print(F("\n\nDisplay INA226 Readings V1.0.0\n")); // Display program information //
INA226.begin( 1, // ± Amps maximum expected on bus //
100000); // Shunt resistance in nanoOhm(µ?),//
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 //
INA226.setShuntConversion(); // Maximum conversion time 8.244ms //
INA226.setMode(7); // Bus/shunt measured continuously //

INA226.setMode(INA_MODE_TRIGGERED_BOTH);

// INA226.setMode(7); // Bus/shunt measured continuously //
} // of method setup() // //
/*******************************************************************************************************************
** This is the main program for the Arduino IDE, it is called in an infinite loop. The INA226 measurements are **
Expand Down
2 changes: 1 addition & 1 deletion Examples/DisplayReadings/__vm/Upload.vmps.xml

Large diffs are not rendered by default.

20 changes: 15 additions & 5 deletions INA226.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ void INA226_Class::begin(const uint8_t maxBusAmps, const uint32_t nanoOhmR) { //
} // for-next each possible I2C address // //
} // of method begin() //----------------------------------//


/*******************************************************************************************************************
** Method readByte reads 1 byte from the specified address **
*******************************************************************************************************************/
Expand Down Expand Up @@ -96,18 +95,28 @@ void INA226_Class::writeWord(const uint8_t addr, const uint16_t data) { //
/*******************************************************************************************************************
** Method getBusMilliVolts retrieves the bus voltage measurement **
*******************************************************************************************************************/
uint16_t INA226_Class::getBusMilliVolts() { // //
uint16_t INA226_Class::getBusMilliVolts(const bool waitSwitch=false) { // //
if (waitSwitch) waitForConversion(); // wait for conversion to complete //
uint16_t busVoltage = readWord(INA_BUS_VOLTAGE_REGISTER); // Get the raw value and apply //
busVoltage = busVoltage*INA_BUS_VOLTAGE_LSB/100; // conversion to get milliVolts //
busVoltage = (uint32_t)busVoltage*INA_BUS_VOLTAGE_LSB/100; // conversion to get milliVolts //
if (!bitRead(_OperatingMode,2) && bitRead(_OperatingMode,1)) { // If triggered mode and bus active //
int16_t configRegister = readWord(INA_CONFIGURATION_REGISTER); // Get the current register //
writeWord(INA_CONFIGURATION_REGISTER,configRegister); // Write back to trigger next //
} // of if-then triggered mode enabled // //
return(busVoltage); // return computed milliVolts //
} // of method getBusMilliVolts() // //

/*******************************************************************************************************************
** Method getShuntMicroVolts retrieves the shunt voltage measurement **
*******************************************************************************************************************/
int16_t INA226_Class::getShuntMicroVolts() { // //
int16_t INA226_Class::getShuntMicroVolts(const bool waitSwitch=false) { // //
if (waitSwitch) waitForConversion(); // wait for conversion to complete //
int16_t shuntVoltage = readWord(INA_SHUNT_VOLTAGE_REGISTER); // Get the raw value //
shuntVoltage = shuntVoltage*INA_SHUNT_VOLTAGE_LSB/10; // Convert to microvolts //
if (!bitRead(_OperatingMode,2) && bitRead(_OperatingMode,0)) { // If triggered and shunt active //
int16_t configRegister = readWord(INA_CONFIGURATION_REGISTER); // Get the current register //
writeWord(INA_CONFIGURATION_REGISTER,configRegister); // Write back to trigger next //
} // of if-then triggered mode enabled // //
return(shuntVoltage); // return computed microvolts //
} // of method getShuntMicroVolts() // //

Expand Down Expand Up @@ -206,7 +215,8 @@ void INA226_Class::reset() { //
void INA226_Class::setMode(uint8_t mode = 7) { // Set the monitoring mode //
int16_t configRegister = readWord(INA_CONFIGURATION_REGISTER); // Get the current register //
configRegister &= ~INA_CONFIG_MODE_MASK; // zero out the mode bits //
mode = B00001111 | mode; // Mask off unused bits //
mode = B00001111 & mode; // Mask off unused bits //
configRegister |= mode; // shift in the mode settings //
writeWord(INA_CONFIGURATION_REGISTER,configRegister); // Save new value //
_OperatingMode = mode; // Save the operating mode //
} // of method setMode() // //
5 changes: 3 additions & 2 deletions INA226.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
INA226_Class(); // Class constructor //
~INA226_Class(); // Class destructor //
void begin(const uint8_t maxBusAmps, const uint32_t nanoOhmR); // Class initializer //
uint16_t getBusMilliVolts(); // Retrieve Bus voltage in mV //
int16_t getShuntMicroVolts(); // Retrieve Shunt voltage in uV //
uint16_t getBusMilliVolts(const bool waitSwitch=false); // Retrieve Bus voltage in mV //
int16_t getShuntMicroVolts(const bool waitSwitch=false); // Retrieve Shunt voltage in uV //
int32_t getBusMicroAmps(); // Retrieve microamps //
int32_t getBusMicroWatts(); // Retrieve microwatts //
void reset(); // Reset the device //
Expand All @@ -100,5 +100,6 @@
uint16_t _Configuration = 0; // Configuration register value //
uint16_t _Current_LSB = 0; // Amperage LSB //
uint32_t _Power_LSB = 0; // Wattage LSB //
uint8_t _OperatingMode = B111; // Default continuous mode operation//
}; // of MicrochipSRAM class definition // //
#endif //----------------------------------//

0 comments on commit 9890632

Please sign in to comment.