From 22bf8b5a84385c1653047b2e1dd9be687c4bc24b Mon Sep 17 00:00:00 2001 From: stancecoke Date: Thu, 21 Dec 2023 16:14:19 +0100 Subject: [PATCH] disable PWM after one minute idle --- Src/FOC.c | 7 +++++-- Src/main.c | 15 +++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Src/FOC.c b/Src/FOC.c index 33e76b1d..81299cdd 100644 --- a/Src/FOC.c +++ b/Src/FOC.c @@ -242,11 +242,14 @@ void FOC_calculation(int16_t int16_i_as, int16_t int16_i_bs, q31_t q31_teta, int if(MS_FOC->system_state){ MS_FOC->teta_obs=atan2_LUT(-fl_e_beta_obs,fl_e_alpha_obs)+SPEC_ANGLE;//811271600;//1312351118;//-811271600;//-930576247;//-1431655765; } - if(q31_erps_counter<10000)q31_erps_counter++; + if(q31_erps_counter<10000){ + q31_erps_counter++; + MS_FOC->system_state = Sensorless; + } else { MS_FOC->Speed=10000; MS_FOC->system_state=IdleRun; - if(!int16_i_q_target&&MS_FOC->Obs_flag)CLEAR_BIT(TIM1->BDTR, TIM_BDTR_MOE); + //if(!int16_i_q_target&&MS_FOC->Obs_flag)CLEAR_BIT(TIM1->BDTR, TIM_BDTR_MOE); if(MP_FOC->com_mode==Hallsensor_Sensorless)MS_FOC->Obs_flag=0;//reset for Hall sensor startup } diff --git a/Src/main.c b/Src/main.c index 939d16d7..41a2fe93 100644 --- a/Src/main.c +++ b/Src/main.c @@ -148,7 +148,7 @@ uint32_t uint32_PAS_fraction= 100; uint32_t uint32_SPEED_counter=32000; uint32_t uint32_SPEEDx100_cumulated=0; uint32_t uint32_PAS=32000; - +uint16_t uint16_idle_run_counter= 0; q31_t q31_rotorposition_PLL = 0; q31_t q31_angle_per_tic = 0; @@ -925,7 +925,7 @@ if(MP.com_mode==Sensorless_openloop||MP.com_mode==Sensorless_startkick)MS.Obs_fl //------------------------------------------------------------------------------------------------------------ //enable PWM if power is wanted if (MS.i_q_setpoint>0&&!READ_BIT(TIM1->BDTR, TIM_BDTR_MOE)){ - + MS.system_state=Running; uint16_half_rotation_counter=0; uint16_full_rotation_counter=0; TIM1->CCR1 = 1023; //set initial PWM values @@ -951,8 +951,15 @@ if(MP.com_mode==Sensorless_openloop||MP.com_mode==Sensorless_startkick)MS.Obs_fl HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); if(MS.Obs_flag)arm_sin_cos_q31(FILTER_DELAY/((MS.Speed)+1), &MS.sin_delay_filter, &MS.cos_delay_filter); if(MP.com_mode==Hallsensor_Sensorless&&MS.Speed<8000&&!MS.Obs_flag)MS.Obs_flag=1; - + if(MS.system_state==IdleRun)uint16_idle_run_counter++; + else uint16_idle_run_counter=0; if(ui8_KV_detect_flag){ui16_KV_detect_counter++;} + //disable PWM after 1 minute idle run. + if(uint16_idle_run_counter>960){ + MS.system_state=Stop; + uint16_idle_run_counter=0; + CLEAR_BIT(TIM1->BDTR, TIM_BDTR_MOE); + } #if (R_TEMP_PULLUP) MS.Temperature = T_NTC(adcData[6]); //Thank you Hendrik ;-) #else @@ -1001,7 +1008,7 @@ if(MP.com_mode==Sensorless_openloop||MP.com_mode==Sensorless_startkick)MS.Obs_fl //print values for debugging - sprintf_(buffer, "%d, %d, %d, %d, %d, %d, %d, %d, %d\r\n", adcData[1],MS.i_q_setpoint, MS.Speed, temp4, MS.Obs_flag, int32_temp_current_target , MS.i_q, MS.teta_obs, MS.system_state); + sprintf_(buffer, "%d, %d, %d, %d, %d, %d, %d, %d, %d\r\n", adcData[1],MS.i_q_setpoint, MS.Speed, temp4, MS.Obs_flag, int32_temp_current_target , MS.i_q, uint16_idle_run_counter, MS.system_state); // sprintf_(buffer, "%d, %d, %d, %d, %d, %d, %d\r\n",(uint16_t)adcData[0],(uint16_t)adcData[1],(uint16_t)adcData[2],(uint16_t)adcData[3],(uint16_t)(adcData[4]),(uint16_t)(adcData[5]),(uint16_t)(adcData[6])) ; // sprintf_(buffer, "%d, %d, %d, %d, %d, %d\r\n",tic_array[0],tic_array[1],tic_array[2],tic_array[3],tic_array[4],tic_array[5]) ; i=0;