This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

f28035时钟问题

Other Parts Discussed in Thread: CONTROLSUITE

各位老师好,我正在学习f28035,用的controlSUITE中的例程,我看到程序中都是这么用时钟 的,先把程序粘贴如下。为什么在系统中要设置时钟在下面这几个函数之间一直循环,作用是什么?另外系统中断是采用定时器中断还是CPU中断,这个在哪有配置呢?

非常感谢!!!

void A0(void)
{
if(CpuTimer0Regs.TCR.bit.TIF == 1)
{
CpuTimer0Regs.TCR.bit.TIF = 1;
//-----------------------------------------------------------
(*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)
{
if(CpuTimer1Regs.TCR.bit.TIF == 1)
{
CpuTimer1Regs.TCR.bit.TIF = 1;
//-----------------------------------------------------------
(*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)
{
if(CpuTimer2Regs.TCR.bit.TIF == 1)
{
CpuTimer2Regs.TCR.bit.TIF = 1;
//-----------------------------------------------------------
(*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 (Disable==1)
{
EALLOW;
EPwm1Regs.TZFRC.bit.OST=1;
EPwm2Regs.TZFRC.bit.OST=1;
EPwm3Regs.TZFRC.bit.OST=1;
EPwm4Regs.TZFRC.bit.OST=1;
EDIS;
}
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)
//=================================================================================
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)
//=================================================================================
void C1(void) // Toggle GPIO-34
{
GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1; // Blink LED
//-----------------
//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;
}

  • 这是一个小的状态机,用于处理一些后台任务

  • 谢谢您的回复。

    请问后台有什么任务需要处理呢?

    这样的话,3个时钟被占用了,系统中断是CPU中断吗?

  • 并没有真正触发CPU中断,只是利用定时器的计数匹配标志位来判断是否已经计数到设定时间,来定时调度一个任务,举个例子

    void A0(void)
    {
    if(CpuTimer0Regs.TCR.bit.TIF == 1)
    {
    CpuTimer0Regs.TCR.bit.TIF = 1;
    //-----------------------------------------------------------
    (*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)
    {
    if(CpuTimer1Regs.TCR.bit.TIF == 1)
    {
    CpuTimer1Regs.TCR.bit.TIF = 1;
    //-----------------------------------------------------------
    (*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)
    {
    if(CpuTimer2Regs.TCR.bit.TIF == 1)
    {
    CpuTimer2Regs.TCR.bit.TIF = 1;
    //-----------------------------------------------------------
    (*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 (Disable==1)
    {
    EALLOW;
    EPwm1Regs.TZFRC.bit.OST=1;
    EPwm2Regs.TZFRC.bit.OST=1;
    EPwm3Regs.TZFRC.bit.OST=1;
    EPwm4Regs.TZFRC.bit.OST=1;
    EDIS;
    }
    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)
    //=================================================================================
    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)
    //=================================================================================
    void C1(void) // Toggle GPIO-34 
    {
    GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1; // Blink LED
    //-----------------
    //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; 
    }

    红色框部分是CPUtimer0计时到你设定时间,就会CpuTimer1Regs.TCR.bit.TIF 标志位等于1,所以任务A0就会判断通过,来运行,然后运行完,会把指针给到任务B,这样CPUtimer1定时到时间,如黄色部分,就会运行B0任务,然后再把指针扔个C任务,这样来回的调度。可以理解为一个小操作系统

    A0任务下会有子任务A1,A2,A3。B C也同样。

  • 谢谢您,程序如何运行的我明白了。

    1、但是,在程序中只存在PWM错误联防程序,没有执行其他的任务,这样和直接用一个定时器定时有什么区别呢?

    2、程序中没有设定系统总中断是用哪个定时器中断,这个怎么判断呢?

  • 1、但是,在程序中只存在PWM错误联防程序,没有执行其他的任务,这样和直接用一个定时器定时有什么区别呢?

    这只是C2000例程一个模板,这个例程只有这一个功能,但是其他例程可能会有很多后台任务就需要这样方法来调度。

    2、程序中没有设定系统总中断是用哪个定时器中断,这个怎么判断呢?

    你指的系统中断是什么中断?要这个中断什么功能?系统总中断只是一个bit,用来允许PWM或者ADC的中断被CPU触发执行

  • 在程序中,有一个主中断,程序中放着进行矢量控制需要的算法,进入这个中断是定时器中断吧。

    谢谢你!!!

  • 这个中断一般是ADC中断或者EPWM中断,建议你可以看一下F28035的 SPRUFN3 userguide了解一下C2000的中断系统

  • 嗯好,非常感谢!!!