求2812EvA计时器诡异问题解答

liujinjin   2009-7-12 14:37 楼主
本人编了一个电机控制程序,由EvA的Timer1作为采样计时器,周期中断后在中断服务程序中进行相关计算(计算与EvA无关)。随后返回等待下一次中断。开始时Timer1的周期值始终不能修改,我赋值0x00ff的值,而查看时他始终为0x1770.后在程序中删除Timer1的所有设置,改为Timer2的设置,结果还是如前Timer2的周期之无法改变,任为0x1770.,同时设有Timer1,Timer2时,只有Timer1发生同上状况,Timer2不工作。求高人解答.谢谢。


以下为设为Timer2的程序:
void main(void)
{
// Initialize System Control registers, PLL, WatchDog, Clocks to Alphafault state:
        // This function is found in the DSP281x_SysCtrl.c file.
    InitSysCtrl();

// HISPCP prescale register settings, normally it will be set to Alphafault values
    EALLOW;   // This is neeAlphad to write to EALLOW protected registers
    SysCtrlRegs.HISPCP.all = 0x0006;     // SYSCLKOUT/1 //HISCLK=10MHz
    EDIS;   // This is neeAlphad to disable write to EALLOW protected registers

// Disable and clear all CPU interrupts:
    DINT;
    IER = 0x0000;
    IFR = 0x0000;
    InitPieCtrl();
    InitPieVectTable();   
    EALLOW;
    PieVectTable.ADCINT=&adc1_isr;
    PieVectTable.T2PINT = &eva_timer2_isr;
    EDIS;
    init_eva_timer2();  
    PieCtrlRegs.PIEIER3.all = M_INT1;
    PieCtrlRegs.PIEIFR3.all = M_INT1;
    PieCtrlRegs.PIEACK.bit.ACK3=1;
    IER |= M_INT3;            
// Enable global Interrupts and higher priority real-time debug events:
    EINT;   // Enable Global interrupt INTM
    ERTM;    // Enable Global realtime interrupt DBGM

}

回复评论 (3)

补上初始化程序
void init_eva_timer2(void)
{
    // Initialize EVA Timer 2:
    // Setup Timer 2 Registers (EV A)

    EvaRegs.GPTCONA.all = 0;
    // Set the Period for the GP timer 2 to 0x0200;
    EvaRegs.T2PR = 0x0400;       // Period
    EvaRegs.T2CMPR = 0x0000;     // Compare Reg
   
    // Enable Period interrupt bits for GP timer 2
    // Count up, x128, internal clk, enable compare, use own period
    EvaRegs.EVAIMRB.bit.T2PINT = 1;
    EvaRegs.EVAIFRB.bit.T2PINT = 1;

    // Clear the counter for GP timer 2
    EvaRegs.T2CNT = 0x0000;
    EvaRegs.T2CON.all = 0x1742;

    // Start EVA ADC Conversion on timer 2 Period interrupt
    EvaRegs.GPTCONA.bit.T2TOADC = 2;
}
点赞  2009-7-12 14:38
你的主程序就这些吗?始终在执行初始化吗?
应该有for这样一个循环把
点赞  2009-7-23 05:42
不知道你是否设置了cputimer2的时钟,或者任意一个CPU定时器,如果有,将cpu定时器的周期放大些试试,我曾经也遇到过类似的怪现象,当然,最后发现还是设置的问题,不过现在我有些忘记了。
点赞  2009-7-27 12:26
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复