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

📄 pmsm31.c

📁 TI 的DSP2407A的无速度传感器永磁同步电机FOC控制程序
💻 C
📖 第 1 页 / 共 3 页
字号:
           
/*-----------------------------------------------------------------------------
    Initialize PWM Generator
-----------------------------------------------------------------------------*/
        pwm.init(&pwm);          

/*-----------------------------------------------------------------------------
    Initialize ILEG2MEAS
-----------------------------------------------------------------------------*/
       	ilg2.init(&ilg2);

/*-----------------------------------------------------------------------------
    Set the dac pointers
-----------------------------------------------------------------------------*/
        dac.qptr0=&ilg2.out_a;
        dac.qptr1=&foc.svgen.vb;
        dac.qptr2=&foc.svgen.vc;
        dac.qptr3=&foc.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 FOC_TI object. This is a call to the init method within 
    the FOC_TI object foc.
-----------------------------------------------------------------------------*/
        FOC_TI_Init(&foc);

/*-----------------------------------------------------------------------------
    Initialize the real time monitor
-----------------------------------------------------------------------------*/
        rtmon_init();            /* Call the monitor init function           */
 //      	enable_ints();      /* Set off the system running.              */
		asm (" CLRC INTM");     /* 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 ILEG2MEAS
-----------------------------------------------------------------------------*/
       	ilg2.init(&ilg2);

/*-----------------------------------------------------------------------------
    Set the dac pointers
-----------------------------------------------------------------------------*/
        dac.qptr0=&foc.rg.rmp_out;
        dac.qptr1=&foc.svgen.va;
        dac.qptr2=&qep.theta_elec;
        dac.qptr3=&foc.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 FOC_TI object. This is a call to the init method within 
    the FOC_TI object foc.
-----------------------------------------------------------------------------*/
        FOC_TI_Init(&foc);

/*-----------------------------------------------------------------------------
    Initialize the real time monitor
-----------------------------------------------------------------------------*/
        rtmon_init();            /* Call the monitor init function           */
 //      	enable_ints();      /* Set off the system running.              */
		asm (" CLRC INTM");     /* 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 ILEG2MEAS
-----------------------------------------------------------------------------*/
       	ilg2.init(&ilg2);

/*-----------------------------------------------------------------------------
    Set the dac pointers
-----------------------------------------------------------------------------*/
        dac.qptr0=&ilg2.out_a;
        dac.qptr1=&foc.svgen.va;
        dac.qptr2=&qep.theta_elec;
        dac.qptr3=&foc.svgen.vb;

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


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

//#elif   TARGET==F2407                                                          
        EVBIFRA=0x0ffff;          /* Clear all EV2 Group B 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*/
        EVBIFRA=0x0ffff;          /* Clear all EV2 Group B EV interrupt flags*/
//#endif              

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

/*------------------------------------------------------------------------------
    Call the FOC_TI_Run function to perform the runtime tasks of the 
    FOC_TI algorithm.
------------------------------------------------------------------------------*/
        FOC_TI_Run(&foc); 

/*------------------------------------------------------------------------------
    Connect output of the FOC.SVGEN to the PWM Driver and call the PWM driver 
    update function.
------------------------------------------------------------------------------*/
        pwm.mfunc_c1 = foc.svgen.va;         
        pwm.mfunc_c2 = foc.svgen.vb;
        pwm.mfunc_c3 = foc.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*/
        EVBIFRA=0x0ffff;          /* Clear all EV2 Group B EV interrupt flags*/
//#endif              

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

/*------------------------------------------------------------------------------
    Call the FOC_TI_Run function to perform the runtime tasks of the 
    FOC_TI algorithm.
------------------------------------------------------------------------------*/
        FOC_TI_Run(&foc); 

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

/*------------------------------------------------------------------------------
    Call the ileg2_drv function to perform the ADC tasks for 2 currents measurement.     
------------------------------------------------------------------------------*/
        ilg2.read(&ilg2);

/*------------------------------------------------------------------------------

⌨️ 快捷键说明

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