From 6316dcd57f9f320e9dc02d0484197b73dd36c61c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Tue, 30 Jun 2020 10:35:10 +0200 Subject: [PATCH] Add DC/DC HV side output enable switch --- boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts | 9 +++++++++ boards/arm/mppt_2420_rc/mppt_2420_rc.dts | 5 +++++ src/dcdc.cpp | 22 ++++++++++++++++++++++ src/dcdc.h | 11 +++++++++++ 4 files changed, 47 insertions(+) diff --git a/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts b/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts index 87cca2c..e6cf158 100644 --- a/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts +++ b/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts @@ -38,6 +38,7 @@ leds { compatible = "gpio-leds"; + pwr { gpios = <&gpioc 15 GPIO_ACTIVE_HIGH>; label = "Power LED"; @@ -46,21 +47,29 @@ outputs { compatible = "outputs"; + pwm_switch { label = "PWM power switch (solar panel)"; pwms = <&pwm3 2 (20*1000*1000)>; /* 20 ms period = 50 Hz */ current-max = <20>; kconfig-flag; /* make node visible in Kconfig */ }; + load { label = "Load output"; gpios = <&gpiob 15 GPIO_ACTIVE_LOW>; current-max = <20>; }; + charge_pump { label = "Charge pump for HS MOSFET drivers"; pwms = <&pwm8 1 200000>; /* 200 us period = 5 kHz */ }; + + hv-ext-sense { + label = "HV external sense and switch"; + gpios = <&gpiob 12 GPIO_ACTIVE_LOW>; + }; }; adc-inputs { diff --git a/boards/arm/mppt_2420_rc/mppt_2420_rc.dts b/boards/arm/mppt_2420_rc/mppt_2420_rc.dts index 1fdaf38..632f2ed 100644 --- a/boards/arm/mppt_2420_rc/mppt_2420_rc.dts +++ b/boards/arm/mppt_2420_rc/mppt_2420_rc.dts @@ -51,6 +51,11 @@ label = "CAN disable / standby"; gpios = <&gpiob 14 GPIO_ACTIVE_LOW>; }; + + hv-ext-sense { + label = "HV external sense and switch"; + gpios = <&gpiob 12 GPIO_ACTIVE_LOW>; + }; }; adc-inputs { diff --git a/src/dcdc.cpp b/src/dcdc.cpp index f9ae995..af85fc8 100644 --- a/src/dcdc.cpp +++ b/src/dcdc.cpp @@ -8,6 +8,10 @@ #include +#ifndef UNIT_TEST +#include +#endif + #include // for fabs function #include // for min/max function #include @@ -290,4 +294,22 @@ void Dcdc::fuse_destruction() counter++; } +void Dcdc::output_hvs_enable() +{ +#ifdef DT_OUTPUTS_HV_EXT_SENSE_GPIOS_CONTROLLER + struct device *dev_hv_ext = device_get_binding(DT_OUTPUTS_HV_EXT_SENSE_GPIOS_CONTROLLER); + gpio_pin_configure(dev_hv_ext, DT_OUTPUTS_HV_EXT_SENSE_GPIOS_PIN, + DT_OUTPUTS_HV_EXT_SENSE_GPIOS_FLAGS | GPIO_OUTPUT_ACTIVE); +#endif +} + +void Dcdc::output_hvs_disable() +{ +#ifdef DT_OUTPUTS_HV_EXT_SENSE_GPIOS_CONTROLLER + struct device *dev_hv_ext = device_get_binding(DT_OUTPUTS_HV_EXT_SENSE_GPIOS_CONTROLLER); + gpio_pin_configure(dev_hv_ext, DT_OUTPUTS_HV_EXT_SENSE_GPIOS_PIN, + DT_OUTPUTS_HV_EXT_SENSE_GPIOS_FLAGS | GPIO_OUTPUT_INACTIVE); +#endif +} + #endif /* DT_COMPAT_DCDC */ diff --git a/src/dcdc.h b/src/dcdc.h index f51a743..b79b714 100644 --- a/src/dcdc.h +++ b/src/dcdc.h @@ -130,6 +130,17 @@ private: * @returns 0 if everything is fine, error number otherwise */ int perturb_observe_controller(); + + /** + * If manual control of the reverse polarity MOSFET on the high-side is available, this + * function enables it to use the high voltage side as output. + */ + void output_hvs_enable(); + + /** + * Disable the reverse polarity MOSFET on the high-sied (if option available) + */ + void output_hvs_disable(); }; #endif // __cplusplus