Skip to content

Commit

Permalink
Improvement of PLL
Browse files Browse the repository at this point in the history
  • Loading branch information
stancecoke committed Dec 21, 2024
1 parent 04ecf2f commit 1155ea1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .settings/language.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-1059628809318420809" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="482849276983345380" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand All @@ -16,7 +16,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-1059628809318420809" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="482849276983345380" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand Down
6 changes: 3 additions & 3 deletions Inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
//#define INDIVIDUAL_MODES
//#define SPEEDTHROTTLE
#define SIXSTEPTHRESHOLD 20000
#define SPEED_PLL 0 //1 for using PLL, 0 for angle extrapolation
#define SPEED_PLL 1 //1 for using PLL, 0 for angle extrapolation
#define P_FACTOR_PLL 10
#define I_FACTOR_PLL 10

Expand Down Expand Up @@ -76,7 +76,7 @@

//---------------------------------------------------------------------
//Throttle settings
#define THROTTLE_OFFSET 690 //only default value, throttle offset is set at startup automatically
#define THROTTLE_OFFSET 800 //only default value, throttle offset is set at startup automatically
#define THROTTLE_MAX 2850
#define THROTTLE_OVERRIDE

Expand All @@ -93,7 +93,7 @@
//---------------------------------------------------------------------
//power settings
#define PH_CURRENT_MAX 1200
#define BATTERYCURRENT_MAX 14000
#define BATTERYCURRENT_MAX 18000
#define REVERSE 1 //1 for normal direction, -1 for reverse
#define PUSHASSIST_CURRENT 300
#define VOLTAGE_MIN 1320 //33V
Expand Down
4 changes: 2 additions & 2 deletions Src/FOC.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ void FOC_calculation(int16_t int16_i_as, int16_t int16_i_bs, q31_t q31_teta, int
}
if(q31_erps_counter<10000){
q31_erps_counter++;
MS_FOC->system_state = Sensorless;
//MS_FOC->system_state = Sensorless;
}
else {
MS_FOC->Speed=10000;
MS_FOC->system_state=IdleRun;
//MS_FOC->system_state=IdleRun;
//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
}
Expand Down
26 changes: 20 additions & 6 deletions Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ uint16_t uint16_half_rotation_counter=0;
uint16_t uint16_full_rotation_counter=0;
int32_t int32_temp_current_target=0;
q31_t q31_PLL_error=0;
uint8_t ui_8_PLL_counter=0;
q31_t q31_t_Battery_Current_accumulated=0;

q31_t q31_rotorposition_absolute;
Expand Down Expand Up @@ -356,15 +357,15 @@ if(MP.com_mode==Sensorless_openloop||MP.com_mode==Sensorless_startkick)MS.Obs_fl
PI_id.setpoint = 0;
PI_id.limit_output = _U_MAX;
PI_id.max_step=5000;
PI_id.shift=6;
PI_id.shift=10;
PI_id.limit_i=1800;

PI_iq.gain_i=I_FACTOR_I_Q;
PI_iq.gain_p=P_FACTOR_I_Q;
PI_iq.setpoint = 0;
PI_iq.limit_output = _U_MAX;
PI_iq.max_step=5000;
PI_iq.shift=6;
PI_iq.shift=10;
PI_iq.limit_i=_U_MAX;

#ifdef SPEEDTHROTTLE
Expand Down Expand Up @@ -1000,15 +1001,24 @@ if(MP.com_mode==Sensorless_openloop||MP.com_mode==Sensorless_startkick)MS.Obs_fl

} else if (ui8_6step_flag)
SystemState = SixStep;
else
SystemState = Running;
//else
//SystemState = Running;
}

#if (DISPLAY_TYPE == DISPLAY_TYPE_DEBUG && !defined(FAST_LOOP_LOG))
//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, uint16_idle_run_counter, MS.system_state);
sprintf_(buffer, "%d, %d, %d, %d, %d, %d, %d, %u, %d\r\n",
adcData[1],
MS.i_q_setpoint,
MS.Speed,
ui_8_PLL_counter,
MS.Obs_flag,
int32_temp_current_target ,
MS.i_q,
q31_angle_per_tic>>12,
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;
Expand Down Expand Up @@ -1710,7 +1720,7 @@ void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc)
}
if (ui16_tim2_recent < ui16_timertics + (ui16_timertics >> 2)
&& !ui8_overflow_flag && !ui8_6step_flag) { //prevent angle running away at standstill
if (MS.angle_est && iabs(q31_PLL_error) < deg_30) {
if (MS.angle_est && ui_8_PLL_counter>11) {
q31_rotorposition_absolute = q31_rotorposition_PLL;
MS.system_state = PLL;
} else {
Expand Down Expand Up @@ -1885,6 +1895,10 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef* htim)

if(MS.angle_est){
q31_PLL_error=q31_rotorposition_PLL-q31_rotorposition_hall;
if(iabs(q31_PLL_error) < deg_30){
if(ui_8_PLL_counter<12)ui_8_PLL_counter++;
}
else ui_8_PLL_counter=0;
q31_angle_per_tic = speed_PLL(q31_rotorposition_PLL,q31_rotorposition_hall,0);
}

Expand Down

0 comments on commit 1155ea1

Please sign in to comment.