A Kconfig CUSTOM_DCDC_CONTROLLER is introduced to enable implementation of
more sophisticated control functions than the standard perturb and observe.
A function dcdc_low_level_controller() must be implemented and is called
from the DMA interrupt after each new current sensor reading.
The default Dcdc::control() function is defined __weak.
The reason is that the voltage disconnect thresholds used in the load outputs
need to be multiplied with number of batteries aswell. As the DcBus class
should contain all voltage-relevant information, it is the right place for the
multiplier.
The sink and source voltage boundaries for droop control and battery
charge voltage management are now part of the DcBus class.
Also added source and sink current margins, which will be used by the
DC/DC for control targets instead of port current limits, which were
difficult to synchronize before.
Preparation to separate current and voltage measurements and control
parameters into DcBus and PowerPort classes. This will help to
manage current from different sources (grid, solar) going towards
one bus and control the battery voltage. It will also help to align
multiple charge controllers in parallel, communicating via CAN bus.
Indentations of class definitions and preprocessor statements were not
uniform throughout the code. This commit cleans up indentations as well
as the order of include statements.
Style conventions see: https://github.com/LibreSolar/coding-style
We should use src_voltage_stop as limit,
since the input voltage start limit is basically an OC voltage
where as the stop voltage is a voltage to be measured under load.
Check for overvoltage/undervoltage conditions after each ADC reading cycle and
trigger alert (stopping DC/DC, PWM switch and load output) if limits exceeded.
In addition to the normal error flags we now have
ERR_ANY_ERROR which may be used to clear all errors
at once or to use in has_error to see if there is any error flag set.
Rationale: Logging is used for historic data, but error flags are instantaneous data. Device status
is more generic and now contains also the internal temperature measurement.
Previous naming with chg/dis didn't make much sense e.g. for load output or solar panels. Voltage
targets are now named with source or sink. Current limits are defined based on their direction
(negative or positive). ASCII art graphic added for better explanation of passive sign convention.
Reason: Previous idea with storing the voltage only once and not in every port
doesn't work well for droop settings, e.g. the DC/DC output port doesn't know
the actual battery current, which should be used to calculate the droop caued
by wire resistance.
- Solar and battery ports now defined as references to actual hardware ports at very beginning of main.cpp, allowing to use the references also in data_objects.cpp
- Different charger types (PWM / MPPT) are configured more clearly by switching on/off features (DC/DC, PWM switch and load) in PCB configuration
The DC bus type caused issues because current limits could not be defined individually for each
connection to a junction, as described in issue #50.
With this commit, also some structs were converted to C++ classes to improve readibility of the
code and make sure that pointers (e.g. to PowerPort objects) are always assigned during
initialization.
- 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
- DcBus representing actual screw terminals renamed
- Internal DC bus at DC/DC low voltage side added for correct DC/DC control
- DC/DC struct now stores pointers to HV and LV bus objects. Redundant voltage and current measurement variables removed.
- Unit tests updated
DC/DC control needs further improvements to make use of the changes
The dcdc_control now better controls which mode (boost vs. buck) is being
used when: If configured in Buck mode, boost mode is never used.
The _dcdc_control function now "knows" if it is in boost or buck mode (dcdc_dir)
The no load condition now uses the dcdc transfer power as measure, not the out current
which is not reflecting the "no dcdc load" condition correctly if a load is connected
The dcdc power has to use the dcdc current and voltage instead of the
output voltage (which can be low side - buck or high side - boost) and
the dcdc current instead of the out current. See #44 for the discussion
on this issue.
- Serious bug: Switch did not go below 90% duty cycle (left-over from testing code). Could result in overcharging of battery.
- Improvement: Preventing very short on/off times (duty cycles close to 0 or 1) as switching time is quite slow
- PWM frequency now configurable via PCB config (and increased from 20 to 25 Hz)
- Some unused parameters in PwmSwitch struct removed and variables renamed
- Overcurrent setting now via solar_bus
- The DC/DC test function slowly ramps up the duty cycle to 50% to allow defined measurements of gate driver, switch node etc. with an oscilloscope (without disturbance by the MPPT algorithm)
- The dead-time between HS and LS gate on/off is now configurable for each PCB and not fixed to 300 ns for all PCBs anymore.
Previously, the DC/DC started at 90% of the solar panel OCV to be closer to the MPP (at around 80% of OCV). This creates stress on the MOSFETs due to high inrush currents. In addtion to that, a high power panel might not be derated fast enough, which caused issues in the 12V/10A charge controller connected to a 280W panel. This commit improves the situation and starts the MPPT slightly below the measured solar voltage with low power.
- Using PlatformIO's embedded unit testing with native environment
- mbed-dependent .cpp files escaped with #ifndef UNIT_TEST
- First tests for charger module added under test/ directory
- Files for interfaces connected via UEXT are stored in separate uext/ directory
- UEXT init and process function names independent of connected module
- LED function names adjusted to start with leds_
- main.cpp structure simplified