A compilation of some hardware sensors and their shared programming interfaces.
Embed:
(wiki syntax)
Show/hide line numbers
MAX17043.h
00001 /* MAX17043.h 00002 * Tested with mbed board: FRDM-KL46Z 00003 * Author: Mark Gottscho 00004 * mgottscho@ucla.edu 00005 */ 00006 00007 #ifndef MAX17043_H 00008 #define MAX17043_H 00009 00010 #include "mbed.h" 00011 #include "I2CSensor.h" 00012 #include "PeriodicSensor.h" 00013 00014 /** 00015 * This class allows for easy control over a MAX17043 LiPo fuel gauge IC. 00016 */ 00017 class MAX17043 : public I2CSensor, public PeriodicSensor { 00018 public: 00019 /** 00020 * @param sda the pin identifier for SDA I2C signal 00021 * @param scl the pin identifier for SCL I2C signal 00022 * @param i2c_addr the 8-bit I2C address for this device. Note that LSB is a don't care. 00023 */ 00024 MAX17043 (PinName sda, PinName scl, int i2c_addr); 00025 00026 /** 00027 * 00028 */ 00029 ~MAX17043(); 00030 00031 /** 00032 * Initializes the device to some preferred state. 00033 */ 00034 void selfInit(); 00035 00036 /** 00037 * Performs a software reset of the device. 00038 */ 00039 void reset(); 00040 00041 /** 00042 * @returns the IC version code 00043 */ 00044 uint16_t getVersion (); 00045 00046 /** 00047 * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value. 00048 * The latter is preferred if this object is set up to sample using interrupts. 00049 * @returns the battery voltage raw ADC value 00050 */ 00051 uint16_t getVCell (bool sampleNow); 00052 00053 /** 00054 * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value. 00055 * The latter is preferred if this object is set up to sample using interrupts. 00056 * @returns the battery voltage as floating point 00057 */ 00058 float getFloatVCell (bool sampleNow); 00059 00060 /** 00061 * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value. 00062 * The latter is preferred if this object is set up to sample using interrupts. 00063 * @returns the battery state of charge as computed by the ModelGauge algorithm. High byte: units of %. Low byte: units of 1/256%. 00064 */ 00065 uint16_t getSOC (bool sampleNow); 00066 00067 /** 00068 * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value. 00069 * The latter is preferred if this object is set up to sample using interrupts. 00070 * @returns the battery state of charge in %, as a floating point # 00071 */ 00072 float getFloatSOC (bool sampleNow); 00073 00074 private: 00075 /** 00076 * Interrupt service routine for fetching SOC and VCell data from the device. 00077 */ 00078 virtual void __sample_data_ISR(); 00079 00080 uint16_t __soc; 00081 uint16_t __vcell; 00082 00083 ///////////////// CONSTANTS ///////////////////// 00084 00085 //Device register addresses 00086 static const uint8_t VCELL_MSB = 0x02; //Read only 00087 static const uint8_t VCELL_LSB = 0x03; //Read only 00088 static const uint8_t SOC_MSB = 0x04; //Read only 00089 static const uint8_t SOC_LSB = 0x05; //Read only 00090 static const uint8_t MODE_MSB = 0x06; //Write only 00091 static const uint8_t MODE_LSB = 0x07; //Write only 00092 static const uint8_t VERSION_MSB = 0x08; //Read only 00093 static const uint8_t VERSION_LSB = 0x09; //Read only 00094 static const uint8_t CONFIG_MSB = 0x0C; //Read/write 00095 static const uint8_t CONFIG_LSB = 0x0D; //Read/write 00096 static const uint8_t COMMAND_MSB = 0xFE; //Write only 00097 static const uint8_t COMMAND_LSB = 0xFF; //Write only 00098 00099 static const uint16_t RST_CODE = 0x5400; //reset code for COMMAND 16-bit register 00100 00101 //Levels 00102 static const float DIV_VCELL = 1.25e-3; //1.25 mV/level 00103 static const float DIV_SOC = 0.00390625; //1/256% / level 00104 }; 00105 00106 00107 #endif
Generated on Wed Jul 13 2022 19:24:41 by 1.7.2