Commit Graph
52 Commits
Author SHA1 Message Date
Martin Jäger 81aefff168 Fix load overvoltage control for 24V systems (#96) 2020-05-21 10:09:54 +02:00
Martin Jäger e1c7f97f63 Add support for devices without load output 2020-05-11 10:32:24 +02:00
Martin Jäger e76709f2af Enable load short circuit comparator
The load driver had to be moved to a .c file to allow attaching interrupt
in Zephyr.
2020-05-06 12:53:26 +02:00
Martin Jäger ce7f63b888 Introduce generic "outputs" DTS binding
Replaces previous "switch" and "pwm-out" bindings and allows to reference
either gpio or pwm handle and specify maximum current.

Also replacing CONFIG_HAS_LOAD and CONFIG_HAS_USB_PWR with DT_ variants.
2020-05-06 12:53:26 +02:00
Martin Jäger 4e6f6c7365 Move thermal model parameters to DTS 2020-05-06 12:53:26 +02:00
Martin Jäger ab504e3dfa DC/DC and PWM switch configuration via DTS
As these settings are clearly hardware-specific, configuration was
moved from Kconfig (hidden symbols) to DTS. New bindings added.
2020-05-06 12:53:26 +02:00
Martin Jäger 2a71d02aeb Move PCB and user config to board Kconfig
Files in src/pcbs/xyz.h are moved to boards/xyz/board.h. User settings from
src/config.h are also configured via Kconfig, so the file is removed.
2020-04-30 10:53:58 +02:00
Martin Jäger 1a9c290485 Charger.num_batteries moved to DcBus.series_multiplier
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.
2020-03-01 09:48:35 +01:00
Martin Jäger 651f66616b Add load info variable (combines state and error_flags) 2020-02-29 13:39:34 +01:00
Martin Jäger fa9d15e796 Separate load and USB out, improve state handling
Identified issues:
- The load output and USB charging port shared the same state machine,
  which did not allow to set different switch-off thresholds.
- Load error codes were global, so it was not possible to have multiple
  load instances.

This commit introduces load-specific error_flags, makes the LoadOutput
class inherit from PowerPort (to improve code readability), separates
the load driver better from higher level implementation and adds a
second LoadOutput object for the USB charging port.
2020-02-21 18:27:36 +01:00
Martin Jaeger 6af8e6d93d Improve load voltage limits setup and update 2020-02-19 14:34:40 +01:00
Martin Jaeger cdb9183c11 Fix load overvoltage limit
The setting is now based on LoadOutput menber overvoltage and not
on the bus voltage bounds, which are used for charging setpoint.
2020-02-19 14:34:40 +01:00
Martin Jaeger 43f90eea7c Move voltage control parameters to DcBus class
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.
2020-02-07 12:03:25 +01:00
Martin Jaeger f0e99cd80f Voltage replaced by DcBus ptr in PowerPort class
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.
2020-02-07 11:55:51 +01:00
Martin Jaeger 24f751b2e5 Initial support of MPPT 2420 HPX board
- Some flags changed to make the firmware compile for new STM32G431 MCU
- Zephyr board definition added
- Serial, OLED display and LED working
- ADC compiling, but not yet working
2020-01-23 14:41:44 +01:00
Martin Jaeger 10f7d44bdf Zephyr: Load output added
Overcurrent protection in PWM charge controller not yet working for Zephyr.
2020-01-18 16:30:37 +01:00
Martin Jaeger a76b92c27b time(NULL) replaced with uptime() in helper files
Reason: Zephyr does not support time(NULL). This way it is portable.
2020-01-16 20:04:37 +01:00
Martin Jaeger cb988639ce Zephyr: Added PWM 2420 LUS board 2020-01-09 13:56:02 +01:00
Martin Jaeger 53ae6d4608 File headers shortened using SPDX-License-Identifier 2019-12-20 11:40:10 +01:00
Martin Jaeger 88148e70cb Initial compiling Zephyr integration 2019-12-20 10:37:50 +01:00
Martin Jaeger 47954166be Fine-tuning of battery/load UV/OV alerts
- Alerts now set to +-20% of actual measured voltage
- Hysteresis for load overvoltage reconnect setpoint made configurable
- Added check for PWM switch MOSFET driver undervoltage
2019-11-11 11:38:34 +01:00
Martin Jaeger f254c77ab6 Refactoring of load control and state machine
- State machine and control merged to one function
- Load states marked as deprecated, global error flags used instead
- Reduced duplicated code and made load control function easier to read
2019-11-11 09:35:26 +01:00
Martin Jaeger 328215dc8e Load overvoltage detection corrected and error flag comments added 2019-11-07 16:00:51 +01:00
Martin Jaeger 7874b8b4d6 ADC alerts and emergency stop functions added
Check for overvoltage/undervoltage conditions after each ADC reading cycle and
trigger alert (stopping DC/DC, PWM switch and load output) if limits exceeded.
2019-11-04 18:12:00 +01:00
hogthrob bec02cb25b Switched to use power of 2 error numbers (#72)
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.
2019-11-04 09:19:06 +01:00
Martin Jaeger 22f9138a15 LogData renamed to DeviceStatus / dev_stat
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.
2019-11-01 09:54:01 +01:00
Martin Jaeger 20bc6d124b Fix to prevent toggling between load states disabled and low SOC 2019-10-31 19:50:55 +01:00
Martin Jaeger cb0c3c8135 USB output state machine improved (see #69) 2019-10-31 16:32:03 +01:00
Martin Jaeger b98461fee4 Load off for internal overtemp implemented 2019-10-31 12:07:21 +01:00
Martin Jaeger b1a7babaff Load overcurrent model now using internal temperature 2019-10-31 11:33:18 +01:00
Martin Jaeger b0e265f3e9 NTC on PCB not used as battery temperature anymore
- MCU temperature was renamed to internal_temperature
- NTC at board edge senses temperatures far above battery / ambient temperature at high loads and is now ignored
- Battery temperature always assumed 25ÂC unless external sensor is detected
2019-10-31 11:22:03 +01:00
Martin Jaeger 5b4df98656 Load protection improvements
- Switched back to older mbed version, as update broke comparator function
- Added voltage dip detection to disconnect load if charge controller is connected to small
  battery or with bad wires and short circuit detection doesn't trigger
- Added more error flags to diagnose reasons for load disconnect
2019-10-30 17:31:16 +01:00
Martin Jaeger 68ae3227cc Discharge and load output control improvements
- Charge/discharge control in charger class sets global error flags
- Load state machine analyzes error flags to distinguish reasons for switching load off
- Temperature errors now identified correctly (issue #59)
- Delay before load re-connect after low voltage or overcurrent event now configurable
- Unit tests added
2019-10-24 16:04:32 +02:00
Martin Jaeger ba10a2882c Fixing load output and improved overvoltage config
Previous load output expected the battery port as a parameter and checked if
discharging of the battery was allowed. New implementation has own load port
and needs to check if current output (i.e. positive direction) is allowed.

Overvoltage setting is now configured via power port sink_voltage_max.
2019-10-23 13:16:04 +02:00
Martin Jaeger 42751c83c2 PowerPort member variables renamed
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.
2019-10-23 10:32:48 +02:00
Martin Jaeger f879dc9c5d DC bus integrated into PowerPort class
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.
2019-10-22 18:23:19 +02:00
Martin Jaeger 0399c4e877 PowerPort added to store current independent from DC bus type
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.
2019-10-20 14:52:35 +02:00
Martin Jaeger 6c3885e5d0 Log unit-tests added 2019-10-16 21:32:35 +02:00
Martin Jaeger f33146e9de 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
2019-10-16 16:04:21 +02:00
Martin Jaeger e51a6384fb Fixing bug in load overvoltage protection 2019-08-16 07:48:56 +02:00
Martin Jaeger c968a6bb8a Structs renamed for new coding style (closes #42) 2019-08-08 10:16:16 +02:00
Martin Jaeger 4bc3f8bd1e Load voltage thresholds adjusted and inhibit added
During tests, the deep discharge counter increased by several 100 counts per day under certain circumstances, most probably because of quite small battery making the voltage toggle between disconnect and reconnect voltage. This commit suggests several improvements.

- Load reconnect voltage increased
- Don't reconnect before waiting at least 1h (lvd_timestamp in load.cpp)
- SOC filter calculation slightly changed to make sure 100% is reached fast enough.
2019-07-12 18:55:13 +02:00
Martin Jaeger 3a2af7ccc7 Rewrite of LED module (closes #28) 2019-07-11 17:19:06 +02:00
Martin Jaeger 26ae254ec4 Fixing load overvoltage protection (closes #27) 2019-06-25 09:14:57 +02:00
Martin Jaeger 690e204a16 Solar, bat and load power added to data objects 2019-06-18 17:04:33 +02:00
Martin Jaeger 0e91c834ac Faster load short circuit protection via LPTIM
The PWM charge controllers don't have a fuse and need a reliable load short
circuit protection implemented in the microcontroller. The comparator
monitoring the load current now triggers LPTIM connected to the load
disable pin. This allows to switch off the load with a defined time delay
and glitch filter.

During tests, switching off the load in an ISR triggered by COMP2 did
not lead to reliable delays (especially in case of wake-up from sleep),
hence this alternative solution using LPTIM was implemented.

The load switch functions were moved from hardware.cpp to load.cpp.
2019-06-12 09:45:19 +02:00
Martin Jaeger 5a264e9332 Load short circuit protection using analog COMP2
- Immediate load cut-off in case of current > 2x rated current (still to be fine-tuned)
- Using built-in comparator of STM32 MCU
- Currently only supported by PWM charge controller PCB, as it doesn't have an internal fuse
2019-05-27 16:41:30 +02:00
Martin Jaeger 7c75548193 DC bus type introduced and unit tests added 2019-05-07 18:56:04 +02:00
Martin Jaeger d9f7103e97 Starting test-driven development (TDD) with Unity
- 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
2019-05-04 11:31:37 +02:00
Martin Jaeger 213ebf8c17 Improved load overcurrent and overvoltage diagnosis and protection 2019-04-28 17:29:57 +02:00