TI中文支持网
TI专业的中文技术问题搜集分享网站

cc2640r2f的硬件定时器和软件定时器都不精确,怎么回事,怎么提高定时器精度?

我需要20khz的定时,也就是50us,分别用了硬件定时器和软件定时器分别作了测试,都不是特别精确

软件定时器:

void AddPwmOutTimer(void)
{
    Clock_Params clockParams;

    // Convert clockDuration in milliseconds to ticks.
    uint32_t clockTicks = 50/Clock_tickPeriod;//50us

    // Setup parameters.
    Clock_Params_init(&clockParams);

    // Setup argument.
//    clockParams.arg = arg;

    // If period is 0, this is a one-shot timer.
    clockParams.period = 50/Clock_tickPeriod;//50us

    // Starts immediately after construction if true, otherwise wait for a call
    // to start.
    clockParams.startFlag = false;

    // Initialize clock instance.
    Clock_construct(&PwmOutClock, PwmOutTimerHandler, clockTicks, &clockParams);
}

硬件定时器:

Hwi_Struct timer2Hwi;
void Timer2Init(void)
{
  /* Switches the peripheral power domain on */
  Power_setDependency(PowerCC26XX_PERIPH_GPT2);
  /* Prevents the controller from going to standby */
  Power_setConstraint(PowerCC26XX_SB_DISALLOW);
  // register ISR and enable hardware interrupt for timer
  Hwi_Params params;
  Hwi_Params_init(&params);
  params.enableInt = TRUE;
  Hwi_construct(&timer2Hwi, INT_GPT2A, &interruptTimerA, &params, NULL);
  /* Configure the timer hardware */
  TimerDisable(GPT2_BASE, TIMER_A);
  TimerConfigure(GPT2_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC);
  TimerPrescaleSet(GPT2_BASE, TIMER_A, 0); // prescaler is 1 – 48Mhz
  TimerLoadSet(GPT2_BASE, TIMER_A, 2400); // 20 khz
//  TimerIntClear(GPT2_BASE, TIMER_TIMA_TIMEOUT);
//  TimerIntEnable(GPT2_BASE, TIMER_TIMA_TIMEOUT);
//  TimerEnable(GPT2_BASE, TIMER_A);
  TimerIntDisable(GPT2_BASE, TIMER_TIMA_TIMEOUT);
  TimerDisable(GPT2_BASE, TIMER_A);
  TimerIntClear(GPT2_BASE, TIMER_TIMA_TIMEOUT);
}

因为我要动态修改PWM占空比,我的PWM周期就是20k,没有PWM中断,只能用定时器的方法,但是发现定时器不精准,导致经常性的无法及时修改pwm占空比,很头疼,这个问题怎么解决呢?

Viki Shi:

用协议栈的话,确实us级别的精度难以达到。可以看下这边的类似贴:e2echina.ti.com/…/122853

赞(0)
未经允许不得转载:TI中文支持网 » cc2640r2f的硬件定时器和软件定时器都不精确,怎么回事,怎么提高定时器精度?
分享到: 更多 (0)