Skip to content

Commit

Permalink
fixed mode change with pwm off
Browse files Browse the repository at this point in the history
  • Loading branch information
Netzpfuscher committed Feb 10, 2022
1 parent c1da472 commit 19614eb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
41 changes: 21 additions & 20 deletions common_files/src/VescToSTM.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ void VescToSTM_pwm_force(bool force, bool update){
}
}

bool VescToSTM_overspeed(){
if(MCI_GetAvrgMecSpeedUnit(pMCI[M1]) > MCI_GetLastRampFinalSpeed(pMCI[M1])){
return true;
}else{
return false;
}
}

int16_t VescToSTM_Iq_lim_hook(int16_t iq){

//Do temperature Iq limit
Expand All @@ -122,15 +130,16 @@ int16_t VescToSTM_Iq_lim_hook(int16_t iq){
//Do PWM off feature
if(fp.minimum_current>0 && pMCI[M1]->pSTM->hFaultOccurred == 0){
if(pwm_force == false && abs(iq) <= fp.minimum_current && abs(FW_M1.AvVolt_qd.q) < MIN_DUTY_PWM){
VescToSTM_pwm_stop();
if(VescToSTM_overspeed()==false){
VescToSTM_pwm_stop();
}
}else{
VescToSTM_pwm_start(); //Function checks if PWM off otherwise it does nothing
}
}
return iq;
}


int32_t VescToSTM_rpm_to_speed(int32_t rpm){
int32_t speed = ((rpm*SPEED_UNIT*mc_conf.si_motor_poles)/_RPM);
return speed;
Expand Down Expand Up @@ -318,25 +327,22 @@ void VescToSTM_pwm_start(void){
void VescToSTM_update_torque(int32_t q, int32_t min_erpm, int32_t max_erpm){
q *= DIR_MUL;
if(q >= 0){
//FW_M1.wNominalSqCurr = q*q;
//FW_M1.hDemagCurrent = -((float)q*mc_conf.foc_d_gain_scale_max_mod);
SpeednTorqCtrlM1.PISpeed->wUpperIntegralLimit = q * SP_KIDIV;
SpeednTorqCtrlM1.PISpeed->wLowerIntegralLimit = mc_conf.s_pid_allow_braking ? -q : 0;
SpeednTorqCtrlM1.PISpeed->wLowerIntegralLimit = mc_conf.s_pid_allow_braking ? -q * SP_KIDIV : 0;
SpeednTorqCtrlM1.PISpeed->hUpperOutputLimit = q;
SpeednTorqCtrlM1.PISpeed->hLowerOutputLimit = mc_conf.s_pid_allow_braking ? -q : 0;
//HALL_M1.q = q;

MCI_ExecSpeedRamp(pMCI[M1], VescToSTM_erpm_to_speed(max_erpm), 0);
SpeednTorqCtrlM1.PISpeed->hLowerOutputLimit = mc_conf.s_pid_allow_braking ? -q * SP_KIDIV : 0;
if(MCI_RampCompleted(pMCI[M1])){
MCI_ExecSpeedRamp(pMCI[M1], VescToSTM_erpm_to_speed(max_erpm), 0);
}

}else{
//FW_M1.wNominalSqCurr = q*q;
//FW_M1.hDemagCurrent = ((float)q*mc_conf.foc_d_gain_scale_max_mod);
SpeednTorqCtrlM1.PISpeed->wUpperIntegralLimit = mc_conf.s_pid_allow_braking ? -q : 0;
SpeednTorqCtrlM1.PISpeed->wUpperIntegralLimit = mc_conf.s_pid_allow_braking ? -q * SP_KIDIV : 0;
SpeednTorqCtrlM1.PISpeed->wLowerIntegralLimit = q * SP_KIDIV;
SpeednTorqCtrlM1.PISpeed->hUpperOutputLimit = mc_conf.s_pid_allow_braking ? -q : 0;
SpeednTorqCtrlM1.PISpeed->hUpperOutputLimit = mc_conf.s_pid_allow_braking ? -q * SP_KIDIV : 0;
SpeednTorqCtrlM1.PISpeed->hLowerOutputLimit = q;
//HALL_M1.q = q;
MCI_ExecSpeedRamp(pMCI[M1], VescToSTM_erpm_to_speed(min_erpm) , 0);
if(MCI_RampCompleted(pMCI[M1])){
MCI_ExecSpeedRamp(pMCI[M1], VescToSTM_erpm_to_speed(min_erpm) , 0);
}
}
}

Expand Down Expand Up @@ -415,15 +421,11 @@ void VescToSTM_set_speed(int32_t erpm){
}
VescToSTM_set_open_loop(false, 0, 0);
if(erpm>=0){
//FW_M1.wNominalSqCurr = SpeednTorqCtrlM1.MaxPositiveTorque*SpeednTorqCtrlM1.MaxPositiveTorque;
//FW_M1.hDemagCurrent = -((float)SpeednTorqCtrlM1.MaxPositiveTorque*mc_conf.foc_d_gain_scale_max_mod);
SpeednTorqCtrlM1.PISpeed->wUpperIntegralLimit = (int32_t)SpeednTorqCtrlM1.MaxPositiveTorque * SP_KIDIV;
SpeednTorqCtrlM1.PISpeed->wLowerIntegralLimit = mc_conf.s_pid_allow_braking ? (int32_t)SpeednTorqCtrlM1.MinNegativeTorque * SP_KIDIV: 0;
SpeednTorqCtrlM1.PISpeed->hUpperOutputLimit = SpeednTorqCtrlM1.MaxPositiveTorque;
SpeednTorqCtrlM1.PISpeed->hLowerOutputLimit = mc_conf.s_pid_allow_braking ? SpeednTorqCtrlM1.MinNegativeTorque : 0;
}else{
//FW_M1.wNominalSqCurr = SpeednTorqCtrlM1.MinNegativeTorque*SpeednTorqCtrlM1.MinNegativeTorque;
//FW_M1.hDemagCurrent = ((float)SpeednTorqCtrlM1.MinNegativeTorque*mc_conf.foc_d_gain_scale_max_mod);
SpeednTorqCtrlM1.PISpeed->wUpperIntegralLimit = mc_conf.s_pid_allow_braking ? (int32_t)SpeednTorqCtrlM1.MaxPositiveTorque * SP_KIDIV: 0;
SpeednTorqCtrlM1.PISpeed->wLowerIntegralLimit = (int32_t)SpeednTorqCtrlM1.MinNegativeTorque * SP_KIDIV;
SpeednTorqCtrlM1.PISpeed->hUpperOutputLimit = mc_conf.s_pid_allow_braking ? SpeednTorqCtrlM1.MaxPositiveTorque : 0;
Expand Down Expand Up @@ -466,7 +468,6 @@ float VescToSTM_get_input_current(){

#ifdef G30P
return (float)pMPM[M1]->_super.hAvrgElMotorPowerW/(float)VBS_GetAvBusVoltage_V(pMCT[M1]->pBusVoltageSensor);
//return (float)CURR_GetCurrent(pMCT[M1]->pMainCurrentSensor);// NOT WORKING :(
#endif
}

Expand Down
10 changes: 8 additions & 2 deletions common_files/src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void vEnableOutput( TimerHandle_t xTimer ){
*/
void app_set_configuration(app_configuration *conf) {
appconf = *conf;
static app_use old_app;

if(app_disable==NULL){
app_disable = xTimerCreate("DIS_TMR",MS_TO_TICKS(20) , pdFALSE, ( void * ) 0,vEnableOutput );
Expand Down Expand Up @@ -68,20 +69,25 @@ void app_set_configuration(app_configuration *conf) {
switch (appconf.app_to_use) {
case APP_UART:
if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING){
task_app_kill(&aux_uart);
if(old_app != APP_UART){
task_app_kill(&aux_uart);
}
}
task_cli_init(&aux_uart);
break;
case APP_ADC:
case APP_ADC_UART:
if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING){
task_cli_kill(&aux_uart);
if(old_app == APP_UART){
task_cli_kill(&aux_uart);
}
}
task_app_init(&aux_uart);
break;
default:
break;
}
old_app = appconf.app_to_use;
}


Expand Down
8 changes: 2 additions & 6 deletions m365/STM32CubeIDE/.cproject
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@
<listOptionValue builtIn="false" value="../../Drivers/CMSIS/Include"/>
<listOptionValue builtIn="false" value="../../Drivers/CMSIS/DSP/Include"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.otherflags.1769448087" name="Other flags" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.otherflags" useByScannerDiscovery="true" valueType="stringList">
<listOptionValue builtIn="false" value="-flto"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.otherflags.1769448087" name="Other flags" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.otherflags" useByScannerDiscovery="true" valueType="stringList"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.warnings.extra.1323845115" name="Enable extra warning flags (-Wextra)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.warnings.extra" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.languagestandard.769594203" name="Language standard" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.languagestandard" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.languagestandard.value.gnu11" valueType="enumerated"/>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.608253036" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
Expand All @@ -164,9 +162,7 @@
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script.1027440289" name="Linker Script (-T)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script" useByScannerDiscovery="false" value="${workspace_loc:/${ProjName}/STM32F103C8TX_FLASH.ld}" valueType="string"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.directories.2050242690" name="Library search path (-L)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.directories" useByScannerDiscovery="false" valueType="libPaths"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.libraries.18463665" name="Libraries (-l)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.libraries" useByScannerDiscovery="false" valueType="libs"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.otherflags.1186220329" name="Other flags" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.otherflags" useByScannerDiscovery="false" valueType="stringList">
<listOptionValue builtIn="false" value="-flto"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.otherflags.1186220329" name="Other flags" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.otherflags" useByScannerDiscovery="false" valueType="stringList"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.libmath.5229109" name="Use C math library (-Wl,--start-group -lc -lm -Wl,--end-group)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.libmath" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.nostdlib.628611062" name="No startup or default libs (-nostdlib)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.nostdlib" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.nodefaultlibs.1191492039" name="Do not use default libraries (-nodefaultlibs)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.nodefaultlibs" useByScannerDiscovery="false" value="false" valueType="boolean"/>
Expand Down

0 comments on commit 19614eb

Please sign in to comment.