msp432功能(一)定时功能

const Timer_A_ContinuousModeConfig continuousModeConfig =
{
     
        TIMER_A_CLOCKSOURCE_ACLK,           // ACLK Clock Source
        TIMER_A_CLOCKSOURCE_DIVIDER_1,      // ACLK/1 = 32.768khz     //最大64分频       
        TIMER_A_TAIE_INTERRUPT_ENABLE,      // Enable Overflow ISR
        TIMER_A_DO_CLEAR                    // Clear Counter
};
void timer_count_Init(void)
{
     
    /* Starting and enabling ACLK (32kHz)   时钟频率*/
        CS_setReferenceOscillatorFrequency(CS_REFO_128KHZ);
        CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_4);//分频

        /* Configuring Continuous Mode */
        Timer_A_configureContinuousMode(TIMER_A0_BASE, &continuousModeConfig); //连续计数模式
      
        /* Enabling interrupts and going to sleep */
        MAP_Interrupt_enableSleepOnIsrExit();
        MAP_Interrupt_enableInterrupt(INT_TA0_N);

        /* Enabling MASTER interrupts */
        MAP_Interrupt_enableMaster();

        /* Starting the Timer_A0 in continuous mode */
        MAP_Timer_A_startCounter(TIMER_A0_BASE, TIMER_A_CONTINUOUS_MODE);
 }

如何计算定时时间???
1.看时钟频率
这里这里设置的是CS_setReferenceOscillatorFrequency(CS_REFO_128KHZ); 128khz
2.看分频系数
CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_4); 4分频
3.确定时钟频率 128/4=32 ----------------32khz(ACLK)
time=65535/f(ACLK) *结构体中分频数 (TIMER_A_CLOCKSOURCE_DIVIDER_?)
为什么是65535???-----------------------因为是16位的计数器

验证函数中时间计算:
time=65535/ACLK*1=65535/32000=2s

你可能感兴趣的:(MSP432)