Systick Reset or Recalibration

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Systick Reset or Recalibration

1,394 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kwinchell on Wed Aug 28 15:42:52 MST 2013
I have an application that uses systick.

Here is my code:

void Scheduler_Start(void)
{
    NVIC_SetPriority(PendSV_IRQn, 3);

    __enable_irq();

    SysTick->CTRL = (1<<SYSTICK_CLKSOURCE) | (1<<SYSTICK_ENABLE) | (1<<SYSTICK_TICKINT); // enable the timer

}


void Scheduler_Init(void)
{
    // Disable the scheduler
    SysTick->STCTRL = (uint8_t) 0;       
    SetSchedulerPeriod();   // set period to correct value for PCLK

    NVIC_SetPriority(SysTick_IRQn, 3);

    SchedulerTicks = 0;
    // the Scheduler Clock (SysTick) is ready to run, just needs to be enabled
}   // end of function Scheduler_Init()

/***********************************************************************
** SetSchedulerPeriod
*
*  DESCRIPTION: Set the systick timer reload value to the correct value for the clock
*
***********************************************************************/
void SetSchedulerPeriod(void)
{
    SysTick->STRELOAD = GetClocksPerMicrosecond() * SCHEDULER_TICK_TIME_US;
    SysTick->STCURR = 0;
}


It all works fine, normally.

My application requires an interrupt event to resynchronize the period to the current event.
According to the UM, this can be done by writing to System Timer Current value register (STCURR - 0xE000 E018)

The note is:
23:0 CURRENT Reading this register returns the current value of the System Tick
counter. Writing any value clears the System Tick counter and the
COUNTFLAG bit in STCTRL.

Therefore I call SetSchedulerPeriod() to write to STCUR.
Now, my Systick time is set to 100uSec. 
Therefore, I expect the next interrupt to occur at 100 uSec.
Instead, I get the interrupt at 125 uSec.  This is not a problem for me.
The problem is that every once in a while, it happens in 25 uSec.
This is a MAJOR problem for me.

1. Why is this happening?
2. How can I get a consistant reset time?

标签 (1)
0 项奖励
回复
2 回复数

1,136 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kwinchell on Fri Aug 30 11:47:52 MST 2013
I found the problem. User Error (of all things??)

It looks like the systick timer works according to spec.
0 项奖励
回复

1,136 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kwinchell on Fri Aug 30 11:44:59 MST 2013
I found the problem. User error (of all things??)

It looks like the systick timer works according to spec.

K Winchell

0 项奖励
回复