cancel
Showing results for 
Search instead for 
Did you mean: 

STEVAL-IPMNG8Q

Eakso.2
Associate II

Hi, I am student at SAKARYA university. I want to drive PMSM 3-phase motor. So I have STEVAL-IPMNG8Q.

I have STM32F407G discovery board and STEVAL-IPMNG8Q. I want to drive the PMSM motor with my code but I'm having problems.

I'm using six-step control with timer CH1-CH1N pwm.The code I wrote is below.

 int pwmSin[] = {0,18,20,30,40,50,60,70,80,90,80,70,60,50,40,30,20,0,0,18,20,30,40,50,60,70,80,90,80,70,60,50,40,30,20,0,0,18,20,30,40,50,60,70,80,90,80,70};

void motor_control(void) {

///--------- A HIGH- B LOW ---------///

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);

HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2);

///--------- A HIGH- C LOW ---------///

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);

HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_3);

///--------- B HIGH- C LOW ---------///

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);

HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_3);

///--------- B HIGH- A LOW ---------///

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);

HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);

///--------- C HIGH- A LOW ---------///

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3);

HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);

///--------- C HIGH- B LOW ---------///

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3);

HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2);

}

while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

    for( i = 0; i<64;i++){

    __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, pwmSin[i]);

__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, pwmSin[i]+16);

__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, pwmSin[i]+32);

 motor_control();

if(i == 63){

i=0;

}

    }

When I run this code the motor is locked. The motor could not move.

I know I need to generate a sine wave using pwm but something is wrong.

I was able to create a 120 degree angle difference between phases but I am getting a square wave output. I will be grateful if you could help me. I wish you good work.

0 REPLIES 0