battery.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "battery.h"
  2. #include "ti/driverlib/dl_i2c.h"
  3. #include "ti_msp_dl_config.h"
  4. Battery batteries[NUM_SLOTS];
  5. // Permissible charge temperature for LiIon battery is 0.0 degree Celsius to 45.0 degree Celsius
  6. // Correct temp_threshold yet to be analyzed
  7. #define TEMP_THRESHOLD (460)
  8. //#define VOLTAGE_THRESHOLD ()
  9. uint16_t charge_change_threshold;
  10. /*Initialize battery array and default parameters*/
  11. void Battery_Init(){
  12. for(uint8_t i=0; i< NUM_SLOTS; i++){
  13. batteries[i].slot_id= i;
  14. batteries[i].state= STATE_EMPTY;
  15. batteries[i].voltage= 0;
  16. batteries[i].current= 0;
  17. batteries[i].temperature= 0;
  18. batteries[i].min_voltage= 0;
  19. batteries[i].max_voltage= 0;
  20. batteries[i].cut_off_current= 0;
  21. batteries[i].capacitance= 0;
  22. }
  23. }
  24. void Battery_SafetyCheck(uint8_t slot){
  25. if(slot>= NUM_SLOTS){
  26. return;
  27. }
  28. if (batteries[slot].temperature > TEMP_THRESHOLD){
  29. batteries[slot].state= STATE_OVERCHARGING;
  30. //How to exit? Disable the DAC channel?
  31. }
  32. }