From c11cb2855857833a44cfc85a0162910648b378b7 Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Mon, 3 Oct 2016 16:03:15 +0200 Subject: [PATCH] pwm variable now contains actual timer value This also causes the actual PWM value to be output over UART. --- src/main.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main.c b/src/main.c index 9840eca..be1d940 100644 --- a/src/main.c +++ b/src/main.c @@ -723,14 +723,14 @@ int main(void) pwm = fxp_to_int(controlAction); - if(pwm >= CONV_PWM_MAX) { - timer_set_oc_value(TIM1, TIM_CH_CONV, CONV_PWM_MAX); - } else if(pwm > 0) { - timer_set_oc_value(TIM1, TIM_CH_CONV, pwm); - } else { - timer_set_oc_value(TIM1, TIM_CH_CONV, 0); + if(pwm > CONV_PWM_MAX) { + pwm = CONV_PWM_MAX; + } else if(pwm < 0) { + pwm = 0; } + timer_set_oc_value(TIM1, TIM_CH_CONV, pwm); + #ifdef DEBUG if((time_in_state % 100) == 0) { debug_send_string("pErr: "); @@ -746,7 +746,7 @@ int main(void) } #endif - if(time_in_state > 5000 && pwm > CONV_PWM_MAX && power_state.current_avg < CURRENT_THRESHOLD) { + if(time_in_state > 5000 && fxp_to_int(controlAction) > CONV_PWM_MAX && power_state.current_avg < CURRENT_THRESHOLD) { operState = Bootstrap; nextState = ConvConstVoltage; } @@ -787,14 +787,14 @@ int main(void) pwm = fxp_to_int(controlAction); - if(pwm >= CONV_PWM_MAX) { - timer_set_oc_value(TIM1, TIM_CH_CONV, CONV_PWM_MAX); - } else if(pwm > 0) { - timer_set_oc_value(TIM1, TIM_CH_CONV, pwm); - } else { - timer_set_oc_value(TIM1, TIM_CH_CONV, 0); + if(pwm > CONV_PWM_MAX) { + pwm = CONV_PWM_MAX; + } else if(pwm < 0) { + pwm = 0; } + timer_set_oc_value(TIM1, TIM_CH_CONV, pwm); + if(time_in_state > 5000 && pwm > CONV_PWM_MAX && power_state.current_avg < CURRENT_THRESHOLD) { operState = Bootstrap; nextState = ConvConstCurrent;