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

📄 aci3_3.c

📁 F2812感应电机矢量控制程序
💻 C
📖 第 1 页 / 共 2 页
字号:
//    speed1.InputSelect = 0;
// 	speed1.BaseRpm = 120*BASE_FREQ/P;//因为P为极数,不是极对数
// 	speed1.SpeedScaler = 60*(SYSTEM_FREQUENCY*1000000/1000)*1/(128*speed1.BaseRpm);
// #endif

// Initialize RAMPGEN module
    rg1.StepAngleMax = _IQ(BASE_FREQ*T);
 
// Initialize the CUR_MOD constant module     
//	cm1_const.Rr = RR;
//	cm1_const.Lr = LR;
//	cm1_const.fb = BASE_FREQ;
//	cm1_const.Ts = T;
//	cm1_const.calc(&cm1_const);      

// Initialize the CUR_MOD module
// 	cm1.Kr = _IQ(cm1_const.Kr);
// 	cm1.Kt = _IQ(cm1_const.Kt);
// 	cm1.K = _IQ(cm1_const.K);

// Initialize the PID_REG3 module for Id
	pid1_id.Kp = _IQ(0.9463);  
	pid1_id.Ki = _IQ(T/0.04);	
	pid1_id.Kd = _IQ(0/T); 						
	pid1_id.Kc = _IQ(0.2);
    pid1_id.OutMax = _IQ(0.30);
    pid1_id.OutMin = _IQ(-0.30);    
 
// Initialize the PID_REG3 module for Iq
	pid1_iq.Kp = _IQ(0.9463);
	pid1_iq.Ki = _IQ(T/0.04);		
	pid1_iq.Kd = _IQ(0/T); 				
	pid1_iq.Kc = _IQ(0.2);
    pid1_iq.OutMax = _IQ(0.95);
    pid1_iq.OutMin = _IQ(-0.95);    

// Initialize the PID_REG3 module for speed
    pid1_spd.Kp = _IQ(1);                  
	pid1_spd.Ki = _IQ(T*SpeedLoopPrescaler/0.2);			
	pid1_spd.Kd = _IQ(0/(T*SpeedLoopPrescaler));					
 	pid1_spd.Kc = _IQ(0.2);
    pid1_spd.OutMax = _IQ(1);
    pid1_spd.OutMin = _IQ(-1); 

// Enable global Interrupts and higher priority real-time debug events:	
	EINT;   // Enable Global interrupt INTM
	ERTM;	// Enable Global realtime interrupt DBGM

// IDLE loop. Just sit and loop forever:	

	
	
}


interrupt void MainISR(void)
{

// Verifying the ISR
    IsrTicker++;


// ***************** LEVEL5 ***************** 
#if (BUILDLEVEL==LEVEL5)

// ------------------------------------------------------------------------------
//    Call the ILEG2_VDC read function.
// ------------------------------------------------------------------------------
    ilg2_vdc1.read(&ilg2_vdc1);

// ------------------------------------------------------------------------------
//    Connect inputs of the CLARKE module and call the clarke transformation
//    calculation function.
// ------------------------------------------------------------------------------
 	clarke1.As = _IQ15toIQ((int32)ilg2_vdc1.ImeasA);
  	clarke1.Bs = _IQ15toIQ((int32)ilg2_vdc1.ImeasB);
	clarke1.calc(&clarke1);

// ------------------------------------------------------------------------------
//    Connect inputs of the PARK module and call the park transformation
//    calculation function.
// ------------------------------------------------------------------------------
    park1.Alpha = clarke1.Alpha;
    park1.Beta = clarke1.Beta;
    park1.Angle = speed1.ElecTheta;
    park1.calc(&park1);

// ------------------------------------------------------------------------------
//    Connect inputs of the PID_REG3 module and call the PID speed controller
//    calculation function.
// ------------------------------------------------------------------------------  
    if (SpeedLoopCount==SpeedLoopPrescaler)
     {
      pid1_spd.Ref = _IQ(SpeedRef);
      pid1_spd.Fdb = speed1.Speed;
	  pid1_spd.calc(&pid1_spd);
      SpeedLoopCount=1;
     }
    else SpeedLoopCount++; 

// ------------------------------------------------------------------------------
//    Connect inputs of the PID_REG3 module and call the PID IQ controller
//    calculation function.
// ------------------------------------------------------------------------------  
    pid1_iq.Ref = pid1_spd.Out;
	pid1_iq.Fdb = park1.Qs;
	pid1_iq.calc(&pid1_iq);

// ------------------------------------------------------------------------------
//    Connect inputs of the PID_REG3 module and call the PID ID controller
//    calculation function.
// ------------------------------------------------------------------------------  
    pid1_id.Ref = _IQ(IdRef);
	pid1_id.Fdb = park1.Ds;
	pid1_id.calc(&pid1_id);

// ------------------------------------------------------------------------------
//    Connect inputs of the INV_PARK module and call the inverse park transformation
//    calculation function.
// ------------------------------------------------------------------------------
    ipark1.Ds = pid1_id.Out;
    ipark1.Qs = pid1_iq.Out;
    ipark1.Angle = speed1.ElecTheta;
    ipark1.calc(&ipark1);

// ------------------------------------------------------------------------------
//    Connect inputs of the SVGEN_DQ module and call the space-vector gen.
//    calculation function.
// ------------------------------------------------------------------------------
  	svgen_dq1.Ualpha = ipark1.Alpha;
 	svgen_dq1.Ubeta = ipark1.Beta;
  	svgen_dq1.calc(&svgen_dq1);	

// ------------------------------------------------------------------------------
//    Connect inputs of the PWM_DRV module and call the PWM signal generation 
//    update function.
// ------------------------------------------------------------------------------
    pwm1.MfuncC1 = (int16)_IQtoIQ15(svgen_dq1.Ta); // MfuncC1 is in Q15
    pwm1.MfuncC2 = (int16)_IQtoIQ15(svgen_dq1.Tb); // MfuncC2 is in Q15  
    pwm1.MfuncC3 = (int16)_IQtoIQ15(svgen_dq1.Tc); // MfuncC3 is in Q15
	pwm1.update(&pwm1);
	
// ------------------------------------------------------------------------------
//    Call the QEP calculation function 
// ------------------------------------------------------------------------------
    qep1.calc(&qep1);
    
    
// ------------------------------------------------------------------------------
//    Connect inputs of the SPEED_FR module and call the speed calculation function 
// ------------------------------------------------------------------------------

#if (DSP_TARGET==F2812)
       speed1.ElecTheta = _IQ15toIQ((int32)qep1.ElecTheta);
       speed1.DirectionQep = (int32)(qep1.DirectionQep);
       speed1.calc(&speed1);
#endif

// ------------------------------------------------------------------------------
//    Connect inputs of the CUR_MOD module and call the current model
//    calculation function.
// ------------------------------------------------------------------------------
//    cm1.IDs = park1.Ds;
//    cm1.IQs = park1.Qs;
//	  cm1.Wr = speed1.Speed;
//	  cm1.calc(&cm1);    

// ------------------------------------------------------------------------------
//    Connect inputs of the PWMDAC module 
// ------------------------------------------------------------------------------	
//    PwmDacCh1 = (int16)_IQtoIQ15(svgen_dq1.Ta);
//    PwmDacCh2 = (int16)_IQtoIQ15(clarke1.As);    
//    PwmDacCh3 = (int16)_IQtoIQ15(cm1.Theta);    

// ------------------------------------------------------------------------------
//    Connect inputs of the DATALOG module 
// ------------------------------------------------------------------------------
//    DlogCh1 = (int16)_IQtoIQ15(svgen_dq1.Ta);
//    DlogCh2 = (int16)_IQtoIQ15(cm1.Theta);
//    DlogCh3 = (int16)_IQtoIQ15(pid1_spd.Ref);
//    DlogCh4 = (int16)_IQtoIQ15(pid1_spd.Fdb);

// ------------------------------------------------------------------------------
//    Connect inputs of the EN_DRV module and call the enable/disable PWM signal
//    update function. (FOR DMC1500 ONLY)
// ------------------------------------------------------------------------------ 
//    drv1.EnableFlag = EnableFlag;
//    drv1.update(&drv1);
    
#endif // (BUILDLEVEL==LEVEL5)


// ------------------------------------------------------------------------------
//    Call the PWMDAC update function.
// ------------------------------------------------------------------------------
//	pwmdac1.update(&pwmdac1);  

// ------------------------------------------------------------------------------
//    Call the DATALOG update function.
// ------------------------------------------------------------------------------
//    dlog.update(&dlog);

#if (DSP_TARGET==F2812)
// Enable more interrupts from this timer
	EvaRegs.EVAIMRA.bit.T1UFINT = 1;//屏蔽寄存器设置,使能T1UFINT

// Note: To be safe, use a mask value to write to the entire
	// EVAIFRA register.  Writing to one bit will cause a read-modify-write
	// operation that may have the result of writing 1's to clear 
	// bits other then those intended. 
    EvaRegs.EVAIFRA.all = BIT9;//标志寄存器设置:通用定时器1下溢中断复位标志

// Acknowledge interrupt to recieve more interrupts from PIE group 2
	PieCtrlRegs.PIEACK.all = PIEACK_GROUP2;
#endif

}

//===========================================================================
// No more.
//===========================================================================

⌨️ 快捷键说明

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