battery.c 960 B

12345678910111213141516171819202122232425262728293031323334353637
  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. /*Initialize battery array and default parameters*/
  9. void Battery_Init(){
  10. for(uint8_t i=0; i< NUM_SLOTS; i++){
  11. batteries[i].slot_id= i;
  12. batteries[i].state= STATE_EMPTY;
  13. batteries[i].voltage= 0;
  14. batteries[i].current= 0;
  15. batteries[i].temperature= 0;
  16. batteries[i].min_voltage= 0;
  17. batteries[i].max_voltage= 0;
  18. batteries[i].cut_off_current= 0;
  19. batteries[i].capacitance= 0;
  20. }
  21. }
  22. void Battery_SafetyCheck(uint8_t slot){
  23. if(slot>= NUM_SLOTS){
  24. return;
  25. }
  26. if (batteries[slot].temperature > TEMP_THRESHOLD){
  27. batteries[slot].state= STATE_OVERCHARGING;
  28. //How to exit? Disable the DAC channel?
  29. }
  30. }