Battery discharging control restructured

- Discharging control separated from charger state machine
- Unit-tests for discharging control added
- DC bus chg/dis_enabled flags removed, control now only based on chge/dis_current_limit values
- _current_max values renamed to _limit to make more clear that values for discharging direction must be negative
- Load output struct now stores pointer to internal and external DC bus objects
This commit is contained in:
Martin Jaeger
2019-10-16 16:04:21 +02:00
parent cce6e2a9b3
commit f33146e9de
17 changed files with 217 additions and 102 deletions
+18 -6
View File
@@ -23,8 +23,9 @@
* Load/USB output functions and data types
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdbool.h>
#include "dc_bus.h"
/** Load/USB output states
@@ -48,20 +49,29 @@ typedef struct {
uint16_t switch_state; ///< Current state of load output switch
uint16_t usb_state; ///< Current state of USB output
DcBus *bus; ///< Pointer to DC bus containting actual voltage and current measurement
DcBus *bus_int; ///< Pointer to internal DC bus where the load output
///< current is coming from
DcBus *terminal; ///< Pointer to DC bus containting actual voltage and current
///< measurement of (external) load output terminal
float current_max; ///< maximum allowed current
int overcurrent_timestamp; ///< time at which an overcurrent event occured
float junction_temperature; ///< calculated using thermal model based on current and ambient temperature measurement (unit: °C)
float junction_temperature; ///< calculated using thermal model based on current and ambient
///< temperature measurement (unit: °C)
bool enabled_target; ///< target setting defined via communication port (overruled if battery is empty)
bool enabled_target; ///< target setting defined via communication port (overruled if
///< battery is empty)
bool usb_enabled_target; ///< same for USB output
} LoadOutput;
/** Initialize LoadOutput struct and overcurrent / short circuit protection comparator (if existing)
*
* @param load Load output struct
* @param bus_int Internal DC bus the load switch is connected to (e.g. battery and DC/DC junction)
* @param terminal Load terminal DC bus (external interface)
*/
void load_init(LoadOutput *load, DcBus *bus);
void load_init(LoadOutput *load, DcBus *bus_int, DcBus *terminal);
/** Enable/disable load switch
*/
@@ -72,8 +82,10 @@ void load_switch_set(bool enabled);
void load_usb_set(bool enabled);
/** State machine, called every second.
*
* @param load Load output struct
*/
void load_state_machine(LoadOutput *load, bool source_enabled);
void load_state_machine(LoadOutput *load);
/** Main load control function, should be called by control timer
*