cancel
Showing results for 
Search instead for 
Did you mean: 

problem in STM32Cubeide

StanPeeters
Associate II

Hello,

Im new to this and im stuck on 2 things i generated a code from the motorcontrol workbench and im using a Nucleo 64 f030R8 with a IHM07M1A BLDC Motor controller. i can start the motor and control speed. 

1st question : where can i change direction because the motor is rotating always the same direction CCW and i also want the motor to turn CW.

2nd question : i needed to insert the motor parameters in the workbench but cant find these back in the IDE software maybe someone knows where to find this.

Thank you in advance for your assistance. I look forward to receiving your response.

1 ACCEPTED SOLUTION

Accepted Solutions

One mistake i found is uint16_t speed = -1000; this is unsigned value and you are assigning negative value. 

You can modify the code as below 

if (MC_GetImposedDirectionMotor1 == 1)

{

MC_StopMotor1();

HAL_Delay(500);

output_speed = RPM_2_SPEED_UNIT(1000);

}

else if (MC_GetImposedDirectionMotor1 == -1){

MC_StopMotor1();

HAL_Delay(500);

output_speed = RPM_2_SPEED_UNIT(-1000);

}

MC_ProgramSpeedRampMotor1(output_speed, 100);

you have to ensure the value of output_speed will be positive in one direction and negative in other direction.

 

 

 

View solution in original post

5 REPLIES 5
Gael A
ST Employee

Hello StanPeeters,

You can change motor direction by using the MC_ProgramSpeedRampMotor1(int16_t hFinalSpeed, uint16_t hDurationms) function located in mc_api.c. You just need to enter a negative speed. However be aware that changing motor direction in sensorless cannot be done while running : you need to stop your motor first.
Moreover, have you checked the MotorPilot tool provided with the MCSDK package ? It allows you to manually set speed through its GUI as well as many other parameters.

Concerning the motor parameters, they are located in the pmsm_motor_parameters.h file. As it is a header file, it may be the reason you have trouble finding it. In CubeIDE, when looking at your Project Explorer, go to Includes -> C:/PROJECT_PATH/Inc to find it.

If you agree with my answer, please consider accepting it by clicking on 'Accept as solution'.

Hope this will help,
Gaël A.

However be aware that changing motor direction in sensorless cannot be done while running : you need to stop your motor first.

Just a small clarification if this is mandatory, can it be handled as part of the API itself without the user taking care of it?

I already have this in my code but even when im starting the program the motor does not turn the other direction.

 

this is my code :

while (1)

{

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

// Lees de knoppen en potentiometer

uint8_t startStopButton = HAL_GPIO_ReadPin(Start_Stop_GPIO_Port, GPIO_PIN_13);

uint8_t brakeButton = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_14);

//uint8_t directionButton = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_15);

//uint8_t Hall_sensor1 = HAL_GPIO_ReadPin(Hall_sensor1_GPIO_Port, GPIO_PIN_15);

//uint8_t Hall_sensor2 = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_3);

//uint8_t Hall_sensor3 = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_10);

//uint16_t speed = HAL_ADC_GetValue(&hadc); // ADC-waarde van potentiometer op PB7

uint16_t speed = -1000;

output_speed = RPM_2_SPEED_UNIT(speed);

 

//MC_ProgramSpeedRampMotor1(output_speed, 1000); // Pas de 100 ms aan op basis van je vereisten

//HAL_UART_Transmit(&huart2, (uint8_t*)brakeButton, strlen(brakeButton), HAL_MAX_DELAY);

 

 

// Voer acties uit op basis van knoppen

if (startStopButton == GPIO_PIN_RESET) {

// Start/Stop-knop is ingedrukt

if (MC_GetSTMStateMotor1() == RUN) {

MC_StopMotor1(); // Stop de motor als deze al draait

} else {

MC_StartMotor1(); // Start de motor als deze niet draait

}

}

 

/*if (brakeButton == GPIO_PIN_RESET) {

// Remknop is ingedrukt

MC_StopMotor1(); // Stop de motor

HAL_Delay(500);

}*/

 

if (/*directionButton*/brakeButton == GPIO_PIN_RESET) {

// Richtingknop is ingedrukt

// Implementeer logica om de richting van de motor te wijzigen.

// Dit kan variëren op basis van de specifieke API van jouw motorcontroller.

//MC_StopMotor1();

//HAL_Delay(500);

if (MC_GetImposedDirectionMotor1 == 1){

MC_StopMotor1();

HAL_Delay(500);

SetDirection(-1);

 

}

else if (MC_GetImposedDirectionMotor1 == -1){

MC_StopMotor1();

HAL_Delay(500);

SetDirection(1);

}

}

 

// Pas de motorsnelheid aan op basis van de potentiometerwaarde (speed)

MC_ProgramSpeedRampMotor1(output_speed, 100); // Pas de 100 ms aan op basis van je vereisten

//HAL_UART_Transmit(&huart2, (uint8_t*)&speed, sizeof(speed), HAL_MAX_DELAY);

// Voeg een kleine vertraging toe om de knoppen te debouncen.

HAL_Delay(100);

}

 

maybe you can point where it goes wrong.

 

Thank you in advance for your assistance.

One mistake i found is uint16_t speed = -1000; this is unsigned value and you are assigning negative value. 

You can modify the code as below 

if (MC_GetImposedDirectionMotor1 == 1)

{

MC_StopMotor1();

HAL_Delay(500);

output_speed = RPM_2_SPEED_UNIT(1000);

}

else if (MC_GetImposedDirectionMotor1 == -1){

MC_StopMotor1();

HAL_Delay(500);

output_speed = RPM_2_SPEED_UNIT(-1000);

}

MC_ProgramSpeedRampMotor1(output_speed, 100);

you have to ensure the value of output_speed will be positive in one direction and negative in other direction.

 

 

 

Thx for the help and obviously Uint is always positive i read over it. so i apreciate the help and I can continue my work thanks.

 

with kind regards, 

Stan