From 6f591ab2f7244db52a0403439053fc478e65aedf Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Thu, 3 Oct 2019 01:46:05 +0200 Subject: [PATCH] Added a thermal shutdown state --- src/main.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main.c b/src/main.c index 4b13f8c..b9d5d3b 100644 --- a/src/main.c +++ b/src/main.c @@ -34,6 +34,7 @@ enum OperState { ConvFloat, ConvConstCurrent, ConvMPP, + ThermalShutdown, Idle, }; @@ -614,6 +615,10 @@ int main(void) fxp_t ADC2CURRENT_M = fxp_from_float( 0.00225f); fxp_t ADC2CURRENT_T = fxp_from_float(-0.2255f); + // Thermal shutdown thresholds + fxp_t SHUTDOWN_TEMPERATURE = fxp_from_float(55.0f); + fxp_t RECOVER_TEMPERATURE = fxp_from_float(45.0f); + /* if power changes by more than this factor, MPP is tested again */ MPP_MAX_POWER_CHANGE_FACTOR = fxp_from_float(0.2f); @@ -1041,6 +1046,16 @@ int main(void) break; + case ThermalShutdown: + // shut down the converter + timer_set_oc_value(TIM1, TIM_CH_CONV, 0); + + if(power_state.temp_avg < RECOVER_TEMPERATURE) { + nextState = ConvMPP; + operState = Bootstrap; + } + break; + default: debug_send_string("Invalid state detected!"); sentSomething = 1; @@ -1049,6 +1064,10 @@ int main(void) break; } + if(power_state.temp_avg > SHUTDOWN_TEMPERATURE) { + operState = ThermalShutdown; + } + if(operState != lastState) { time_in_state = 0; lastState = operState; @@ -1073,6 +1092,9 @@ int main(void) case ConvMPP: lcd_send_string("MPP"); break; + case ThermalShutdown: + lcd_send_string("TRM"); + break; default: lcd_send_string("???"); break;