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

📄 pmsm3_4.c

📁 移植TI的永磁同步电机(PMSM)速度闭环调速程序
💻 C
📖 第 1 页 / 共 4 页
字号:
    	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);
    	//pid_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==F2808)
           speed1.ElecTheta = _IQ24toIQ((int32)qep1.ElecTheta);
           speed1.DirectionQep = (int32)(qep1.DirectionQep);
           speed1.calc(&speed1);
        #endif
        #if (DSP_TARGET==F2812)
           speed1.ElecTheta = _IQ15toIQ((int32)qep1.ElecTheta);
           speed1.DirectionQep = (int32)(qep1.DirectionQep);
           speed1.calc(&speed1);
        #endif

        #if 0  // 使用计算机 Motor Monitor 软件观测,不需要   
        //    Connect inputs of the PWMDAC module 
        // ------------------------------------------------------------------------------	
            PwmDacCh1 = (int16)_IQtoIQ15(svgen_dq1.Ta);
            PwmDacCh2 = (int16)_IQtoIQ15(speed1.ElecTheta);    
            PwmDacCh3 = (int16)_IQtoIQ15(clarke1.As);    

        // ------------------------------------------------------------------------------
        //    Connect inputs of the DATALOG module 
        // ------------------------------------------------------------------------------
            DlogCh1 = (int16)_IQtoIQ15(svgen_dq1.Ta);
            DlogCh2 = (int16)_IQtoIQ15(speed1.ElecTheta);
            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
        }
#endif // (BUILDLEVEL==LEVEL5) 


// ***************** LEVEL6 *****************
#if (BUILDLEVEL==LEVEL6)   // 位置闭环

// ------------------------------------------------------------------------------
//    Specify the initial position reference when DC-bus voltage is less than 25%
// ------------------------------------------------------------------------------
    #if (DSP_TARGET==F2808)
      if (_IQ15toIQ((int32)ilg2_vdc1.VdcMeas) < _IQ(0.25))
         PositionRef = _IQtoF(_IQ24toIQ((int32)qep1.ElecTheta));
    #endif
    #if (DSP_TARGET==F2812)
      if (_IQ15toIQ((int32)ilg2_vdc1.VdcMeas) < _IQ(0.25))
         PositionRef = _IQtoF(_IQ15toIQ((int32)qep1.MechTheta));
    #endif

// ------------------------------------------------------------------------------
//    Connect inputs of the RMP_CNTL module and call the Ramp control
//    calculation function.
// ------------------------------------------------------------------------------
      rc1.TargetValue = _IQ(PositionRef);
      rc1.calc(&rc1);

// ------------------------------------------------------------------------------
//    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;
  #if (DSP_TARGET==F2808)
     park1.Angle = _IQ24toIQ((int32)qep1.ElecTheta);
  #endif
  #if (DSP_TARGET==F2812)
     park1.Angle = _IQ15toIQ((int32)qep1.ElecTheta);
  #endif
     park1.calc(&park1);

// ------------------------------------------------------------------------------
//    Connect inputs of the PID_REG3 modules and compute the P position 
//    controller. 
//    Note that this P controller is manually implemented in the main function.
//    It is not from the DMC library. 
// ------------------------------------------------------------------------------  
//   pid1_pos.Ref = _IQ(PositionRef); 
     pid1_pos.Ref = rc1.SetpointValue;
  #if (DSP_TARGET==F2808)
     pid1_pos.Fdb = _IQ24toIQ((int32)qep1.MechTheta);
  #endif
  #if (DSP_TARGET==F2812)
     pid1_pos.Fdb = _IQ15toIQ((int32)qep1.MechTheta);
  #endif
     pid1_pos.calc(&pid1_pos);

// ------------------------------------------------------------------------------
//    Connect inputs of the PID_REG3 module and call the PID IQ controller
//    calculation function.
// ------------------------------------------------------------------------------  
    pid1_iq.Ref = pid1_pos.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);

// ------------------------------------------------------------------------------
//    Call the QEP_DRV calculation function.
// ------------------------------------------------------------------------------
    qep1.calc(&qep1);

// ------------------------------------------------------------------------------
//    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;	
  #if (DSP_TARGET==F2808)
    ipark1.Angle = _IQ24toIQ((int32)qep1.ElecTheta);
  #endif
  #if (DSP_TARGET==F2812)
    ipark1.Angle = _IQ15toIQ((int32)qep1.ElecTheta);
  #endif
    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);
    
// ------------------------------------------------------------------------------
//    Connect inputs of the PWMDAC module 
// ------------------------------------------------------------------------------	
    PwmDacCh1 = (int16)_IQtoIQ15(svgen_dq1.Ta);
  #if (DSP_TARGET==F2808)
    PwmDacCh2 = (int16)_IQtoIQ15(_IQ24toIQ(qep1.ElecTheta));
  #endif
  #if (DSP_TARGET==F2812)
    PwmDacCh2 = qep1.ElecTheta;
  #endif
    PwmDacCh3 = (int16)_IQtoIQ15(clarke1.As);    

// ------------------------------------------------------------------------------
//    Connect inputs of the DATALOG module 
// ------------------------------------------------------------------------------
    DlogCh1 = (int16)_IQtoIQ15(svgen_dq1.Ta);
  #if (DSP_TARGET==F2808)
    DlogCh3 = (int16)_IQtoIQ15(_IQ24toIQ(qep1.ElecTheta));
  #endif
  #if (DSP_TARGET==F2812)
    DlogCh3 = qep1.ElecTheta;
  #endif
    DlogCh3 = (int16)_IQtoIQ15(pid1_pos.Ref);
    DlogCh4 = (int16)_IQtoIQ15(pid1_pos.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==LEVEL6) 

    #if 0  // 使用计算机 Motor Monitor 软件观测,不需要
    //    Call the PWMDAC update function.
    // ------------------------------------------------------------------------------
    	pwmdac1.update(&pwmdac1);  

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

    volt1.DcBusVolt = _IQ(1.0);
    volt1.MfuncV1 = svgen_dq1.Ta;
    volt1.MfuncV2 = svgen_dq1.Tb;
    volt1.MfuncV3 = svgen_dq1.Tc;        
 	volt1.calc(&volt1);

	//lMotorRpmMeas = (float)speed1.SpeedRpm;//_IQtoF(_IQmpy(speed1.Speed, _IQ(200.0)) );//(_IQtoF(speed1.Speed));
	lMotorRpmMeas = _IQtoF(_IQmpy(speed1.Speed, _IQ(200.0)) );//(_IQtoF(speed1.Speed));
	//fIa = (float)(_IQtoF(speed1.Speed));

    fMotorFreq = _IQtoF(rg1.Freq);
	fTheta = _IQtoF(_IQmpy(speed1.ElecTheta, _IQ(100.0)));
    fPWMTu = _IQtoF(_IQmpy(rg1.Out, _IQ(100.0)));
	iq19Vdc  = _IQ19mpy(_IQ19(asOscSamData[ADC_CHAN_DC_VOL_INDEX]), _IQ19(FLOAT_FACTOR_DC_VOL));
    fVa    = _IQ19toF(_IQ19mpy(_IQtoIQ19(volt1.VphaseA), iq19Vdc)); 
    fVb    = _IQ19toF(_IQ19mpy(_IQtoIQ19(volt1.VphaseB), iq19Vdc));
    fVc    = _IQ19toF(_IQ19mpy(_IQtoIQ19(volt1.VphaseC), iq19Vdc));
    fIa    = _IQ19toF(iq19Iu);
    fIb    = _IQ19toF(iq19Iv);
    fIc    = _IQ19toF(iq19Iw);
    fVds   = _IQtoF(_IQmpy(ipark1.Ds, _IQ(1)));
    fVqs   = _IQtoF(_IQmpy(ipark1.Qs, _IQ(1)));
    //fPWMTu = _IQ19toF(_IQ19mpy(_IQtoIQ19(svgen_dq1.Ta), _IQ19(100.0)));
    fPWMTv = _IQ19toF(_IQ19mpy(_IQtoIQ19(svgen_dq1.Tb), _IQ19(100.0)));
    fPWMTw = _IQ19toF(_IQ19mpy(_IQtoIQ19(svgen_dq1.Tc), _IQ19(100.0)));
    MONITOR_THETA(fTheta);
    MONITOR_VDS(fVds);
    MONITOR_VQS(fVqs);
    MONITOR_PWMTU(fPWMTu);
    MONITOR_PWMTV(fPWMTv);
    MONITOR_PWMTW(fPWMTw);

    
#if (DSP_TARGET==F2808)
// Enable more interrupts from this timer
	EPwm1Regs.ETCLR.bit.INT = 1;

// Acknowledge interrupt to recieve more interrupts from PIE group 3
	PieCtrl.PIEACK.all = PIEACK_GROUP3;
#endif


#if (DSP_TARGET==F2812)
// Enable more interrupts from this timer
	EvaRegs.EVAIMRA.bit.T1UFINT = 1;
	
// 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;
	
// Acknowledge interrupt to recieve more interrupts from PIE group 2
	PieCtrl.PIEACK.all |= PIEACK_GROUP2;
#endif

    if (200 == IsrTicker) BEEP_Off();

}


#if (DSP_TARGET==F2812)
interrupt void QepISR(void)
{
    if(PMSM_OPEN_LOOP ==bMode)
    {
        ucIndexCount ++;
        if (5 <ucIndexCount) 
        {
            bMode = PMSM_CLOSE_LOOP;
        }
    }

// ------------------------------------------------------------------------------
//    Call the QEP_DRV isr function.
// ------------------------------------------------------------------------------
   qep1.isr(&qep1);

// Enable more interrupts from this timer
	EvaRegs.EVAIMRC.bit.CAP3INT = 1;
	
// Note: To be safe, use a mask value to write to the entire
	// EVAIFRC 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.EVAIFRC.all = BIT2;
	
// Acknowledge interrupt to recieve more interrupts from PIE group 3
	PieCtrl.PIEACK.all |= PIEACK_GROUP3;
  
}
#endif

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

⌨️ 快捷键说明

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