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

📄 pmsm32.c

📁 本程序来自TI公司网站原程序,其功能是通过传统的矢量控制算法来实现对永磁同步电机的控制,矢量控制采用双闭环结构
💻 C
📖 第 1 页 / 共 4 页
字号:
/*-----------------------------------------------------------------------------
    Initialize the SFOC_TI object. This is a call to the init method within 
    the SFOC_TI object sfoc.
-----------------------------------------------------------------------------*/
        SFOC_TI_Init(&sfoc);

/*-----------------------------------------------------------------------------
    Initialize the real time monitor
-----------------------------------------------------------------------------*/
        rtmon_init();            /* Call the monitor init function           */
        enable_ints();           /* Set off the system running.              */

/*-----------------------------------------------------------------------------
    Initialize DRIVE  --  Waiting for PWM enable flag setting 
-----------------------------------------------------------------------------*/
        while(drive.enable_flg==0)
        {
        drive.init(&drive);
        }
 
/*-----------------------------------------------------------------------------
    Initialize PWM Generator
-----------------------------------------------------------------------------*/
        pwm.init(&pwm);          

/*-----------------------------------------------------------------------------
    Initialize the Quadrature Encoder Interface Driver.
------------------------------------------------------------------------------*/      
        qep.init(&qep);     

/*-----------------------------------------------------------------------------
    Initialize parameters of the speed calculation based on angle
-----------------------------------------------------------------------------*/
/* fb = 200 Hz */
        speed.K1_fr = 4800;  
        speed.K2_fr = 32361;
        speed.K3_fr = 407;
        speed.rpm_max = 6000;

/*-----------------------------------------------------------------------------
    Initialize ILEG2VDCMEAS
-----------------------------------------------------------------------------*/
       	ilg2_vdc.init(&ilg2_vdc);

/*-----------------------------------------------------------------------------
    Set the dac pointers
-----------------------------------------------------------------------------*/
        dac.qptr0=&ilg2_vdc.Imeas_a;
        dac.qptr1=&sfoc.svgen.vb;
        dac.qptr2=&sfoc.smo.thetae;
        dac.qptr3=&sfoc.svgen.vc;

#endif /* (BUILDLEVEL==LEVEL7) */  


#if     TARGET==F243                      
        EVIFRA=0x0ffff;           /* Clear all Group A EV interrupt flags    */

#elif   TARGET==F2407                                                          
        EVAIFRA=0x0ffff;          /* Clear all EV1 Group A EV interrupt flags*/
#endif              


/*---------------------------------------------------------------------------*/
        while(1)             /* Nothing running in the background at present */
        { 
        
        }
/*---------------------------------------------------------------------------*/

} /* End: main() */

 
void interrupt c_int02()
{       
     asm("      CLRC     XF ");
     
     isr_ticker++;    

#if (BUILDLEVEL==LEVEL1)
/*---------------------------------------------------------------------------*/
#if     TARGET==F243                      
        EVIFRA=0x0ffff;           /* Clear all Group A EV interrupt flags    */

#elif   TARGET==F2407                                                          
        EVAIFRA=0x0ffff;          /* Clear all EV1 Group A EV interrupt flags*/
#endif              

/*------------------------------------------------------------------------------
    Call the enable/disable PWM signal drive function.
------------------------------------------------------------------------------*/
        drive.calc(&drive);

/*------------------------------------------------------------------------------
    Call the SFOC_TI_Run function to perform the runtime tasks of the 
    SFOC_TI algorithm.
------------------------------------------------------------------------------*/
        SFOC_TI_Run(&sfoc); 

/*------------------------------------------------------------------------------
    Connect output of the SFOC.SVGEN to the PWM Driver and call the PWM driver 
    update function.
------------------------------------------------------------------------------*/
        pwm.mfunc_c1 = sfoc.svgen.va;         
        pwm.mfunc_c2 = sfoc.svgen.vb;
        pwm.mfunc_c3 = sfoc.svgen.vc;
        pwm.update(&pwm);

/*------------------------------------------------------------------------------
    Call the diagnostic DAC utility update function.
------------------------------------------------------------------------------*/
        dac.update(&dac);

/*----------------------------------------------------------------------------*/
#endif /* BUILDLEVEL==LEVEL1 */


#if (BUILDLEVEL==LEVEL2)
/*---------------------------------------------------------------------------*/
#if     TARGET==F243                      
        EVIFRA=0x0ffff;           /* Clear all Group A EV interrupt flags    */

#elif   TARGET==F2407                                                          
        EVAIFRA=0x0ffff;          /* Clear all EV1 Group A EV interrupt flags*/
#endif              

/*------------------------------------------------------------------------------
    Call the enable/disable PWM drive function.
------------------------------------------------------------------------------*/
        drive.calc(&drive);

/*------------------------------------------------------------------------------
    Call the SFOC_TI_Run function to perform the runtime tasks of the 
    SFOC_TI algorithm.
------------------------------------------------------------------------------*/
        SFOC_TI_Run(&sfoc); 

/*------------------------------------------------------------------------------
    Connect output of the SFOC.SVGEN to the PWM Driver and call the PWM driver 
    update function.
------------------------------------------------------------------------------*/
        pwm.mfunc_c1 = sfoc.svgen.va;         
        pwm.mfunc_c2 = sfoc.svgen.vb;
        pwm.mfunc_c3 = sfoc.svgen.vc;
        pwm.update(&pwm);

/*------------------------------------------------------------------------------
    Call the ileg2_dcbus_drv function to perform the ADC tasks for 2 currents and 
    DC-bus measurement.     
------------------------------------------------------------------------------*/
        ilg2_vdc.read(&ilg2_vdc);

/*------------------------------------------------------------------------------
    Connect outputs of the ILEG2VDCMEAS to SFOC   
------------------------------------------------------------------------------*/
	  	sfoc.current_abc.a = ilg2_vdc.Imeas_a;
	  	sfoc.current_abc.b = ilg2_vdc.Imeas_b;
	  	sfoc.current_abc.c = ilg2_vdc.Imeas_c;        
        sfoc.Vbus = ilg2_vdc.Vdc_meas;

/*------------------------------------------------------------------------------
    Call the diagnostic DAC utility update function.
------------------------------------------------------------------------------*/
        dac.update(&dac);

/*----------------------------------------------------------------------------*/
#endif /* BUILDLEVEL==LEVEL2 */


#if (BUILDLEVEL==LEVEL3)
/*---------------------------------------------------------------------------*/
#if     TARGET==F243                      
        EVIFRA=0x0ffff;           /* Clear all Group A EV interrupt flags    */

#elif   TARGET==F2407                                                          
        EVAIFRA=0x0ffff;          /* Clear all EV1 Group A EV interrupt flags*/
#endif              

/*------------------------------------------------------------------------------
    Call the enable/disable PWM signal drive function.
------------------------------------------------------------------------------*/
        drive.calc(&drive);

/*------------------------------------------------------------------------------
    Call the SFOC_TI_Run function to perform the runtime tasks of the 
    SFOC_TI algorithm.
------------------------------------------------------------------------------*/
        SFOC_TI_Run(&sfoc); 

/*------------------------------------------------------------------------------
    Connect output of the SFOC.SVGEN to the PWM Driver and call the PWM driver 
    update function.
------------------------------------------------------------------------------*/
        pwm.mfunc_c1 = sfoc.svgen.va;         
        pwm.mfunc_c2 = sfoc.svgen.vb;
        pwm.mfunc_c3 = sfoc.svgen.vc;
        pwm.update(&pwm);

/*------------------------------------------------------------------------------
    Call the ileg2_dcbus_drv function to perform the ADC tasks for 2 currents and 
    DC-bus measurement.     
------------------------------------------------------------------------------*/
        ilg2_vdc.read(&ilg2_vdc);

/*------------------------------------------------------------------------------
    Connect outputs of the ILEG2VDCMEAS to SFOC   
------------------------------------------------------------------------------*/
	  	sfoc.current_abc.a = ilg2_vdc.Imeas_a;
	  	sfoc.current_abc.b = ilg2_vdc.Imeas_b;
	  	sfoc.current_abc.c = ilg2_vdc.Imeas_c;        
        sfoc.Vbus = ilg2_vdc.Vdc_meas;

/*------------------------------------------------------------------------------
    Call the diagnostic DAC utility update function.
------------------------------------------------------------------------------*/
        dac.update(&dac);
      
/*----------------------------------------------------------------------------*/
#endif /* BUILDLEVEL==LEVEL3 */


#if (BUILDLEVEL==LEVEL4)
/*---------------------------------------------------------------------------*/
#if     TARGET==F243                      
        EVIFRA=0x0ffff;           /* Clear all Group A EV interrupt flags    */

#elif   TARGET==F2407                                                          
        EVAIFRA=0x0ffff;          /* Clear all EV1 Group A EV interrupt flags*/
#endif              

/*------------------------------------------------------------------------------
    Call the enable/disable PWM signal drive function.
------------------------------------------------------------------------------*/
        drive.calc(&drive);

/*------------------------------------------------------------------------------
    Call the SFOC_TI_Run function to perform the runtime tasks of the 
    SFOC_TI algorithm.
------------------------------------------------------------------------------*/
        SFOC_TI_Run(&sfoc); 

/*------------------------------------------------------------------------------
    Connect output of the SFOC.SVGEN to the PWM Driver and call the PWM driver 
    update function.
------------------------------------------------------------------------------*/
        pwm.mfunc_c1 = sfoc.svgen.va;         
        pwm.mfunc_c2 = sfoc.svgen.vb;
        pwm.mfunc_c3 = sfoc.svgen.vc;
        pwm.update(&pwm);

/*------------------------------------------------------------------------------
    Call the ileg2_dcbus_drv function to perform the ADC tasks for 2 currents and 
    DC-bus measurement.     
------------------------------------------------------------------------------*/
        ilg2_vdc.read(&ilg2_vdc);

/*------------------------------------------------------------------------------
    Connect outputs of the ILEG2VDCMEAS to SFOC   
------------------------------------------------------------------------------*/
	  	sfoc.current_abc.a = ilg2_vdc.Imeas_a;
	  	sfoc.current_abc.b = ilg2_vdc.Imeas_b;
	  	sfoc.current_abc.c = ilg2_vdc.Imeas_c;        
        sfoc.Vbus = ilg2_vdc.Vdc_meas;

/*------------------------------------------------------------------------------
	First collect the position information. The driver function updates the
	qep data structure with the information. 
------------------------------------------------------------------------------*/
        qep.calc(&qep);
        sfoc.shaft_theta_elec = qep.theta_elec;
        sfoc.shaft_direction = qep.dir_QEP;

/*------------------------------------------------------------------------------
	Connect outputs of the QEP to SPEED  
------------------------------------------------------------------------------*/
        speed.theta_elec = qep.theta_elec;
        speed.calc(&speed);             
        sfoc.Mea_spd = speed.speed_frq;
        
/*------------------------------------------------------------------------------
    Call the diagnostic DAC utility update function.
------------------------------------------------------------------------------*/
        dac.update(&dac);

/*----------------------------------------------------------------------------*/
#endif /* BUILDLEVEL==LEVEL4 */


#if (BUILDLEVEL==LEVEL5)
/*---------------------------------------------------------------------------*/
#if     TARGET==F243                      
        EVIFRA=0x0ffff;           /* Clear all Group A EV interrupt flags    */

⌨️ 快捷键说明

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