Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef XPAL_BAT_H
00022 #define XPAL_BAT_H
00023
00024 #include <avr/io.h>
00025
00031
00036 #define HL_BAT_VOLT_INVALID 0x7fff // invalid Voltage value
00037
00040 #define HL_BAT_MEASURE_ACTIVE 0x8000 // Flag for measurement in progress
00041
00044 #define HL_BAT_FULL_VOLT 4500
00045
00048 #define HL_BAT_MIN_VOLT 2500
00049
00053 #define HL_BAT_MIN_GPS_VOLT 3500
00054
00058 #define HL_BAT_MAX_VOLT_GRADIENT -50
00059
00060
00063 #define HL_BAT_GRADIENT_COUNT_PON -5 //!< Loaded at power up to ignore the first 5 cycles
00064 #define HL_BAT_GRADIENT_COUNT_MAX 32400 //!< 9 hours, Value will not be incremented beyond this limit
00065
00068 #define HL_BAT_ST_FOPMAX 0x09
00069 #define HL_BAT_V_FOPMAX HL_BAT_FULL_VOLT
00070 #define HL_BAT_ST_FOP4 0x08
00071 #define HL_BAT_V_FOP4 HL_BAT_MIN_GPS_VOLT + (4 * (HL_BAT_FULL_VOLT - HL_BAT_MIN_GPS_VOLT) / 5)
00072 #define HL_BAT_ST_FOP3 0x07
00073 #define HL_BAT_V_FOP3 HL_BAT_MIN_GPS_VOLT + (3 * (HL_BAT_FULL_VOLT - HL_BAT_MIN_GPS_VOLT) / 5)
00074 #define HL_BAT_ST_FOP2 0x06
00075 #define HL_BAT_V_FOP2 HL_BAT_MIN_GPS_VOLT + (2 * (HL_BAT_FULL_VOLT - HL_BAT_MIN_GPS_VOLT) / 5)
00076 #define HL_BAT_ST_FOP1 0x05
00077 #define HL_BAT_V_FOP1 HL_BAT_MIN_GPS_VOLT + (1 * (HL_BAT_FULL_VOLT - HL_BAT_MIN_GPS_VOLT) / 5)
00078 #define HL_BAT_ST_FOPMIN 0x04
00079 #define HL_BAT_V_FOPMIN HL_BAT_MIN_GPS_VOLT
00080 #define HL_BAT_ST_LIM3 0x03
00081 #define HL_BAT_V_LIM3 HL_BAT_MIN_VOLT + (3 * (HL_BAT_MIN_GPS_VOLT - HL_BAT_MIN_VOLT)/ 4)
00082 #define HL_BAT_ST_LIM2 0x02
00083 #define HL_BAT_V_LIM2 HL_BAT_MIN_VOLT + (2 * (HL_BAT_MIN_GPS_VOLT - HL_BAT_MIN_VOLT)/ 4)
00084 #define HL_BAT_ST_LIM1 0x01
00085 #define HL_BAT_V_LIM1 HL_BAT_MIN_VOLT + (1 * (HL_BAT_MIN_GPS_VOLT - HL_BAT_MIN_VOLT)/ 4)
00086 #define HL_BAT_ST_EMPTY 0x00
00087 #define HL_BAT_V_EMPTY HL_BAT_MIN_VOLT
00088
00091 #define HL_BAT_ST_MASK 0x0F //!< Battery State bits
00092 #define HL_BAT_UPDATE 0x80 //!< Check Bat Condition when set (xpal_bat internal bit)
00093 #define HL_BAT_NEWSTAT 0x40 //!< Status is new and returned for the first time
00094 #define HL_BAT_BLED_OFF 0x20 //!< Notice that Battery level is fast decreasing
00095 #define HL_BAT_GPS_STOP 0x10 //!< Notice that GPS will be powered off
00096
00097 extern volatile uint8_t BatStatus;
00098
00099 extern volatile uint16_t BatVoltage;
00100 extern volatile int16_t BatGradient;
00101 extern volatile int16_t BatGradientTimer;
00102
00111 void hl_InitBatMan(void);
00112
00117 uint8_t hl_bat_GetBatStatus(void);
00118
00119
00125 inline uint16_t hl_pwr_GetBatVoltage(void){
00126 return (BatVoltage & ~HL_BAT_MEASURE_ACTIVE);
00127 };
00128
00129
00135 inline uint16_t hl_pwr_GetBatGradient(void){
00136 return BatGradient;
00137 };
00138
00144 extern int8_t adc_calibration;
00145
00151 inline uint16_t hl_adc_correct (uint16_t r)
00152 {
00158 return r + ((int32_t)r * adc_calibration >> 8);
00159 }
00160
00172 #define HL_BAT_MV_PER_DIGIT 5
00173
00174 inline uint16_t hl_adc_convert (uint16_t r)
00175 {
00176 return (r * HL_BAT_MV_PER_DIGIT);
00177 }
00178
00179 #endif
00180