在HVACI_Sensorless.C程序中定义了一下这些状态机函数
// State Machine function prototypes
//------------------------------------
// Alpha states
void A0(void); //state A0
void B0(void); //state B0
void C0(void); //state C0
// A branch states
void A1(void); //state A1
void A2(void); //state A2
void A3(void); //state A3
// B branch states
void B1(void); //state B1
void B2(void); //state B2
void B3(void); //state B3
// C branch states
void C1(void); //state C1
void C2(void); //state C2
void C3(void); //state C3
// Variable declarations
void (*Alpha_State_Ptr)(void); // Base States pointer
void (*A_Task_Ptr)(void); // State pointer A branch
void (*B_Task_Ptr)(void); // State pointer B branch
void (*C_Task_Ptr)(void); // State pointer C branch
// Timing sync for background loops
// Timer period definitions found in device specific PeripheralHeaderIncludes.h
CpuTimer0Regs.PRD.all = mSec1; // A tasks
CpuTimer1Regs.PRD.all = mSec5; // B tasks
CpuTimer2Regs.PRD.all = mSec50; // C tasks
// Tasks State-machine init
Alpha_State_Ptr = &A0;// ;
A_Task_Ptr = &A1;
B_Task_Ptr = &B1;
C_Task_Ptr = &C1;
//=================================================================================
// STATE-MACHINE SEQUENCING AND SYNCRONIZATION FOR SLOW BACKGROUND TASKS
//=================================================================================
//--------------------------------- FRAMEWORK -------------------------------------
void A0(void)
{
// loop rate synchronizer for A-tasks
if(CpuTimer0Regs.TCR.bit.TIF == 1)
{
CpuTimer0Regs.TCR.bit.TIF = 1; // clear flag
//-----------------------------------------------------------
(*A_Task_Ptr)(); // jump to an A Task (A1,A2,A3,...)
//-----------------------------------------------------------
VTimer0[0]++; // virtual timer 0, instance 0 (spare)
SerialCommsTimer++;
}
Alpha_State_Ptr = &B0; // Comment out to allow only A tasks
}
void B0(void)
{
// loop rate synchronizer for B-tasks
if(CpuTimer1Regs.TCR.bit.TIF == 1)
{
CpuTimer1Regs.TCR.bit.TIF = 1; // clear flag
//-----------------------------------------------------------
(*B_Task_Ptr)(); // jump to a B Task (B1,B2,B3,...)
//-----------------------------------------------------------
VTimer1[0]++; // virtual timer 1, instance 0 (spare)
}
Alpha_State_Ptr = &C0; // Allow C state tasks
}
void C0(void)
{
// loop rate synchronizer for C-tasks
if(CpuTimer2Regs.TCR.bit.TIF == 1)
{
CpuTimer2Regs.TCR.bit.TIF = 1; // clear flag
//-----------------------------------------------------------
(*C_Task_Ptr)(); // jump to a C Task (C1,C2,C3,...)
//-----------------------------------------------------------
VTimer2[0]++; //virtual timer 2, instance 0 (spare)
}
Alpha_State_Ptr = &A0; // Back to State A0
}
//=================================================================================
// A - TASKS (executed in every 1 msec)
//=================================================================================
//--------------------------------------------------------
void A1(void) // SPARE (not used)
//--------------------------------------------------------
{
if(EPwm1Regs.TZFLG.bit.OST==0x1)
TripFlagDMC=1; // Trip on DMC (halt and IPM fault trip )
//-------------------
//the next time CpuTimer0 'counter' reaches Period value go to A2
A_Task_Ptr = &A2;
//-------------------
}
//-----------------------------------------------------------------
void A2(void) // SPARE (not used)
//-----------------------------------------------------------------
{
//-------------------
//the next time CpuTimer0 'counter' reaches Period value go to A3
A_Task_Ptr = &A3;
//-------------------
}
//-----------------------------------------
void A3(void) // SPARE (not used)
//-----------------------------------------
{
//-----------------
//the next time CpuTimer0 'counter' reaches Period value go to A1
A_Task_Ptr = &A1;
//-----------------
}
//=================================================================================
// B - TASKS (executed in every 5 msec)
//=================================================================================
//----------------------------------- USER ----------------------------------------
//----------------------------------------
void B1(void) // Toggle GPIO-00
//----------------------------------------
{
//-----------------
//the next time CpuTimer1 'counter' reaches Period value go to B2
B_Task_Ptr = &B2;
//-----------------
}
//----------------------------------------
void B2(void) // SPARE
//----------------------------------------
{
//-----------------
//the next time CpuTimer1 'counter' reaches Period value go to B3
B_Task_Ptr = &B3;
//-----------------
}
//----------------------------------------
void B3(void) // SPARE
//----------------------------------------
{
//-----------------
//the next time CpuTimer1 'counter' reaches Period value go to B1
B_Task_Ptr = &B1;
//-----------------
}
//=================================================================================
// C - TASKS (executed in every 50 msec)
//=================================================================================
//--------------------------------- USER ------------------------------------------
//----------------------------------------
void C1(void) // Toggle GPIO-34
//----------------------------------------
{
if(EPwm1Regs.TZFLG.bit.OST==0x1) // TripZ for PWMs is low (fault trip)
{ TripFlagDMC=1;
}
GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1; // Turn on/off LD3 on the controlCARD
//-----------------
//the next time CpuTimer2 'counter' reaches Period value go to C2
C_Task_Ptr = &C2;
//-----------------
}
//----------------------------------------
void C2(void) // SPARE
//----------------------------------------
{
//-----------------
//the next time CpuTimer2 'counter' reaches Period value go to C3
C_Task_Ptr = &C3;
//-----------------
}
//-----------------------------------------
void C3(void) // SPARE
//-----------------------------------------
{
//-----------------
//the next time CpuTimer2 'counter' reaches Period value go to C1
C_Task_Ptr = &C1;
//-----------------
}
之后在main函数的死循环中跳转到Alpha state (A0,B0,...)
// IDLE loop. Just sit and loop forever:
for(;;) //infinite loop
{
// State machine entry & exit point
//===========================================================
(*Alpha_State_Ptr)(); // jump to an Alpha state (A0,B0,...)
//===========================================================
}
问题是
1.该程序设置了这么多状态机(ABC三组共12个)是干什么用的?程序员的目的是什么,在最早2812的电机控制程序中只有主中断interrupt void MainISR(void)程序,没有这些状态机。
2.状态机跳转的次数太多跟不上,不知道在有没有文档对其进行说明,在改程序的doc文件夹中没有发现对于状态机的说明,只有一个PDF文档对于电机控制部分的主中断进行了说明
3.这些状态机的表现是在控制28335control card 上的一个红色LED灯的闪烁,但是当我提高主中断的中断频率,增加主中断的运算量时,LED不再闪烁,是为什么?
4.如何判断主中断(PieVectTable.EPWM1_INT = &MainISR;)中的程序代码是否被完全执行?
例如:将PWM1的主中断频率定为20K,#define ISR_FREQUENCY 20
主中断里的电机控制程序进行了大量的增幅,运算量较大,如何证明PWM1的主中断内的代码在0.05ms内全部执行完