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

📄 pmsm32.c

📁 本程序来自TI公司网站原程序,其功能是通过传统的矢量控制算法来实现对永磁同步电机的控制,矢量控制采用双闭环结构
💻 C
📖 第 1 页 / 共 4 页
字号:
        drive.init(&drive);
        }
           
/*-----------------------------------------------------------------------------
    Initialize PWM Generator
-----------------------------------------------------------------------------*/
        pwm.init(&pwm);          

/*-----------------------------------------------------------------------------
    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.svgen.vc;
        dac.qptr3=&sfoc.rg.rmp_out;

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


#if (BUILDLEVEL==LEVEL4)

/*-----------------------------------------------------------------------------
    Set the pwm period to 500 cycles,(F243) [ or 750 cycles, LF240x ].
    This assumes a CPU CLKIN of 5MHz for the F243 and CLKIN of 7.5 MHz
    for the LF240x.
    Defaults for pwm are set in F243_PWM.H
    Note that this will ONLY change runtime configurable parameters.
    For changing settings like timer modes or PWM Polarity, once the 
    constants like PWM_INIT_STATE, or ACTR_INIT_STATE are changed, the
    driver file must be re-compiled.

    To do this change the constant and then run the batch file 
    ..\..\drv011\build\f243drv.bat or f2407drv.bat

    This will re-build the driver, with the new timer mode or PWM polarity,
    and then run the (re)build for this project. This will update the 
    setting.
-----------------------------------------------------------------------------*/
#if     TARGET==F243                      
        pwm.period_max=667;          /* This is based on 15kHz PWM frequency (20MHz) */

#elif   TARGET==F2407                                                          
/*        pwm.period_max=1000;    */    /* This is based on 15kHz PWM frequency (30MHz) */
        pwm.period_max=1333;       /* This is based on 15kHz PWM frequency (40MHz)*/
#endif  /* TARGET */            

/*-----------------------------------------------------------------------------
    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
-----------------------------------------------------------------------------*/
        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=&sfoc.rg.rmp_out;
        dac.qptr1=&sfoc.svgen.va;
        dac.qptr2=&qep.theta_elec;
        dac.qptr3=&sfoc.svgen.vb;

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

#if (BUILDLEVEL==LEVEL5)

/*-----------------------------------------------------------------------------
    Set the pwm period to 500 cycles,(F243) [ or 750 cycles, LF240x ].
    This assumes a CPU CLKIN of 5MHz for the F243 and CLKIN of 7.5 MHz
    for the LF240x.
    Defaults for pwm are set in F243_PWM.H
    Note that this will ONLY change runtime configurable parameters.
    For changing settings like timer modes or PWM Polarity, once the 
    constants like PWM_INIT_STATE, or ACTR_INIT_STATE are changed, the
    driver file must be re-compiled.

    To do this change the constant and then run the batch file 
    ..\..\drv011\build\f243drv.bat or f2407drv.bat

    This will re-build the driver, with the new timer mode or PWM polarity,
    and then run the (re)build for this project. This will update the 
    setting.
-----------------------------------------------------------------------------*/
#if     TARGET==F243                      
        pwm.period_max=667;          /* This is based on 15kHz PWM frequency (20MHz) */

#elif   TARGET==F2407                                                          
/*        pwm.period_max=1000;    */    /* This is based on 15kHz PWM frequency (30MHz) */
        pwm.period_max=1333;       /* This is based on 15kHz PWM frequency (40MHz)*/
#endif  /* TARGET */            

/*-----------------------------------------------------------------------------
    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
-----------------------------------------------------------------------------*/
        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=&qep.theta_elec; 
        dac.qptr1=&sfoc.svgen.va;
        dac.qptr2=&sfoc.smo.thetae;  
        dac.qptr3=&sfoc.svgen.vb;

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

#if (BUILDLEVEL==LEVEL6)

/*-----------------------------------------------------------------------------
    Set the pwm period to 500 cycles,(F243) [ or 750 cycles, LF240x ].
    This assumes a CPU CLKIN of 5MHz for the F243 and CLKIN of 7.5 MHz
    for the LF240x.
    Defaults for pwm are set in F243_PWM.H
    Note that this will ONLY change runtime configurable parameters.
    For changing settings like timer modes or PWM Polarity, once the 
    constants like PWM_INIT_STATE, or ACTR_INIT_STATE are changed, the
    driver file must be re-compiled.

    To do this change the constant and then run the batch file 
    ..\..\drv011\build\f243drv.bat or f2407drv.bat

    This will re-build the driver, with the new timer mode or PWM polarity,
    and then run the (re)build for this project. This will update the 
    setting.
-----------------------------------------------------------------------------*/
#if     TARGET==F243                      
        pwm.period_max=667;          /* This is based on 15kHz PWM frequency (20MHz) */

#elif   TARGET==F2407                                                          
/*        pwm.period_max=1000;    */    /* This is based on 15kHz PWM frequency (30MHz) */
        pwm.period_max=1333;       /* This is based on 15kHz PWM frequency (40MHz)*/
#endif  /* TARGET */            

/*-----------------------------------------------------------------------------
    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
-----------------------------------------------------------------------------*/
        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.va;
        dac.qptr2=&sfoc.smo.thetae;
        dac.qptr3=&sfoc.svgen.vb;

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


#if (BUILDLEVEL==LEVEL7)

/*-----------------------------------------------------------------------------
    Set the pwm period to 500 cycles,(F243) [ or 750 cycles, LF240x ].
    This assumes a CPU CLKIN of 5MHz for the F243 and CLKIN of 7.5 MHz
    for the LF240x.
    Defaults for pwm are set in F243_PWM.H
    Note that this will ONLY change runtime configurable parameters.
    For changing settings like timer modes or PWM Polarity, once the 
    constants like PWM_INIT_STATE, or ACTR_INIT_STATE are changed, the
    driver file must be re-compiled.

    To do this change the constant and then run the batch file 
    ..\..\drv011\build\f243drv.bat or f2407drv.bat

    This will re-build the driver, with the new timer mode or PWM polarity,
    and then run the (re)build for this project. This will update the 
    setting.
-----------------------------------------------------------------------------*/
#if     TARGET==F243                      
        pwm.period_max=667;          /* This is based on 15kHz PWM frequency (20MHz) */

#elif   TARGET==F2407                                                          
/*        pwm.period_max=1000;    */    /* This is based on 15kHz PWM frequency (30MHz) */
        pwm.period_max=1333;       /* This is based on 15kHz PWM frequency (40MHz)*/
#endif  /* TARGET */            

⌨️ 快捷键说明

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