当前位置:网站首页>STM32 sensorless brushless motor drive

STM32 sensorless brushless motor drive

2022-06-13 01:58:00 richardgann

Preface :

stm32 How to control the induction less brushless motor ?

         First of all, we need to know the working principle of brushless motor , So that we can meet the actual needs , Yes stm32 Make point-to-point calls to internal resources , So as to program .

I believe we can find this Blog All students have a general understanding of brushless motor , But the specific use details and principles , It may not be clear .

         Here I will explain to you some key points in writing programs , When the brushless motor control is clear , So I can understand how to write the program .

The hardware uses KY_Motor Development board . 

link :https://item.taobao.com/item.htm?spm=a1z10.1-c-s.w4004-18361242577.2.110f294eEKyjHQ&id=602257529707

The important part of brushless motor control is commutation , The most important knowledge point of sensorless brushless is zero point detection .

1、 Motor commutation and zero point detection .

         The main content of sensorless brushless motor control is to detect the zero crossing point of the induced electromotive force of the suspended phase , When the analog comparator sends
When an interrupt is generated, it indicates that a zero crossing event is generated , Then prepare for commutation .
        because stm32f103 The series has no built-in comparator , Therefore, the peripheral circuit adopts LM358 As a comparator , In addition to using comparator, zero point detection can also be realized by using interrupt , Interested friends can try to change .

Zero detection circuit

//PA5  Pin interrupt , Calculate commutation time 
void EXTI9_5_IRQHandler(void)			
{    
	Zero=GPIO_ReadInputData(GPIOA);
	Zero=Zero&0x0038; 
	Zero=Zero>>3;// Zero crossing signal ,513264

	if(!Direction)Zero=7-Zero;

	Zero_SW();
	counter1++;

		if(EXTI_GetITStatus(EXTI_Line5)!= RESET)
	{
		EXTI_ClearITPendingBit(EXTI_Line5);
	}
}

Here through the test U、V、W Which three-phase circuit is connected , Then, the comparator is used to determine which circuit is on .

        Explain here zero = zero & 0x0038  What does that mean? , In terms of hardware, we adopt PA3、PA4、PA5 Three pins are used as zero detection pins ,0x0038 The binary of is  xx 0011 1000, That is to say PA3、PA4、PA5 And 111 Meet each other , Then we can get the value of which circuit is turned on .

      then zero The value of is shifted to the right 3 position , The zero crossing signal can be obtained 513264, take 513264 It is also correspondingly converted into binary numbers , You will understand how to obtain the value of the zero crossing signal .

      In the program, we are divided into PA3、PA4、PA5 Three pins are used for interrupt processing , The procedures are the same , But the short and medium term is different , Let's change the procedure by ourselves .

       After obtaining the zero crossing signal, we need to use the obtained signal for motor commutation , This is the classic six arm full bridge drive circuit .

Two of them are connected , Implementation method we implement it by the following methods .

// Zero crossing commutation function 
void Zero_SW(void)   
{ 
	switch(Zero)
	{
			case 5:    
		   TIM1->CCR2=0;             //AB
		   TIM1->CCR1 = My_PWM;					  
       TIM1->CCR3=0;
			
		   GPIO_ResetBits(GPIOB, GPIO_Pin_13 | GPIO_Pin_15); 
		   GPIO_SetBits(GPIOB, GPIO_Pin_14);   
			break;
		case 1:
       TIM1->CCR2=0;              //AC
		   TIM1->CCR1 = My_PWM;					  
       TIM1->CCR3=0;

		   GPIO_ResetBits(GPIOB, GPIO_Pin_13 | GPIO_Pin_14); 
		   GPIO_SetBits(GPIOB, GPIO_Pin_15);  
			break;
		case 3:
		  TIM1->CCR1=0;          //BC
		  TIM1->CCR2 = My_PWM;					  
      TIM1->CCR3=0;
	
		   GPIO_ResetBits(GPIOB, GPIO_Pin_13 | GPIO_Pin_14); 
		   GPIO_SetBits(GPIOB, GPIO_Pin_15);     
			break;

		case 2:
		
	     TIM1->CCR1=0;        //BA
		   TIM1->CCR2 = My_PWM;					  
       TIM1->CCR3=0;
	
		   GPIO_ResetBits(GPIOB, GPIO_Pin_14 | GPIO_Pin_15); 
		   GPIO_SetBits(GPIOB, GPIO_Pin_13);     
			break;

		case 6:
		
		   TIM1->CCR2=0;//CA
	     TIM1->CCR3 = My_PWM;					  
       TIM1->CCR1=0;

		   GPIO_ResetBits(GPIOB, GPIO_Pin_14 | GPIO_Pin_15); 
		   GPIO_SetBits(GPIOB, GPIO_Pin_13);          
			break;

		case 4:
		
	     TIM1->CCR2=0; //CB
		   TIM1->CCR3 = My_PWM;					  
       TIM1->CCR1=0;

		   GPIO_ResetBits(GPIOB, GPIO_Pin_13 | GPIO_Pin_15); 
		   GPIO_SetBits(GPIOB, GPIO_Pin_14);   
			break;
		
		default:

		break;
	}
}

          This program is easy to understand , Don't explain too much .

========================================================================

Here we are , The more important two parts of the program of the sensorless brushless motor drive are explained . Let's next look at the startup function .

// Start the function 
void START_UP(void)
{
	switch(phase)
	{
			case 1:    
		   TIM1->CCR2=0;             //AB
		   TIM1->CCR1 = My_PWM;					  
       TIM1->CCR3=0;
			
		   GPIO_ResetBits(GPIOB, GPIO_Pin_13 | GPIO_Pin_15); 
		   GPIO_SetBits(GPIOB, GPIO_Pin_14);   
			break;
		case 2:
       TIM1->CCR2=0;              //AC
		   TIM1->CCR1 = My_PWM;					  
       TIM1->CCR3=0;

		   GPIO_ResetBits(GPIOB, GPIO_Pin_13 | GPIO_Pin_14); 
		   GPIO_SetBits(GPIOB, GPIO_Pin_15);  
			break;
		case 3:
		  TIM1->CCR1=0;          //BC
		  TIM1->CCR2 = My_PWM;					  
      TIM1->CCR3=0;
	
		   GPIO_ResetBits(GPIOB, GPIO_Pin_13 | GPIO_Pin_14); 
		   GPIO_SetBits(GPIOB, GPIO_Pin_15);     
			break;

		case 4:
		
	     TIM1->CCR1=0;        //BA
		   TIM1->CCR2 = My_PWM;					  
       TIM1->CCR3=0;
	
		   GPIO_ResetBits(GPIOB, GPIO_Pin_14 | GPIO_Pin_15); 
		   GPIO_SetBits(GPIOB, GPIO_Pin_13);     
			break;

		case 5:
		
		   TIM1->CCR2=0;//CA
	     TIM1->CCR3 = My_PWM;					  
       TIM1->CCR1=0;

		   GPIO_ResetBits(GPIOB, GPIO_Pin_14 | GPIO_Pin_15); 
		   GPIO_SetBits(GPIOB, GPIO_Pin_13);          
			break;

		case 6:
		
	     TIM1->CCR2=0; //CB
		   TIM1->CCR3 = My_PWM;					  
       TIM1->CCR1=0;

		   GPIO_ResetBits(GPIOB, GPIO_Pin_13 | GPIO_Pin_15); 
		   GPIO_SetBits(GPIOB, GPIO_Pin_14);   
			break;
		
		default:

		break;
	}
}

         Careful students will find out , The starting function is the same as the zero commutation function .

         Because the program cannot judge which point is at zero point when the motor is started , Therefore, it is necessary to turn on the motor first , After conduction , A reverse electromotive force is generated , It can also collect the zero point signal , So we know which way is open .

The user interface program added to the program is not listed here , This program controls the motor start and acceleration and deceleration control by pressing the key , Another important thing is , With the same procedure, different motors may not start smoothly , You know why ?

More interesting content, please pay attention to WeChat official account : Guangyi electronics (dlrcclub).

原网站

版权声明
本文为[richardgann]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280548346531.html