Commit Graph
74 Commits
Author SHA1 Message Date
Martin Jäger 1bd8734a2e Use K_MSEC macro in k_sleep calls
This is required by Zephyr 2.3, otherwise getting compile error.
2020-05-11 12:26:41 +02:00
Martin Jäger e1c7f97f63 Add support for devices without load output 2020-05-11 10:32:24 +02:00
Martin Jäger 3d4da66955 Generate DeviceID from hwinfo 2020-05-06 12:53:26 +02:00
Martin Jäger efc0bc8fdc Update to ThingSet library v0.3 2020-05-06 12:53:26 +02:00
Martin Jäger 5e94d72117 Use LL for PWM switch driver to support STM32G4
This adds support for PWM solar input of MPPT 2420 HPX. Also adds new
PwmSwitch::test() function.
2020-05-06 12:53:26 +02:00
Martin Jäger 8dd576e40e Configure PWM switch driver via DTS
Driver now moved to separate .c file to allow ISR handling 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 2d3594d254 Add watchdog for each thread using Zephyr API 2020-05-06 12:53:26 +02:00
Martin Jäger 1252a1ffa1 Make default battery type configurable via Kconfig 2020-05-06 12:53:26 +02:00
Martin Jäger d2dd50fe99 Add ThingSet passwords to Kconfig 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 2d74a3a554 Mbed support removed
Rationale: The support for both Zephyr and Mbed made the code confusing,
especially because of many ifdefs.

Zephyr RTOS is the future!
2020-04-04 08:21:43 +02: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 5e3181f5e5 Distinguishing between OV and UV alerts, inhibit added
- During overvoltage alerts, only power sources (PWM switch and DC/DC are
  switched off), undervoltage only switches load off
- Alert inhibit added to prevent switching off during PWM switch startup
2019-11-05 18:43:33 +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 bc8f74aa45 Multiple UExt objects at same time (#68)
The change permits use of multiple UExt objects at the same time,
given that these use different pins.
The current UExt code is safe to be used in combination
(OLED display and ESP32 wifi).
Future extension may require some checks to be put in place to
ensure correct configuration.
Could be achieved using preprocessor macros easily.

Uses same objectification concept we used for the ThingSet devices.
Could be merged into one if desired.
2019-11-04 09:23:37 +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
azeemshatp 6bc2adb793 Bootloader support for STM32L07x MCUs (#65)
A custom linker script (.ld) is added to the root project folder. platformio.ini file updated to add the new env: pwm-2420-lus-v0.3-bl and build_flags. Start address for each Application in the flash need to be is modified in this .ld file. Readme file is updated accordingly. New functions added to perform flash write operations to store the bootloader status.
2019-10-28 13:30:19 +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 515b098e85 Passing of bat voltage and current limits to other ports updated 2019-10-23 07:29:05 +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 a89ac7ff4b Fixing not working references to bat/solar ports in data_objects 2019-10-21 18:00:27 +02:00
Martin Jaeger 8558cef9cb PWM switch also implemented as class 2019-10-20 22:01:45 +02:00
Martin Jaeger b5c7f396e1 PowerPort configuration for different charger types improved
- 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
2019-10-20 17:44:32 +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 29e186624c ThingSet device renamed to interface
Reason: According to ThingSet spec, a device is a complete physical hardware device like a charge controller.
Within one device, we can have different communication interfaces that use the ThingSet protocol.
2019-10-17 10:36:48 +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 6d91e075b3 Update of DC/DC lv side targets based on bat + load 2019-10-15 16:46:24 +02:00
Martin Jaeger ae51d7a0d7 Unit tests for DC/DC control added 2019-10-15 13:59:48 +02:00
Martin Jaeger e7317ae1d8 DC bus and terminal naming improved
- 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
2019-10-15 13:57:23 +02:00
Hogthrob 41f142c112 Readded sleep code to make it work 2019-08-28 17:40:40 +02:00
Hogthrob 4764e0a5d0 Improved command input
Now handles buffer full condition gracefully. Originally a full buffer
would have prevented any further command processing until reboot

Changed buffer types to minimize the number of explicit cast we are
using
2019-08-28 17:39:32 +02:00
Hogthrob a1098aaf71 ThingSetDevice classes
These replace the previous C impementation.
- permits any combination of thingset devices being present
- removes essentially all thingset related #ifdefs outside the actual implementation files.
- Code size is reduced. Code duplication eliminated.

The code is not final in its structure, but works with CAN and Serial.
USBSerial does not work on the F072 (L073 not tested) but this was also
the case for the C implementation.

It is required to apply the changes to the platformio.ini otherwise
the code will not compile.
2019-08-28 17:37:05 +02:00
Martin Jaeger 3f4f52ea18 PWM switch: Bug fixed + some improvements
- 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
2019-08-16 11:37:25 +02:00
Martin Jaeger c968a6bb8a Structs renamed for new coding style (closes #42) 2019-08-08 10:16:16 +02:00
Martin Jaeger 17b044d941 Improve SOC and load LED behavior at low SOC
This commit prevents that the SOC bar shows 2 LEDs already even though the load is still switched of because of low voltage.
2019-07-11 17:50:40 +02:00
Martin Jaeger 3a2af7ccc7 Rewrite of LED module (closes #28) 2019-07-11 17:19:06 +02:00
Martin Jaeger 7300406b94 DC/DC test function and dead time config added
- 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.
2019-07-05 11:01:35 +02:00
Martin Jaeger 26ae254ec4 Fixing load overvoltage protection (closes #27) 2019-06-25 09:14:57 +02:00
hogthrob 14faa1f0e8 Working CAN (#35)
* Minor fix in documentation

* Make CAN compile again

* Now able to disable uart_serial

* Boots and runs CAN

Requires matching thingset-cpp library
The placement of the ts_can.process_asap/process_1s is a little hack,
but I did want to add even more ifdefs in the main method.
Renaming the functions could do the trick.
BTW, serial and CAN thingset can be run at the same time, no problems.

* Some cleanups in the CAN interface
2019-06-23 00:41:01 +02:00
Martin Jaeger 690e204a16 Solar, bat and load power added to data objects 2019-06-18 17:04:33 +02:00
Martin Jaeger 375fcee514 New ThingSet features pub and auth included 2019-06-18 14:20:14 +02:00
Martin Jaeger 96d26b5c34 Fixing stalled MCU if solar is connected before battery
(the change in dcdc.cpp fixes the failed unit-test in previous commit, which didn't find min/max functions)
2019-06-16 14:46:54 +02:00
Martin Jaeger dec36143dd 12V/24V detection added and bat_charger restructured 2019-05-23 22:16:41 +02:00
Martin Jaeger b742fe6671 Energy calculation for PWM CC fixed
- Correct negative sign for incoming solar current
- Current multiplied with PWM duty cycle to get average current
- Min/max calculation moved to log.cpp
2019-05-15 11:06:49 +02:00
Martin Jaeger 7c75548193 DC bus type introduced and unit tests added 2019-05-07 18:56:04 +02:00