A compilation of some hardware sensors and their shared programming interfaces.

Committer:
mgottscho
Date:
Wed Mar 19 00:35:31 2014 +0000
Revision:
1:15396cab58d1
Parent:
0:8d34cc2ff388
Updated for most recent UtilityLib.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mgottscho 0:8d34cc2ff388 1 /* MAX17043.h
mgottscho 0:8d34cc2ff388 2 * Tested with mbed board: FRDM-KL46Z
mgottscho 0:8d34cc2ff388 3 * Author: Mark Gottscho
mgottscho 0:8d34cc2ff388 4 * mgottscho@ucla.edu
mgottscho 0:8d34cc2ff388 5 */
mgottscho 0:8d34cc2ff388 6
mgottscho 0:8d34cc2ff388 7 #ifndef MAX17043_H
mgottscho 0:8d34cc2ff388 8 #define MAX17043_H
mgottscho 0:8d34cc2ff388 9
mgottscho 0:8d34cc2ff388 10 #include "mbed.h"
mgottscho 0:8d34cc2ff388 11 #include "I2CSensor.h"
mgottscho 0:8d34cc2ff388 12 #include "PeriodicSensor.h"
mgottscho 0:8d34cc2ff388 13
mgottscho 0:8d34cc2ff388 14 /**
mgottscho 0:8d34cc2ff388 15 * This class allows for easy control over a MAX17043 LiPo fuel gauge IC.
mgottscho 0:8d34cc2ff388 16 */
mgottscho 0:8d34cc2ff388 17 class MAX17043 : public I2CSensor, public PeriodicSensor {
mgottscho 0:8d34cc2ff388 18 public:
mgottscho 0:8d34cc2ff388 19 /**
mgottscho 0:8d34cc2ff388 20 * @param sda the pin identifier for SDA I2C signal
mgottscho 0:8d34cc2ff388 21 * @param scl the pin identifier for SCL I2C signal
mgottscho 0:8d34cc2ff388 22 * @param i2c_addr the 8-bit I2C address for this device. Note that LSB is a don't care.
mgottscho 0:8d34cc2ff388 23 */
mgottscho 0:8d34cc2ff388 24 MAX17043(PinName sda, PinName scl, int i2c_addr);
mgottscho 0:8d34cc2ff388 25
mgottscho 0:8d34cc2ff388 26 /**
mgottscho 0:8d34cc2ff388 27 *
mgottscho 0:8d34cc2ff388 28 */
mgottscho 0:8d34cc2ff388 29 ~MAX17043();
mgottscho 0:8d34cc2ff388 30
mgottscho 0:8d34cc2ff388 31 /**
mgottscho 0:8d34cc2ff388 32 * Initializes the device to some preferred state.
mgottscho 0:8d34cc2ff388 33 */
mgottscho 0:8d34cc2ff388 34 void selfInit();
mgottscho 0:8d34cc2ff388 35
mgottscho 0:8d34cc2ff388 36 /**
mgottscho 0:8d34cc2ff388 37 * Performs a software reset of the device.
mgottscho 0:8d34cc2ff388 38 */
mgottscho 0:8d34cc2ff388 39 void reset();
mgottscho 0:8d34cc2ff388 40
mgottscho 0:8d34cc2ff388 41 /**
mgottscho 0:8d34cc2ff388 42 * @returns the IC version code
mgottscho 0:8d34cc2ff388 43 */
mgottscho 0:8d34cc2ff388 44 uint16_t getVersion();
mgottscho 0:8d34cc2ff388 45
mgottscho 0:8d34cc2ff388 46 /**
mgottscho 0:8d34cc2ff388 47 * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value.
mgottscho 0:8d34cc2ff388 48 * The latter is preferred if this object is set up to sample using interrupts.
mgottscho 0:8d34cc2ff388 49 * @returns the battery voltage raw ADC value
mgottscho 0:8d34cc2ff388 50 */
mgottscho 0:8d34cc2ff388 51 uint16_t getVCell(bool sampleNow);
mgottscho 0:8d34cc2ff388 52
mgottscho 0:8d34cc2ff388 53 /**
mgottscho 0:8d34cc2ff388 54 * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value.
mgottscho 0:8d34cc2ff388 55 * The latter is preferred if this object is set up to sample using interrupts.
mgottscho 0:8d34cc2ff388 56 * @returns the battery voltage as floating point
mgottscho 0:8d34cc2ff388 57 */
mgottscho 0:8d34cc2ff388 58 float getFloatVCell(bool sampleNow);
mgottscho 0:8d34cc2ff388 59
mgottscho 0:8d34cc2ff388 60 /**
mgottscho 0:8d34cc2ff388 61 * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value.
mgottscho 0:8d34cc2ff388 62 * The latter is preferred if this object is set up to sample using interrupts.
mgottscho 0:8d34cc2ff388 63 * @returns the battery state of charge as computed by the ModelGauge algorithm. High byte: units of %. Low byte: units of 1/256%.
mgottscho 0:8d34cc2ff388 64 */
mgottscho 0:8d34cc2ff388 65 uint16_t getSOC(bool sampleNow);
mgottscho 0:8d34cc2ff388 66
mgottscho 0:8d34cc2ff388 67 /**
mgottscho 0:8d34cc2ff388 68 * @param sampleNow if true, queries the device for the sample and returns it. if false, gets the last queried value.
mgottscho 0:8d34cc2ff388 69 * The latter is preferred if this object is set up to sample using interrupts.
mgottscho 0:8d34cc2ff388 70 * @returns the battery state of charge in %, as a floating point #
mgottscho 0:8d34cc2ff388 71 */
mgottscho 0:8d34cc2ff388 72 float getFloatSOC(bool sampleNow);
mgottscho 0:8d34cc2ff388 73
mgottscho 0:8d34cc2ff388 74 private:
mgottscho 0:8d34cc2ff388 75 /**
mgottscho 0:8d34cc2ff388 76 * Interrupt service routine for fetching SOC and VCell data from the device.
mgottscho 0:8d34cc2ff388 77 */
mgottscho 0:8d34cc2ff388 78 virtual void __sample_data_ISR();
mgottscho 0:8d34cc2ff388 79
mgottscho 0:8d34cc2ff388 80 uint16_t __soc;
mgottscho 0:8d34cc2ff388 81 uint16_t __vcell;
mgottscho 0:8d34cc2ff388 82
mgottscho 0:8d34cc2ff388 83 ///////////////// CONSTANTS /////////////////////
mgottscho 0:8d34cc2ff388 84
mgottscho 0:8d34cc2ff388 85 //Device register addresses
mgottscho 0:8d34cc2ff388 86 static const uint8_t VCELL_MSB = 0x02; //Read only
mgottscho 0:8d34cc2ff388 87 static const uint8_t VCELL_LSB = 0x03; //Read only
mgottscho 0:8d34cc2ff388 88 static const uint8_t SOC_MSB = 0x04; //Read only
mgottscho 0:8d34cc2ff388 89 static const uint8_t SOC_LSB = 0x05; //Read only
mgottscho 0:8d34cc2ff388 90 static const uint8_t MODE_MSB = 0x06; //Write only
mgottscho 0:8d34cc2ff388 91 static const uint8_t MODE_LSB = 0x07; //Write only
mgottscho 0:8d34cc2ff388 92 static const uint8_t VERSION_MSB = 0x08; //Read only
mgottscho 0:8d34cc2ff388 93 static const uint8_t VERSION_LSB = 0x09; //Read only
mgottscho 0:8d34cc2ff388 94 static const uint8_t CONFIG_MSB = 0x0C; //Read/write
mgottscho 0:8d34cc2ff388 95 static const uint8_t CONFIG_LSB = 0x0D; //Read/write
mgottscho 0:8d34cc2ff388 96 static const uint8_t COMMAND_MSB = 0xFE; //Write only
mgottscho 0:8d34cc2ff388 97 static const uint8_t COMMAND_LSB = 0xFF; //Write only
mgottscho 0:8d34cc2ff388 98
mgottscho 0:8d34cc2ff388 99 static const uint16_t RST_CODE = 0x5400; //reset code for COMMAND 16-bit register
mgottscho 0:8d34cc2ff388 100
mgottscho 0:8d34cc2ff388 101 //Levels
mgottscho 0:8d34cc2ff388 102 static const float DIV_VCELL = 1.25e-3; //1.25 mV/level
mgottscho 0:8d34cc2ff388 103 static const float DIV_SOC = 0.00390625; //1/256% / level
mgottscho 0:8d34cc2ff388 104 };
mgottscho 0:8d34cc2ff388 105
mgottscho 0:8d34cc2ff388 106
mgottscho 0:8d34cc2ff388 107 #endif