PWM switch max current limit control fixed

This commit is contained in:
Martin Jaeger
2019-11-06 10:49:40 +01:00
parent 2992cebb81
commit 4c5401d562
3 changed files with 20 additions and 10 deletions
+5 -3
View File
@@ -159,11 +159,13 @@ void update_measurements()
#if FEATURE_PWM_SWITCH
// current multiplied with PWM duty cycle for PWM charger to get avg current for correct power calculation
pwm_terminal.current = - pwm_switch.get_duty_cycle() * (
pwm_port_int.current = pwm_switch.get_duty_cycle() * (
(float)(((adc_filtered[ADC_POS_I_SOLAR] >> (4 + ADC_FILTER_CONST)) * vcc) / 4096) *
ADC_GAIN_I_SOLAR / 1000.0 + solar_current_offset);
pwm_port_int.current = pwm_terminal.current;
lv_terminal.current = -pwm_port_int.current - load_terminal.current;
pwm_terminal.current = -pwm_port_int.current;
lv_terminal.current = pwm_port_int.current - load_terminal.current;
pwm_port_int.power = pwm_port_int.voltage * pwm_port_int.current;
pwm_terminal.power = pwm_terminal.voltage * pwm_terminal.current;
#endif
#if FEATURE_DCDC_CONVERTER
+1
View File
@@ -29,6 +29,7 @@
#define PWM_DEADTIME 230 // ns
#define PWM_TIM 3 // use TIM3 timer
#define PWM_CURRENT_MAX 15 // PCB maximum PWM switch (solar) current
#define DCDC_CURRENT_MAX 20 // PCB maximum DCDC output current
#define LOAD_CURRENT_MAX 20 // PCB maximum load switch current
+14 -7
View File
@@ -19,6 +19,7 @@
#include "pcb.h"
#include "adc_dma.h"
#include "debug.h"
#include <stdio.h>
#include <time.h> // for time(NULL) function
@@ -164,13 +165,17 @@ void PwmSwitch::control()
{
pwm_signal_stop();
off_timestamp = time(NULL);
printf("PWM charger stop.\n");
print_info("PWM charger stop.\n");
}
else if (port_int->voltage > (port_int->sink_voltage_max - port_int->pos_droop_res * port_int->current) // output voltage above target
|| port_int->current > port_int->pos_current_limit // output current limit exceeded
|| terminal->current < terminal->neg_current_limit) // input current (negative signs) above limit
else if (port_int->voltage > (port_int->sink_voltage_max -
port_int->pos_droop_res * port_int->current) // voltage above target
|| port_int->current > port_int->pos_current_limit // port current limit exceeded
|| port_int->current > PWM_CURRENT_MAX // PCB current limit exceeded
|| terminal->current < terminal->neg_current_limit) // input current (negative signs) above limit
{
// The gate driver switch-off time is quite high (fall time around 1ms), so very short
// decrease power, as limits were reached
// the gate driver switch-off time is quite high (fall time around 1ms), so very short
// on or off periods (duty cycle close to 0 and 1) should be avoided
if (pwm_signal_get_duty_cycle() > 0.95) {
// prevent very short off periods
@@ -180,13 +185,15 @@ void PwmSwitch::control()
// prevent very short on periods and switch completely off instead
pwm_signal_stop();
off_timestamp = time(NULL);
printf("PWM charger stop, no further derating possible.\n");
print_info("PWM charger stop, no further derating possible.\n");
}
else {
pwm_signal_duty_cycle_step(-1);
}
}
else {
// increase power (if not yet at 100% duty cycle)
if (pwm_signal_get_duty_cycle() > 0.95) {
// prevent very short off periods and switch completely on instead
pwm_signal_set_duty_cycle(1);
@@ -208,7 +215,7 @@ void PwmSwitch::control()
// turning the PWM switch on creates a short voltage rise, so inhibit alerts by 100 ms
adc_alert_inhibit(ADC_POS_V_BAT, 100);
pwm_signal_start(1);
printf("PWM charger start.\n");
print_info("PWM charger start.\n");
}
}
}