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.

28035 定时器1,2的使用

定时器1,2 分别与INT13、INT14关联以后,怎么才能时能这些中断?在哪里进行设置?如何设置?

  • 定时器本身就有中断,是内部模块触发的中断。

    INT13和INT14是外部信号触发的中断。

    这两者是不同类型的中断。

    楼主能将应用解释的清楚一些么?

  • 我是看到cpu中断0可以通过PIE中INT1,.7进行使能,看到例程中只是将cpu中断1、2与INT13、INT14进行关联,没有进行使能操作。请问在使用cpu中断1时还需要这一步操作吗?如果需要的话,怎样进行设置?

    谢谢

  • 楼主如果要操作CPUTimer0,1,2,可以参考下面这个历程,用到了0,1,2 都有ISR:

    //###########################################################################

    // Description:

    //! \addtogroup f2803x_example_list

    //! <h1>Cpu Timer (cpu_timer)</h1>

    //!

    //! This example configures CPU Timer0, 1, and 2 and increments

    //! a counter each time the timer asserts an interrupt.

    //!

    //! \b Watch \b Variables \n

    //! - CpuTimer0.InterruptCount

    //! - CpuTimer1.InterruptCount

    //! - CpuTimer2.InterruptCount

    //

    //###########################################################################

    // $TI Release: F2803x C/C++ Header Files and Peripheral Examples V126 $

    // $Release Date: November 30, 2011 $

    //###########################################################################

    #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

    // Prototype statements for functions found within this file.

    __interrupt void cpu_timer0_isr(void);

    __interrupt void cpu_timer1_isr(void);

    __interrupt void cpu_timer2_isr(void);

    void main(void)

    {

    // Step 1. Initialize System Control:

    // PLL, WatchDog, enable Peripheral Clocks

    // This example function is found in the DSP2803x_SysCtrl.c file.

      InitSysCtrl();

    // Step 2. Initalize GPIO:

    // This example function is found in the DSP2803x_Gpio.c file and

    // illustrates how to set the GPIO to it's default state.

    // InitGpio();  // Skipped for this example

    // Step 3. Clear all interrupts and initialize PIE vector table:

    // Disable CPU interrupts

      DINT;

    // Initialize the PIE control registers to their default state.

    // The default state is all PIE interrupts disabled and flags

    // are cleared.

    // This function is found in the DSP2803x_PieCtrl.c file.

      InitPieCtrl();

    // Disable CPU interrupts and clear all CPU interrupt flags:

      IER = 0x0000;

      IFR = 0x0000;

    // Initialize the PIE vector table with pointers to the shell Interrupt

    // Service Routines (ISR).

    // This will populate the entire table, even if the interrupt

    // is not used in this example.  This is useful for debug purposes.

    // The shell ISR routines are found in DSP2803x_DefaultIsr.c.

    // This function is found in DSP2803x_PieVect.c.

      InitPieVectTable();

    // Interrupts that are used in this example are re-mapped to

    // ISR functions found within this file.

      EALLOW;  // This is needed to write to EALLOW protected registers

      PieVectTable.TINT0 = &cpu_timer0_isr;

      PieVectTable.TINT1 = &cpu_timer1_isr;

      PieVectTable.TINT2 = &cpu_timer2_isr;

      EDIS;    // This is needed to disable write to EALLOW protected registers

    // Step 4. Initialize the Device Peripheral. This function can be

    //         found in DSP2803x_CpuTimers.c

      InitCpuTimers();   // For this example, only initialize the Cpu Timers

    // Configure CPU-Timer 0, 1, and 2 to interrupt every second:

    // 60MHz CPU Freq, 1 second Period (in uSeconds)

      ConfigCpuTimer(&CpuTimer0, 60, 1000000);

      ConfigCpuTimer(&CpuTimer1, 60, 1000000);

      ConfigCpuTimer(&CpuTimer2, 60, 1000000);

    // To ensure precise timing, use write-only instructions to write to the entire register. Therefore, if any

    // of the configuration bits are changed in ConfigCpuTimer and InitCpuTimers (in DSP2803x_CpuTimers.h), the

    // below settings must also be updated.

      CpuTimer0Regs.TCR.all = 0x4000; // Use write-only instruction to set TSS bit = 0

      CpuTimer1Regs.TCR.all = 0x4000; // Use write-only instruction to set TSS bit = 0

      CpuTimer2Regs.TCR.all = 0x4000; // Use write-only instruction to set TSS bit = 0

    // Step 5. User specific code, enable interrupts:

    // Enable CPU int1 which is connected to CPU-Timer 0, CPU int13

    // which is connected to CPU-Timer 1, and CPU int 14, which is connected

    // to CPU-Timer 2:

      IER |= M_INT1;

      IER |= M_INT13;

      IER |= M_INT14;

    // Enable TINT0 in the PIE: Group 1 interrupt 7

      PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

    // Enable global Interrupts and higher priority real-time debug events:

      EINT;   // Enable Global interrupt INTM

      ERTM;   // Enable Global realtime interrupt DBGM

    // Step 6. IDLE loop. Just sit and loop forever (optional):

      for(;;);

    }

    __interrupt void cpu_timer0_isr(void)

    {

      CpuTimer0.InterruptCount++;

      // Acknowledge this interrupt to receive more interrupts from group 1

      PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

    }

    __interrupt void cpu_timer1_isr(void)

    {

      CpuTimer1.InterruptCount++;

      // The CPU acknowledges the interrupt.

      EDIS;

    }

    __interrupt void cpu_timer2_isr(void)

    {  EALLOW;

      CpuTimer2.InterruptCount++;

      // The CPU acknowledges the interrupt.

      EDIS;

    }

    //===========================================================================

    // No more.

    //===========================================================================

  • 您好,用您上面的例程配置TIMER1, 但是只能进入一次中断,后面就进不去TIMER1了,TIMERO 可以照常进入中断,请问怎么解决,着急,期盼回复

  • CpuTimer1.RegsAddr = &CpuTimer1Regs;
    // CpuTimer2.RegsAddr = &CpuTimer2Regs;
    // Initialize timer period to maximum:
    CpuTimer1Regs.PRD.all = 0x752A;//0.5MS//0xEA54; //0xEA54*16.67ns=1ms
    // CpuTimer2Regs.PRD.all = 0xFFFFFFFF;
    //Timer1 Free Run
    CpuTimer1Regs.TCR.bit.FREE = 1;
    // Make sure timers are started:
    CpuTimer1Regs.TCR.bit.TSS = 0;
    // CpuTimer2Regs.TCR.bit.TSS = 1;
    // Reload all counter register with period value:
    CpuTimer1Regs.TCR.bit.TRB = 1;
    // CpuTimer2Regs.TCR.bit.TRB = 1;
    // Reset interrupt counters:
    CpuTimer1.InterruptCount = 0;
    // CpuTimer2.InterruptCount = 0;

    }

    别人这里定时器的中断禁止了,那不是定时器没有定时的功能啊,没中断函数了,我不知道写这个定时器还由什么用,希望大神指点下。。谢谢