battery.c 1.1 KB

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