⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 int_vhz_wx.c

📁 f2407:电机控制
💻 C
字号:
/*--------------------------------------------------------------------------------
Interrupt subroutine for VHz controller
--------------------------------------------------------------------------------*/
void interrupt pdpint(void)
{	
  switch(*PIVR)
  case 0x19:							//PDPINTB interrupt vector
	{	
	  *EVBIFRA=*EVBIFRA|0x1;			//clearing interrupt flag 
	  ipmfault=1;

	  break;
	}  
} 

void interrupt vhzserve(void)
{	int temp;
	switch(*PIVR)
	{	case 0x31:							//TMR3 underflow
		{	*EVBIFRA=*EVBIFRA|0x200;		//clear the interrupt flag													//clearing interrupt flag
			soft_timer.timer=soft_timer.timer+1;  
			soft_timer.key_timer=soft_timer.key_timer+1;
			/////////////////////////////////2005-10-21/////////////
			temp=*T3CNT;
			while((*ADCTRL2&0x02)==0)                       //如果SEQ2没有发生中断事件
			{	if((*T3CNT-temp)>0x0F0)						//if ADC sample is not complete in 10us, break				
					break;
				else
					continue;          						//waits for AD conversion
			}
			*ADCTRL2=*ADCTRL2|0x02;     					//clears AD interrupt flag 
			*ADCTRL2=*ADCTRL2|0x40;							//reset SEQ2
			/////////////////////////////////////////////////////
			
		    if(flagflag==1)                             //启动电机
			{	
			  if((soft_timer.timer-soft_timer.speed_timer)>=speed_period)
														//speed loop calculation
			  {	temp=*T4CNT;							//read T4CNT
					*T4CNT=0;                          	//clearing T4CNT 
			//		speed=qep(temp);                   	//motor speed scaling 
					soft_timer.speed_timer=soft_timer.timer;
					flagspeedchang=1;  //  刘和平:
            	}    
				freq_theta(&freq_theta_out, freq_ref_out.freq_ref);     //获得PWM调制时每一补的角度增量
				volt_freq(&vhz_volt_out, freq_ref_out.freq_ref);
				sin_cos(&sincos_out, freq_theta_out.theta);
				polar_rectangular(&polar_rect_out, vhz_volt_out.uout, sincos_out.cosx, sincos_out.sinx);
 			
				soft_svpwm(&svpwm_out, polar_rect_out.ualfa, polar_rect_out.ubeta); //calculate the duty ratio base on ualfa and ubeta
				*CMPR4=svpwm_out.va;   						
				*CMPR5=svpwm_out.vb;
				*CMPR6=svpwm_out.vc;
  							
			}
			else
			{  	*T4CNT=0;
			    *CMPR4=0;
				*CMPR5=0;
				*CMPR6=0; 
				soft_timer.speed_timer=soft_timer.timer;
			}
			break;
		}
	}
}


void interrupt phantom(void)
{	           
  //	*COMCONB=*COMCONB&0xFDFF;	//put the pwm output into high impedance state		
  //	*CMPR4=0;					//clear the compara register
  //	*CMPR5=0;  
  //	*CMPR6=0;
}    
	 
    
 


				
				
				
				
				
				

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -