From 7300406b94ee6e013a057330628c9300d19b55ec Mon Sep 17 00:00:00 2001 From: Martin Jaeger <17674105+martinjaeger@users.noreply.github.com> Date: Fri, 5 Jul 2019 11:01:35 +0200 Subject: [PATCH] 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. --- src/dcdc.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/dcdc.h | 8 ++++++++ src/half_bridge_tim1.cpp | 2 -- src/half_bridge_tim3.cpp | 2 -- src/main.cpp | 2 +- src/pcbs/mppt_1210_hus_0v2.h | 1 + src/pcbs/mppt_1210_hus_0v4.h | 1 + src/pcbs/mppt_1210_hus_0v6.h | 1 + src/pcbs/mppt_2420_lc_0v10.h | 1 + 9 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/dcdc.cpp b/src/dcdc.cpp index 5335f25..8849639 100644 --- a/src/dcdc.cpp +++ b/src/dcdc.cpp @@ -181,6 +181,42 @@ void dcdc_control(dcdc_t *dcdc, dc_bus_t *hs, dc_bus_t *ls) } } +void dcdc_test(dcdc_t *dcdc, dc_bus_t *hs, dc_bus_t *ls) +{ + if (half_bridge_enabled()) { + if (half_bridge_get_duty_cycle() > 0.5) { + half_bridge_duty_cycle_step(-1); + } + } + else { + static int startup_delay_counter = 0; + static const int num_wait_calls = (CONTROL_FREQUENCY / 10 >= 1) ? (CONTROL_FREQUENCY / 10) : 1; // wait at least 100 ms for voltages to settle + if (_dcdc_check_start_conditions(dcdc, ls, hs) && ls->voltage < dcdc->ls_voltage_max) { + if (startup_delay_counter >= num_wait_calls) { + // Don't start directly at Vmpp (approx. 0.8 * Voc) to prevent high inrush currents and stress on MOSFETs + half_bridge_start(ls->voltage / (hs->voltage - 1)); + printf("DC/DC buck mode start (HS: %.2fV, LS: %.2fV, PWM: %.1f).\n", hs->voltage, ls->voltage, half_bridge_get_duty_cycle() * 100); + } + else { + startup_delay_counter++; + } + } + else if (_dcdc_check_start_conditions(dcdc, hs, ls) && hs->voltage < dcdc->hs_voltage_max) { + if (startup_delay_counter >= num_wait_calls) { + // will automatically start with max. duty (0.97) if connected to a nanogrid not yet started up (zero voltage) + half_bridge_start(ls->voltage / (hs->voltage + 1)); + printf("DC/DC boost mode start (HS: %.2fV, LS: %.2fV, PWM: %.1f).\n", hs->voltage, ls->voltage, half_bridge_get_duty_cycle() * 100); + } + else { + startup_delay_counter++; + } + } + else { + startup_delay_counter = 0; // reset counter + } + } +} + void dcdc_self_destruction() { printf("Charge controller self-destruction called!\n"); diff --git a/src/dcdc.h b/src/dcdc.h index 5e75bc2..6c7283a 100644 --- a/src/dcdc.h +++ b/src/dcdc.h @@ -101,6 +101,14 @@ void dcdc_init(dcdc_t *dcdc); */ void dcdc_control(dcdc_t *dcdc, dc_bus_t *high_side, dc_bus_t *low_side); +/** Test mode for DC/DC, ramping up to 50% duty cycle + * + * @param dcdc DC/DC type description + * @param high_side High-side power port (e.g. solar input for typical MPPT charge controller application) + * @param low_side Low-side power port (e.g. battery output for typical MPPT charge controller application) + */ +void dcdc_test(dcdc_t *dcdc, dc_bus_t *high_side, dc_bus_t *low_side); + /** Prevent overcharging of battery in case of shorted HS MOSFET * * This function switches the LS MOSFET continuously on to blow the battery input fuse. The reason for self destruction should diff --git a/src/half_bridge_tim1.cpp b/src/half_bridge_tim1.cpp index cce2fa0..891ee9c 100644 --- a/src/half_bridge_tim1.cpp +++ b/src/half_bridge_tim1.cpp @@ -147,11 +147,9 @@ void half_bridge_start(float pwm_duty) { half_bridge_set_duty_cycle(pwm_duty); -#ifndef PIL_TESTING // Break and Dead-Time Register // MOE = 1: Main output enable TIM1->BDTR |= TIM_BDTR_MOE; -#endif _enabled = true; } diff --git a/src/half_bridge_tim3.cpp b/src/half_bridge_tim3.cpp index 52d0bc5..7e4b13e 100644 --- a/src/half_bridge_tim3.cpp +++ b/src/half_bridge_tim3.cpp @@ -146,7 +146,6 @@ void half_bridge_start(float pwm_duty) { half_bridge_set_duty_cycle(pwm_duty); -#ifndef PIL_TESTING // Capture/Compare Enable Register // CCxE = 1: Enable the output on OCx // CCxP = 0: Active high polarity on OCx (default) @@ -154,7 +153,6 @@ void half_bridge_start(float pwm_duty) // CCxNP = 0: Active high polarity on OC1N (default) TIM3->CCER |= TIM_CCER_CC3E; TIM3->CCER |= TIM_CCER_CC4E; -#endif _enabled = true; } diff --git a/src/main.cpp b/src/main.cpp index 9fa8115..da84be3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -116,7 +116,7 @@ int main() pwm_switch_init(&pwm_switch); #else // MPPT dcdc_init(&dcdc); - half_bridge_init(PWM_FREQUENCY, 300, 12 / dcdc.hs_voltage_max, 0.97); // lower duty limit might have to be adjusted dynamically depending on LS voltage + half_bridge_init(PWM_FREQUENCY, PWM_DEADTIME, 12 / dcdc.hs_voltage_max, 0.97); // lower duty limit might have to be adjusted dynamically depending on LS voltage #endif // Configuration from EEPROM diff --git a/src/pcbs/mppt_1210_hus_0v2.h b/src/pcbs/mppt_1210_hus_0v2.h index 20b6677..e8f8084 100644 --- a/src/pcbs/mppt_1210_hus_0v2.h +++ b/src/pcbs/mppt_1210_hus_0v2.h @@ -24,6 +24,7 @@ // DC/DC converter settings #define PWM_FREQUENCY 50 // kHz 50 = better for cloud solar to increase efficiency +#define PWM_DEADTIME 300 // ns #define PWM_TIM 1 // use TIM1 timer #define DCDC_CURRENT_MAX 8 // PCB maximum DCDC output current diff --git a/src/pcbs/mppt_1210_hus_0v4.h b/src/pcbs/mppt_1210_hus_0v4.h index 98609ed..073ed59 100644 --- a/src/pcbs/mppt_1210_hus_0v4.h +++ b/src/pcbs/mppt_1210_hus_0v4.h @@ -24,6 +24,7 @@ // DC/DC converter settings #define PWM_FREQUENCY 50 // kHz 50 = better for cloud solar to increase efficiency +#define PWM_DEADTIME 230 // ns #define PWM_TIM 3 // use TIM3 timer #define DCDC_CURRENT_MAX 10 // PCB maximum DCDC output current diff --git a/src/pcbs/mppt_1210_hus_0v6.h b/src/pcbs/mppt_1210_hus_0v6.h index d8c07f4..740ee7a 100644 --- a/src/pcbs/mppt_1210_hus_0v6.h +++ b/src/pcbs/mppt_1210_hus_0v6.h @@ -24,6 +24,7 @@ // DC/DC converter settings #define PWM_FREQUENCY 50 // kHz 50 = better for cloud solar to increase efficiency +#define PWM_DEADTIME 230 // ns #define PWM_TIM 3 // use TIM3 timer #define DCDC_CURRENT_MAX 10 // PCB maximum DCDC output current diff --git a/src/pcbs/mppt_2420_lc_0v10.h b/src/pcbs/mppt_2420_lc_0v10.h index 39a927b..5e7736e 100644 --- a/src/pcbs/mppt_2420_lc_0v10.h +++ b/src/pcbs/mppt_2420_lc_0v10.h @@ -24,6 +24,7 @@ // DC/DC converter settings #define PWM_FREQUENCY 70 // kHz 70 = good compromise between output ripple and efficiency +#define PWM_DEADTIME 300 // ns #define PWM_TIM 1 // use TIM1 timer #define DCDC_CURRENT_MAX 20 // PCB maximum DCDC output current