Skip to main content
Tejashree
Associate III
October 28, 2021
Solved

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

  • October 28, 2021
  • 4 replies
  • 1266 views

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?

This topic has been closed for replies.
Best answer by cedric H

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

4 replies

cedric H
Technical Moderator
October 28, 2021

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
TejashreeAuthor
Associate III
October 28, 2021

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
TejashreeAuthor
Associate III
October 28, 2021

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
cedric HAnswer
Technical Moderator
October 28, 2021

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