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

📄 pmsm31.c

📁 TI 的DSP2407A的无速度传感器永磁同步电机FOC控制程序
💻 C
📖 第 1 页 / 共 3 页
字号:
    Connect outputs of the ILEG2MEAS to FOC   
------------------------------------------------------------------------------*/
	  	foc.current_abc.a = ilg2.out_a;
	  	foc.current_abc.b = ilg2.out_b;
	  	foc.current_abc.c = -(ilg2.out_a+ilg2.out_b);        

/*------------------------------------------------------------------------------
    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*/
        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 ileg2_drv function to perform the ADC tasks for 2 currents measurement.     
------------------------------------------------------------------------------*/
        ilg2.read(&ilg2);

/*------------------------------------------------------------------------------
    Connect outputs of the ILEG2MEAS to FOC   
------------------------------------------------------------------------------*/
	  	foc.current_abc.a = ilg2.out_a;
	  	foc.current_abc.b = ilg2.out_b;
	  	foc.current_abc.c = -(ilg2.out_a+ilg2.out_b);

/*------------------------------------------------------------------------------
    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*/
        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 ileg2_drv function to perform the ADC tasks for 2 currents measurement.     
------------------------------------------------------------------------------*/
        ilg2.read(&ilg2);

/*------------------------------------------------------------------------------
    Connect outputs of the ILEG2MEAS to SFOC   
------------------------------------------------------------------------------*/
	  	foc.current_abc.a = ilg2.out_a;
	  	foc.current_abc.b = ilg2.out_b;
	  	foc.current_abc.c = -(ilg2.out_a+ilg2.out_b);

/*------------------------------------------------------------------------------
	First collect the position information. The driver function updates the
	qep data structure with the information. 
------------------------------------------------------------------------------*/
        qep.calc(&qep);

/*------------------------------------------------------------------------------
	Connect outputs of the QEP to SPEED  
------------------------------------------------------------------------------*/
        speed.theta_elec = qep.theta_elec;
        speed.calc(&speed);             
        foc.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    */

//#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 ileg2_drv function to perform the ADC tasks for 2 currents measurement.     
------------------------------------------------------------------------------*/
        ilg2.read(&ilg2);

/*------------------------------------------------------------------------------
    Connect outputs of the ILEG2MEAS to FOC   
------------------------------------------------------------------------------*/
	  	foc.current_abc.a = ilg2.out_a;
	  	foc.current_abc.b = ilg2.out_b;
	  	foc.current_abc.c = -(ilg2.out_a+ilg2.out_b);

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

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


/* Change reference speed from pu value to rpm value (Q15 -> Q0)   */
/* Here the base speed is 6000 rpm  */
       	foc.speed_ref_rpm = mul_q(foc.speed_ref,15,6000,0,0);


  	asm("    SETC     XF ");   

}    /* c_int02() */            


/*------------------------------------------------------------------------------
        The CAP3 Interrupt invokes the Int 4 core Interrupt. This is vectored 
        to the c_int04 function below.
        Since in our system the only source of interrupts at level 4 is the
        CAP3 interrupt, the PIVR value is not read or interpreted. In case there
        are multiple events happening on this level, that would be needed.
------------------------------------------------------------------------------*/
void interrupt c_int04()
{                            

/*------------------------------------------------------------------------------
        Since the CAP6 pin is connected to the Encoder Index Signal, execution
        of this code implies that a Index event has occured. So the index 
        event handler is invoked.
------------------------------------------------------------------------------*/
        qep.indexevent(&qep);

}    /* c_int04() */   


void RstSystem(void)
{ 
/*-----------------------------------------------------------------------------
    First execute the initialization for the Wait Stage Genrator, 
    Global interrupt disable, Shut off the Watchdog, 
    and set up the Interupt Mask Register
-----------------------------------------------------------------------------*/
        WSGR=WAIT_STATES;         /* Initialize Wait State Generator         */
//        disable_ints();          /* Make sure the interrupts are disabled   */
        asm (" SETC INTM");        /* Make sure the interrupts are disabled   */
        wdog.disable();           /* Vccp/Wddis pin/bit must be high         */
        IMR=0x0A;                 /* Set up interrupt mask to enable INT4 and INT2   
                                     until an explicit enable.               */

/*-----------------------------------------------------------------------------
    Next we do the code for setting up the SCSR register, which is dependent 
    on the exact device the code is being compiled for (F243 / F2407).
-----------------------------------------------------------------------------*/
        SCSR1=0x8c;                /* Init SCSR */
        EVBIMRA=0x0201;           /* Enable the timer 3 underflow and PDPINTB interrupts  */
		EVBIMRC=0x04;			  /* Enable the CAP6 (index QEP) interrupt  */

}   /* RstSystem(void) */
                          
void interrupt phantom(void)
{   

	static int phantom_count;
	phantom_count ++;
	
/*  Empty function: Used to handle any unwanted interrupts or events.
    All unused interrupt vectors are pointed to this function so that
    if any un-handled interrupts do get enabled, they are handled in a 
    benign manner, preventing un-intended branches, calls or execution
    into garbage.  
    Note that this function is an ISR, not a ordinary function.
*/
} /* phantom() */


/*------------------------------------------------------------------------------
    This function just provides a c-interface to the asm RTMON init function.
------------------------------------------------------------------------------*/
void rtmon_init(void)
{
    asm("       CALL    MON_RT_CNFG ");
}  /* rtmon_init() */




     






⌨️ 快捷键说明

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