Skip to main content
SRedd.5
Senior III
May 3, 2023
Solved

Open Loop Mode in MCSDK

  • May 3, 2023
  • 9 replies
  • 5396 views

I have seen the following options in the software in MCSDK

 MCI_CMD_SETOPENLOOPCURRENT, /*!< set open loop current .*/

 MCI_CMD_SETOPENLOOPVOLTAGE, /*!< set open loop voltage .*/

in mc_interface.h file, but i don't see any source code related to them does MCSDK support open loop mode? I need them to rectify some of the hardware issues, before i run in closed loop with hall sensors. Please advise.

This topic has been closed for replies.
Best answer by Gael A

Hello,

This is a generation issue that has been fixed on MCSDK 6.1.1, you can download it here : X-CUBE-MCSDK-6.

You can also stick to your 6.1 version, and replace every occurrence of M1_DBG_OPEN_LOOP_ENABLE by DBG_OPEN_LOOP in your .ioc file. Then you can generate the project again via CubeMx. This should fix the problem.

Hope this will help,

Best Regards,

Gaël A.

9 replies

Gael A
ST Employee
May 4, 2023

Hello SRedd.5,

Those two options are for a Motor Pilot feature that can be enabled by checking the "Open Loop" box in the "Stage Configuration" tab while creating your project via workbench :


_legacyfs_online_stmicro_images_0693W00000bjMEsQAM.png 

Using the MotorPilot, the two Open Loop Control Modes now become available :


_legacyfs_online_stmicro_images_0693W00000bjMMMQA2.png 

The Open Loop Voltage Mode is used by varying the Voltage Reference value, and the Open Loop Current Mode by varying the Flux Reference Mode. Both are available by clicking on "Advanced Configuration" on the left of the window. Be sure to set a low target speed to ensure your motor manages to start.

Hope this will help,

Best Regards,

Gaël A.

If you agree with my answer, please consider accepting it by clicking on 'Accept as solution'.Hope this will help,Gaël A.
SRedd.5
SRedd.5Author
Senior III
May 4, 2023

Thank you so much for your replies, it is helping me a lot in the project i could now run the motor in sensorless, now i am trying hall sensor based.

My question is i am using your source code and i downloaded the code from Motor control work bench 6.1.0. When i see the source code mc_interface.c

__weak void MCI_ExecBufferedCommands(MCI_Handle_t *pHandle)

{

#ifdef NULL_PTR_MC_INT

 if (NULL == pHandle)

 {

  /* Nothing to do */

 }

 else

 {

#endif

  if ( pHandle->CommandState == MCI_COMMAND_NOT_ALREADY_EXECUTED )

  {

   bool commandHasBeenExecuted = false;

   switch (pHandle->lastCommand)

   {

    case MCI_CMD_EXECSPEEDRAMP:

    {

     pHandle->pFOCVars->bDriveInput = INTERNAL;

     STC_SetControlMode(pHandle->pSTC, MCM_SPEED_MODE);

     commandHasBeenExecuted = STC_ExecRamp(pHandle->pSTC, pHandle->hFinalSpeed, pHandle->hDurationms);

     break;

    }

    case MCI_CMD_EXECTORQUERAMP:

    {

     pHandle->pFOCVars->bDriveInput = INTERNAL;

     STC_SetControlMode(pHandle->pSTC, MCM_TORQUE_MODE);

     commandHasBeenExecuted = STC_ExecRamp(pHandle->pSTC, pHandle->hFinalTorque, pHandle->hDurationms);

     break;

    }

    case MCI_CMD_SETCURRENTREFERENCES:

    {

     pHandle->pFOCVars->bDriveInput = EXTERNAL;

     pHandle->pFOCVars->Iqdref = pHandle->Iqdref;

     commandHasBeenExecuted = true;

     break;

    }

    default:

     break;

   }

   if (commandHasBeenExecuted)

   {

    pHandle->CommandState = MCI_COMMAND_EXECUTED_SUCCESFULLY;

   }

   else

   {

    pHandle->CommandState = MCI_COMMAND_EXECUTED_UNSUCCESFULLY;

   }

  }

#ifdef NULL_PTR_MC_INT

 }

#endif

}

I don't find the

 MCI_CMD_SETOPENLOOPCURRENT, /*!< set open loop current .*/

 MCI_CMD_SETOPENLOOPVOLTAGE,

commands why is it, where are they present, where is it implemented? Please help.

Gael A
Gael ABest answer
ST Employee
May 4, 2023

Hello,

This is a generation issue that has been fixed on MCSDK 6.1.1, you can download it here : X-CUBE-MCSDK-6.

You can also stick to your 6.1 version, and replace every occurrence of M1_DBG_OPEN_LOOP_ENABLE by DBG_OPEN_LOOP in your .ioc file. Then you can generate the project again via CubeMx. This should fix the problem.

Hope this will help,

Best Regards,

Gaël A.

If you agree with my answer, please consider accepting it by clicking on 'Accept as solution'.Hope this will help,Gaël A.
SRedd.5
SRedd.5Author
Senior III
May 4, 2023

Ok I will do that now.​

SRedd.5
SRedd.5Author
Senior III
May 9, 2023

I have downloaded the software i gave the following command when i receive CAN message

if(g_motormodeselection_u8 == OPENLOOP_VOLTAGEMODE)

    {

    MCI_SetOpenLoopVoltage(&Mci[MOTOR_0]);

    }

but the motor does not run

#define OPEN_LOOP_VOLTAGE_d      2000   /*!< Three Phase voltage amplitude

                           in int16_t format */

#define OPEN_LOOP_SPEED_RPM      100    /*!< Final forced speed in rpm */

#define OPEN_LOOP_SPEED_RAMP_DURATION_MS 1000 /*!< 0-to-Final speed ramp duration */

#define OPEN_LOOP_VF         false   /*!< true to enable V/F mode */

#define OPEN_LOOP_K          44    /*! Slope of V/F curve expressed in int16_t Voltage for

                           each 0.1Hz of mecchanical frequency increment. */

#define OPEN_LOOP_OFF         4400   /*! Offset of V/F curve expressed in int16_t Voltage

                           applied when frequency is zero. */

These are the other settings. I only see i fixed PWM on the phase line.

What is the conversion of 2000 into voltage?

Gael A
ST Employee
May 11, 2023

Hello SRedd.5,

You need to make a few more steps to make your motor run.

After setting your Open Loop Voltage, you need to set a duty cycle (referred as Voltage Reference in motor pilot) in percentage. Usually you want a low duty cycle otherwise your motor won't start. Something like 10% is generally enough. This is done like that :

OL_UpdateVoltage( &OpenLoop_ParamsM1, ((DUTY_CYCLE * 32767) / 100));

You can find this function by looking at the MC_REG_FOC_VDREF register when handling MotorPilot requests.

Then you have to set a speed ramp for your motor to follow, :

MCI_ExecSpeedRamp(&Mci[MOTOR_0], (int16_t)((SPEED_RPM * SPEED_UNIT) / U_RPM), DURATION_MS);

You need to specify SPEED_RPM as well as DURATION_MS. Be careful not to set a too high speed, as your motor may not catch up and never start properly ; keep in mind that when working in Open Loop, you must have low acceleration.

Finally, there's only to call for a motor start via :

MC_StartMotor1();

I hope this will help you start your motor.

Best regards,

Gaël A.

If you agree with my answer, please consider accepting it by clicking on 'Accept as solution'.Hope this will help,Gaël A.
SRedd.5
SRedd.5Author
Senior III
May 11, 2023

I will try and update

SRedd.5
SRedd.5Author
Senior III
May 12, 2023

No the motor does not run the voltage dips to 2V from 20V and current increases. I am not sure what to do.​

Gael A
ST Employee
May 12, 2023

Hello again,

Could you tell me the values you gave for DUTY_CYCLE, SPEED_RPM and DURATION_MS as well as the reference of the motor you are trying to run ?

Best Regards,

Gaël A.

If you agree with my answer, please consider accepting it by clicking on 'Accept as solution'.Hope this will help,Gaël A.
SRedd.5
SRedd.5Author
Senior III
May 12, 2023

Duty Cycle = 10

OL_UpdateVoltage( &OpenLoop_ParamsM1, ((10 * 32767) / 100));

Speed = 100

MCI_ExecSpeedRamp(&Mci[MOTOR_0], (int16_t)((100 * SPEED_UNIT) / U_RPM), 1000);

Duration is 1000.

I am not sure the below is also impacting

OpenLoop_Handle_t OpenLoop_ParamsM1 =

{

 .hDefaultVoltage = OPEN_LOOP_VOLTAGE_d,

 .VFMode      = OPEN_LOOP_VF,

 .hVFOffset    = OPEN_LOOP_OFF,

 .hVFSlope     = OPEN_LOOP_K

};

#define OPEN_LOOP_VOLTAGE_d      2000   /*!< Three Phase voltage amplitude in int16_t format */

#define OPEN_LOOP_VF         false 

I am also checking on the hardware side in parallel. Could you please tell me any other changes i need to check or any signal i can verify to confirm?

I have attached the motor data sheet i have the Battery voltage at 20V.

SRedd.5
SRedd.5Author
Senior III
May 12, 2023

Thank you it runs now after correcting hardware issues, but few concerns is after some rotations for 1 to 2 minutes it gets struck up, sometimes gets problem in starting. Do we have solutions for that?

SRedd.5
SRedd.5Author
Senior III
May 18, 2023

Now I have landed in confusion when you give the last command Mci_execSpeedRamp it does not stay in open loop mode it goes to speed mode, could you please explain me this?​

SRedd.5
SRedd.5Author
Senior III
May 21, 2023

It is my mistake


_legacyfs_online_stmicro_images_0693W00000bkVV0QAM.png