cancel
Showing results for 
Search instead for 
Did you mean: 

I want to use Example from MC WB for BEC-STM32G431CB.How define user code?

Tejashree
Associate III

I used motor profiler .Saved the paramters and then while using the examples Imported those paramters.I used following as user code in main.c in while(1):

 if( MCI_GetSTMState() == RUN )

{

  MCI_ExecSpeedRamp(MCI_EXECSPEEDRAMP,1000,2000);

 MCI_StartMotor(MCI_EXECSPEEDRAMP);

}

else;

MCI_StopMotor()

How to start motor with user code in example from MC WB?

1 ACCEPTED SOLUTION

Accepted Solutions
cedric H
ST Employee

Ok, So you want to start your motor at power on and stop it after 5 seconds.

Use the API provided in mc_api.h as shown in the exemple below (in your main.c) :

 /* USER CODE BEGIN 2 */

MC_ProgramSpeedRampMotor1( (int16_t) (1000/6), 10 ); /* Apply a ramp to reach 1000 RPM in 10 ms - 1000 RPM = 1000/6 0.1 Hz */

MC_StopMotor1(void);

  HAL_Delay(5000); /* wait for 5 seconds*/

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

Regards

Cedric

View solution in original post

4 REPLIES 4
cedric H
ST Employee

Hello @Tejashree​ 

I am not sure I understand what do you want to do.

Could you describe on which events do you want to start and stop your motor.

Regards

Cedric

Tejashree
Associate III

i just imported the example with parameters from motor profiler.Now i just want to run the motor with user code.Example:Run motor at 1000rpm for 5sec

Tejashree
Associate III

I am not able understand the motor_interface.h file properly to use the functions.Can you suggest me how can i run the motor by defining user code?

cedric H
ST Employee

Ok, So you want to start your motor at power on and stop it after 5 seconds.

Use the API provided in mc_api.h as shown in the exemple below (in your main.c) :

 /* USER CODE BEGIN 2 */

MC_ProgramSpeedRampMotor1( (int16_t) (1000/6), 10 ); /* Apply a ramp to reach 1000 RPM in 10 ms - 1000 RPM = 1000/6 0.1 Hz */

MC_StopMotor1(void);

  HAL_Delay(5000); /* wait for 5 seconds*/

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

Regards

Cedric