Kinetis KEA:产生定时器中断的LED切换频率

时间:2018-01-26 02:30:44

标签: c arm embedded microcontroller nxp-microcontroller

我正在使用恩智浦的Kinetis KEA64微控制器。

时钟的实际频率为20 MHz,每2.5ms产生一次定时器中断。我有一个中断处理程序,当产生这个定时器中断时切换LED。 LED正在切换此定时器中断,但我不确切知道LED的频率。我的LED是否在5kHz时切换?这是对的吗?

void interrupt_application_timer_FTM0()
{
    SIM_SCGC |= SIM_SCGC_FTM0_MASK; /* Enable Clock for FTM0 */         
    FTM0_SC |= FTM_SC_PS(7);    /* Select Preescaler in this case 128. 20 Mhz /128 =156.25 Khz. */ 
                                    /* Counter increase by one every 6.4 us */      
        /* Enable Channle 0*/
    FTM0_C0SC |= FTM_CnSC_CHIE_MASK; /* Enable channel 0 interrupt */
    FTM0_C0SC |= FTM_CnSC_MSA_MASK;  /* Channel as Output compare mode */           
        /*Select interrupt frequency*/
    FTM0_C0V = FTM_CnV_VAL(391) ;       /* Interrupt every 2.5ms */ 

    FTM0_SC |= FTM_SC_CLKS(1); /*FTM0 use system clock*/

        /* Set the ICPR and ISER registers accordingly */
    NVIC_ICPR |= 1 << ((INT_FTM0-16)%32);
    NVIC_ISER |= 1 << ((INT_FTM0-16)%32);
}

这是我的中断处理程序

void FTM0_IRQHandler()
  {     
    if (1==((FTM0_C0SC & FTM_CnSC_CHF_MASK)>>FTM_CnSC_CHF_SHIFT) )  /* If the CHF of the channel is equal to 0 */
    {
        (void)FTM0_C0SC;                            /* Read to clear flag */
        FTM0_C0SC ^= FTM_CnSC_CHF_MASK;             /* Clear flag */
        FTM0_C0V = FTM0_C0V + 391 ; /* Refresh interrupt period */

        if (LED_counter>=50){
            /* Toggle LED */
            /* Reset counter */
            LED0_TOGGLE;
            LED_counter = 0;
        }
        LED_counter++;
    }
  }

1 个答案:

答案 0 :(得分:1)

  1. 使用频率测量范围
  2. 在MCU中,您可以将总线时钟启用到一个引脚(Busclockout),启用该功能并检查总线时钟,以便确认计算
  3. 然后在LED上使用示波器确认您的频率